Skip to content

Commit

Permalink
Merge pull request Azure#29 from christav/list-job-assets-508
Browse files Browse the repository at this point in the history
Can now list input and output assets for jobs
  • Loading branch information
Chris Tavares committed Dec 13, 2012
2 parents 26b12f8 + 91fdd22 commit 11d915d
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ public LinkInfo getLink(String rel) {
return null;
}

/**
* Get the link to navigate an OData relationship
*
* @param relationName
* name of the OData relationship
* @return the link if found, null if not.
*/
public LinkInfo getRelationLink(String relationName) {
return getLink(Constants.ODATA_DATA_NS + "/related/" + relationName);
}

/**
* Return the links from this entry
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.microsoft.windowsazure.services.media.implementation.content;

import java.util.Date;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
Expand Down Expand Up @@ -70,12 +69,6 @@ public class JobType implements MediaServiceDTO {
@XmlElement(name = "TemplateId", namespace = Constants.ODATA_DATA_NS)
protected String templateId;

/** The output media assets. */
protected List<String> outputMediaAssets;

/** The input media assets. */
protected List<String> inputMediaAssets;

/** The tasks. */
@XmlElement(name = "TaskBody", namespace = Constants.ODATA_DATA_NS)
protected String taskBody;
Expand Down Expand Up @@ -280,46 +273,6 @@ public JobType setTemplateId(String templateId) {
return this;
}

/**
* Gets the output media assets.
*
* @return the output media assets
*/
public List<String> getOutputMediaAssets() {
return outputMediaAssets;
}

/**
* Sets the output media assets.
*
* @param uriList
* the new output media assets
*/
public JobType setOutputMediaAssets(List<String> outputMediaAssets) {
this.outputMediaAssets = outputMediaAssets;
return this;
}

/**
* Gets the input media assets.
*
* @return the input media assets
*/
public List<String> getInputMediaAssets() {
return inputMediaAssets;
}

/**
* Sets the input media assets.
*
* @param uriList
* the new input media assets
*/
public JobType setInputMediaAssets(List<String> inputMediaAssets) {
this.inputMediaAssets = inputMediaAssets;
return this;
}

/**
* Gets the tasks.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ public static EntityListOperation<AssetInfo> list(MultivaluedMap<String, String>
}, queryParameters);
}

/**
* Create an operation that will list all the assets at the given link.
*
* @param link
* Link to request assets from.
* @return The list operation.
*/
public static EntityListOperation<AssetInfo> list(LinkInfo link) {
return new DefaultListOperation<AssetInfo>(link.getHref(), new GenericType<ListResult<AssetInfo>>() {
});
}

/**
* Create an operation that will update the given asset.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private Job() {
}

/**
* Creates the.
* Creates an operation to create a new job.
*
* @param serviceUri
* the service uri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.microsoft.windowsazure.services.media.models;

import java.util.Date;
import java.util.List;

import com.microsoft.windowsazure.services.media.implementation.ODataEntity;
import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
Expand Down Expand Up @@ -130,29 +129,29 @@ public String getTemplateId() {
}

/**
* Gets the input media assets.
* Gets the task body.
*
* @return the input media assets
* @return the task body
*/
public List<String> getInputMediaAssets() {
return getContent().getInputMediaAssets();
public String getTaskBody() {
return getContent().getTaskBody();
}

/**
* Gets the output media assets.
* Get a link which, when listed, will return the input assets for the job
*
* @return the output media assets
* @return Link if found, null if not.
*/
public List<String> getOutputMediaAssets() {
return getContent().getOutputMediaAssets();
public LinkInfo getInputAssetsLink() {
return getRelationLink("InputMediaAssets");
}

/**
* Gets the task body.
* Get a link which, when listed, will return the output assets for the job
*
* @return the task body
* @return Link if found, null if not.
*/
public String getTaskBody() {
return getContent().getTaskBody();
public LinkInfo getOutputAssetsLink() {
return getRelationLink("OutputMediaAssets");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,12 @@ public class JobIntegrationTest extends IntegrationTestBase {
private void verifyJobInfoEqual(String message, JobInfo expected, JobInfo actual) {
verifyJobProperties(message, expected.getName(), expected.getPriority(), expected.getRunningDuration(),
expected.getState(), expected.getTemplateId(), expected.getCreated(), expected.getLastModified(),
expected.getStartTime(), expected.getEndTime(), expected.getInputMediaAssets(),
expected.getOutputMediaAssets(), actual);
expected.getStartTime(), expected.getEndTime(), actual);
}

private void verifyJobProperties(String message, String testName, Integer priority, Double runningDuration,
JobState state, String templateId, Date created, Date lastModified, Date startTime, Date endTime,
List<String> inputMediaAssets, List<String> outputMediaAssets, JobInfo actualJob) {
JobInfo actualJob) {
assertNotNull(message, actualJob);

assertNotNull(message + "Id", actualJob.getId());
Expand All @@ -78,11 +77,6 @@ private void verifyJobProperties(String message, String testName, Integer priori
assertDateApproxEquals(message + " StartTime", startTime, actualJob.getStartTime());
assertDateApproxEquals(message + " EndTime", endTime, actualJob.getEndTime());

// TODO: Add test for accessing the input and output media assets when fixed:
// https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/508
assertEquals(message + " InputMediaAssets", inputMediaAssets, actualJob.getInputMediaAssets());
assertEquals(message + " OutputMediaAssets", outputMediaAssets, actualJob.getOutputMediaAssets());

// TODO: Add test for accessing the tasks when fixed:
// https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/531
}
Expand Down Expand Up @@ -139,8 +133,6 @@ public void createJobSuccess() throws Exception {
double duration = 0.0;
JobState state = JobState.Queued;
String templateId = null;
List<String> inputMediaAssets = null;
List<String> outputMediaAssets = null;
Date created = new Date();
Date lastModified = new Date();
Date stateTime = null;
Expand All @@ -152,7 +144,7 @@ public void createJobSuccess() throws Exception {

// Assert
verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime,
endTime, inputMediaAssets, outputMediaAssets, actualJob);
endTime, actualJob);
}

@Test
Expand All @@ -163,8 +155,6 @@ public void createJobTwoTasksSuccess() throws Exception {
double duration = 0.0;
JobState state = JobState.Queued;
String templateId = null;
List<String> inputMediaAssets = null;
List<String> outputMediaAssets = null;
Date created = new Date();
Date lastModified = new Date();
Date stateTime = null;
Expand All @@ -179,7 +169,7 @@ public void createJobTwoTasksSuccess() throws Exception {

// Assert
verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime,
endTime, inputMediaAssets, outputMediaAssets, actualJob);
endTime, actualJob);
}

@Test
Expand All @@ -190,8 +180,6 @@ public void getJobSuccess() throws Exception {
double duration = 0.0;
JobState state = JobState.Queued;
String templateId = null;
List<String> inputMediaAssets = null;
List<String> outputMediaAssets = null;
String jobId = createJob(name).getId();
Date created = new Date();
Date lastModified = new Date();
Expand All @@ -203,7 +191,7 @@ public void getJobSuccess() throws Exception {

// Assert
verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime,
endTime, inputMediaAssets, outputMediaAssets, actualJob);
endTime, actualJob);
}

@Test
Expand Down Expand Up @@ -296,7 +284,7 @@ public void deleteJobSuccess() throws ServiceException {
}

@Test
public void deleteJobIvalidIdFail() throws ServiceException {
public void deleteJobInvalidIdFail() throws ServiceException {
// Arrange
expectedException.expect(ServiceException.class);
expectedException.expect(new ServiceExceptionMatcher(400));
Expand All @@ -306,4 +294,29 @@ public void deleteJobIvalidIdFail() throws ServiceException {

// Assert
}

@Test
public void canGetInputOutputAssetsFromJob() throws Exception {
String name = testJobPrefix + "canGetInputOutputAssetsFromJob";
int priority = 3;
double duration = 0.0;
JobState state = JobState.Queued;
String templateId = null;
Date created = new Date();
Date lastModified = new Date();
Date stateTime = null;
Date endTime = null;

JobInfo actualJob = service.create(Job.create(service.getRestServiceUri()).setName(name).setPriority(priority)
.addInputMediaAsset(assetInfo.getId()).addTaskCreator(getTaskCreator(0)));

ListResult<AssetInfo> inputs = service.list(Asset.list(actualJob.getInputAssetsLink()));
ListResult<AssetInfo> outputs = service.list(Asset.list(actualJob.getOutputAssetsLink()));

assertEquals(1, inputs.size());
assertEquals(assetInfo.getId(), inputs.get(0).getId());

assertEquals(1, outputs.size());
assertTrue(outputs.get(0).getName().contains(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@
import java.net.URLEncoder;

import javax.ws.rs.core.MultivaluedMap;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;

import org.junit.Test;

import com.microsoft.windowsazure.services.media.implementation.atom.ContentType;
import com.microsoft.windowsazure.services.media.implementation.atom.EntryType;
import com.microsoft.windowsazure.services.media.implementation.atom.LinkType;
import com.microsoft.windowsazure.services.media.implementation.content.AssetType;
import com.microsoft.windowsazure.services.media.implementation.content.Constants;
import com.microsoft.windowsazure.services.media.implementation.content.JobType;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityDeleteOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityGetOperation;
import com.microsoft.windowsazure.services.media.implementation.entities.EntityListOperation;
Expand Down Expand Up @@ -130,4 +137,51 @@ public void assetDeleteReturnsExpectedUri() throws Exception {
assertEquals(expectedUri, deleter.getUri());
}

private static final String expectedOutputAsset = "Job(someJobId)/OutputAssets";
private static final String expectedInputAsset = "Job(someJobId)/InputAssets";

@Test
public void listForLinkReturnsExpectedUri() throws Exception {
JobInfo fakeJob = createJob();

EntityListOperation<AssetInfo> lister = Asset.list(fakeJob.getInputAssetsLink());

assertEquals(lister.getUri(), expectedInputAsset);
}

private JobInfo createJob() {
EntryType fakeJobEntry = new EntryType();
addEntryLink(fakeJobEntry, Constants.ODATA_DATA_NS + "/related/OutputMediaAssets", expectedOutputAsset,
"application/atom+xml;type=feed", "OutputAssets");
addEntryLink(fakeJobEntry, Constants.ODATA_DATA_NS + "/related/InputMediaAssets", expectedInputAsset,
"application/atom+xml;type=feed", "InputAssets");

JobType payload = new JobType().setId("SomeId").setName("FakeJob");
addEntryContent(fakeJobEntry, payload);

return new JobInfo(fakeJobEntry, payload);
}

private void addEntryLink(EntryType entry, String rel, String href, String type, String title) {
LinkType link = new LinkType();
link.setRel(rel);
link.setHref(href);
link.setType(type);
link.setTitle(title);

JAXBElement<LinkType> linkElement = new JAXBElement<LinkType>(new QName("link", Constants.ATOM_NS),
LinkType.class, link);
entry.getEntryChildren().add(linkElement);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
private ContentType addEntryContent(EntryType entry, Object content) {
ContentType contentWrapper = new ContentType();
contentWrapper.getContent().add(
new JAXBElement(Constants.ODATA_PROPERTIES_ELEMENT_NAME, content.getClass(), content));

entry.getEntryChildren().add(
new JAXBElement<ContentType>(Constants.ATOM_CONTENT_ELEMENT_NAME, ContentType.class, contentWrapper));
return contentWrapper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,7 @@ public boolean isJobFinished(JobInfo initialJobInfo) throws ServiceException {
}

public List<AssetInfo> getJobOutputMediaAssets(JobInfo job) throws ServiceException {
List<String> outputMediaAssets = job.getOutputMediaAssets();
if (outputMediaAssets == null) {
return null;
}
List<AssetInfo> ret = new ArrayList<AssetInfo>();
for (String assetId : outputMediaAssets) {
ret.add(service.get(Asset.get(assetId)));
}
return ret;
return service.list(Asset.list(job.getOutputAssetsLink()));
}

// Process
Expand Down

0 comments on commit 11d915d

Please sign in to comment.