diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskHistoricalEventType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskHistoricalEventType.java new file mode 100644 index 000000000000..973b9b53c3e2 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskHistoricalEventType.java @@ -0,0 +1,107 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.windowsazure.services.media.implementation.content; + +import java.util.Date; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +/** + * This type maps the XML returned in the odata ATOM serialization + * for ErrorDetail entities. + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +public class TaskHistoricalEventType implements MediaServiceDTO { + + /** The code. */ + @XmlElement(name = "Code", namespace = Constants.ODATA_DATA_NS) + protected String code; + + /** The message. */ + @XmlElement(name = "Message", namespace = Constants.ODATA_DATA_NS) + protected String message; + + /** The time stamp. */ + @XmlElement(name = "TimeStamp", namespace = Constants.ODATA_DATA_NS) + protected Date timeStamp; + + /** + * Gets the code. + * + * @return the code + */ + public String getCode() { + return code; + } + + /** + * Sets the code. + * + * @param code + * the id to set + * @return the error detail type + */ + public TaskHistoricalEventType setCode(String code) { + this.code = code; + return this; + } + + /** + * Gets the message. + * + * @return the message + */ + public String getMessage() { + return message; + } + + /** + * Sets the message. + * + * @param message + * the message to set + * @return the error detail type + */ + public TaskHistoricalEventType setMessage(String message) { + this.message = message; + return this; + } + + /** + * Gets the time stamp. + * + * @return the time stamp + */ + public Date getTimeStamp() { + return timeStamp; + } + + /** + * Sets the time stamp. + * + * @param timeStamp + * the time stamp + * @return the task historical event type + */ + public TaskHistoricalEventType setTimeStamp(Date timeStamp) { + this.timeStamp = timeStamp; + return this; + } + +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java index 9436ca9ab025..e6486eb697d0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java @@ -44,6 +44,10 @@ public class TaskType implements MediaServiceDTO { @XmlElement(name = "element", namespace = Constants.ODATA_DATA_NS) protected List errorDetails; + @XmlElementWrapper(name = "HistoricalEvents", namespace = Constants.ODATA_DATA_NS) + @XmlElement(name = "element", namespace = Constants.ODATA_DATA_NS) + protected List historicalEventTypes; + @XmlElement(name = "MediaProcessorId", namespace = Constants.ODATA_DATA_NS) protected String mediaProcessorId; @@ -269,4 +273,13 @@ public TaskType setInputMediaAssets(List inputMediaAssets) { this.inputMediaAssets = inputMediaAssets; return this; } + + public List getHistoricalEventTypes() { + return historicalEventTypes; + } + + public TaskType setHistoricalEventTypes(List historicalEventTypes) { + this.historicalEventTypes = historicalEventTypes; + return this; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskHistoricalEvent.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskHistoricalEvent.java new file mode 100644 index 000000000000..14d44fc85142 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskHistoricalEvent.java @@ -0,0 +1,76 @@ +/* + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.windowsazure.services.media.models; + +import java.util.Date; + +/** + * The Class TaskHistoricalEvent. + */ +public class TaskHistoricalEvent { + + /** The code. */ + private final String code; + + /** The message. */ + private final String message; + + /** The time stamp. */ + private final Date timeStamp; + + /** + * Instantiates a new error detail. + * + * @param code + * the code + * @param message + * the message + * @param timeStamp + * the time stamp + */ + public TaskHistoricalEvent(String code, String message, Date timeStamp) { + this.code = code; + this.message = message; + this.timeStamp = timeStamp; + } + + /** + * Gets the code. + * + * @return the code + */ + public String getCode() { + return this.code; + } + + /** + * Gets the message. + * + * @return the message + */ + public String getMessage() { + return this.message; + } + + /** + * Gets the time stamp. + * + * @return the time stamp + */ + public Date getTimeStamp() { + return this.timeStamp; + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java index 8e8c3cd11087..6f22c00bb769 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java @@ -22,6 +22,7 @@ import com.microsoft.windowsazure.services.media.implementation.ODataEntity; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; import com.microsoft.windowsazure.services.media.implementation.content.ErrorDetailType; +import com.microsoft.windowsazure.services.media.implementation.content.TaskHistoricalEventType; import com.microsoft.windowsazure.services.media.implementation.content.TaskType; /** @@ -86,6 +87,30 @@ public List getErrorDetails() { return null; } + /** + * Gets the task historical events. + * + * @return the task historical events + */ + public List getHistoricalEvents() { + List result = new ArrayList(); + List historicalEventTypes = getContent().getHistoricalEventTypes(); + + if (historicalEventTypes != null) { + for (TaskHistoricalEventType taskHistoricalEventType : historicalEventTypes) { + String message = taskHistoricalEventType.getMessage(); + if ((message != null) && (message.isEmpty())) { + message = null; + } + TaskHistoricalEvent taskHistoricalEvent = new TaskHistoricalEvent(taskHistoricalEventType.getCode(), + message, taskHistoricalEventType.getTimeStamp()); + result.add(taskHistoricalEvent); + } + } + + return result; + } + /** * Gets the media processor id. * @@ -213,7 +238,7 @@ public String getInitializationVector() { } /** - * Gets link to the task's input assets + * Gets link to the task's input assets. * * @return the link */ @@ -222,7 +247,7 @@ public LinkInfo getInputAssetsLink() { } /** - * Gets link to the task's output assets + * Gets link to the task's output assets. * * @return the link */ diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/EncryptionIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/EncryptionIntegrationTest.java index 964bafa5072e..2b2e78d125e8 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/EncryptionIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/EncryptionIntegrationTest.java @@ -98,7 +98,7 @@ public void uploadAesProtectedAssetAndDownloadSuccess() throws Exception { uploadEncryptedAssetFile(assetInfo, blobWriter, "MPEG4-H264.mp4", encryptedContent, contentKeyId, iv); // submit and execute the decoding job. - JobInfo jobInfo = decodeAsset("uploadAesProtectedAssetSuccess", assetInfo.getId()); + JobInfo jobInfo = decodeAsset(testJobPrefix + "uploadAesProtectedAssetSuccess", assetInfo.getId()); // assert LinkInfo taskLinkInfo = jobInfo.getTasksLink(); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java index ffa12bb064fa..6e125ca859b1 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java @@ -101,8 +101,8 @@ protected static void cleanupEnvironment() { removeAllTestLocators(); removeAllTestAssets(); removeAllTestAccessPolicies(); - removeAllTestContentKeys(); removeAllTestJobs(); + removeAllTestContentKeys(); } private static void removeAllTestContentKeys() { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index 608aba0901e0..a8032b0bdd3d 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -35,6 +35,7 @@ import com.microsoft.windowsazure.services.media.models.ListResult; import com.microsoft.windowsazure.services.media.models.Task; import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation; +import com.microsoft.windowsazure.services.media.models.TaskHistoricalEvent; import com.microsoft.windowsazure.services.media.models.TaskInfo; public class JobIntegrationTest extends IntegrationTestBase { @@ -343,4 +344,32 @@ public void canGetInputOutputAssetsFromTask() throws Exception { assertTrue(outputs.get(0).getName().contains(name)); } + @Test + public void canGetTaskHistoricalEventsFromTask() throws Exception { + // Arrange + String jobName = testJobPrefix + "canGetTaskHistoricalEventsFromTask"; + int priority = 3; + int retryCounter = 0; + + // Act + JobInfo actualJobInfo = service.create(Job.create().setName(jobName).setPriority(priority) + .addInputMediaAsset(assetInfo.getId()).addTaskCreator(getTaskCreator(0))); + + while (actualJobInfo.getState().getCode() < 3 && retryCounter < 30) { + Thread.sleep(10000); + actualJobInfo = service.get(Job.get(actualJobInfo.getId())); + retryCounter++; + } + ListResult tasks = service.list(Task.list(actualJobInfo.getTasksLink())); + TaskInfo taskInfo = tasks.get(0); + List historicalEvents = taskInfo.getHistoricalEvents(); + TaskHistoricalEvent historicalEvent = historicalEvents.get(0); + + // Assert + assertTrue(historicalEvents.size() >= 5); + assertNotNull(historicalEvent.getCode()); + assertNotNull(historicalEvent.getTimeStamp()); + assertNull(historicalEvent.getMessage()); + } + }