use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class AwsS3DistributionServiceImpl method distributeElements.
/**
* Distribute Mediapackage elements to the download distribution service.
*
* @param channelId
* # The id of the publication channel to be distributed to.
* @param mediapackage
* The media package that contains the elements to be distributed.
* @param elementIds
* The ids of the elements that should be distributed contained within the media package.
* @param checkAvailability
* Check the availability of the distributed element via http.
* @return A reference to the MediaPackageElements that have been distributed.
* @throws DistributionException
* Thrown if the parent directory of the MediaPackageElement cannot be created, if the MediaPackageElement
* cannot be copied or another unexpected exception occurs.
*/
public MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability) throws DistributionException {
notNull(mediapackage, "mediapackage");
notNull(elementIds, "elementIds");
notNull(channelId, "channelId");
final Set<MediaPackageElement> elements = getElements(mediapackage, elementIds);
List<MediaPackageElement> distributedElements = new ArrayList<>();
for (MediaPackageElement element : elements) {
MediaPackageElement distributedElement = distributeElement(channelId, mediapackage, element, checkAvailability);
distributedElements.add(distributedElement);
}
return distributedElements.toArray(new MediaPackageElement[distributedElements.size()]);
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class AwsS3DistributionServiceImplTest method testGetDistributedObjectName.
@Test
public void testGetDistributedObjectName() {
MediaPackageElement element = distributedMp.getElementById("presenter-delivery-distributed");
Assert.assertEquals("channelId/efd6e4df-63b6-49af-be5f-15f598778877/presenter-delivery/video-presenter-delivery.mp4", service.getDistributedObjectName(element));
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class AwsS3DistributionServiceImplTest method testDistributeElement.
@Test
public void testDistributeElement() throws Exception {
Upload upload = EasyMock.createNiceMock(Upload.class);
EasyMock.expect(tm.upload(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(File.class))).andReturn(upload);
EasyMock.replay(upload, tm);
Set<String> mpeIds = new LinkedHashSet<String>();
mpeIds.add("presenter-delivery");
MediaPackageElement[] mpes = service.distributeElements("channelId", mp, mpeIds, false);
MediaPackageElement mpe = mpes[0];
Assert.assertEquals(new URI("http://XYZ.cloudfront.net/channelId/efd6e4df-63b6-49af-be5f-15f598778877/presenter-delivery/video-presenter-delivery.mp4"), mpe.getURI());
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class DownloadDistributionServiceImpl method distributeElements.
/**
* Distribute Mediapackage elements to the download distribution service.
*
* @param channelId
* # The id of the publication channel to be distributed to.
* @param mediapackage
* The media package that contains the elements to be distributed.
* @param elementIds
* The ids of the elements that should be distributed contained within the media package.
* @param checkAvailability
* Check the availability of the distributed element via http.
* @param preserveReference
* copy actual Reference to the new distributed element
* @return A reference to the MediaPackageElements that have been distributed.
* @throws DistributionException
* Thrown if the parent directory of the MediaPackageElement cannot be created, if the MediaPackageElement
* cannot be copied or another unexpected exception occurs.
*/
public MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability, boolean preserveReference) throws DistributionException {
notNull(mediapackage, "mediapackage");
notNull(elementIds, "elementIds");
notNull(channelId, "channelId");
final Set<MediaPackageElement> elements = getElements(mediapackage, elementIds);
List<MediaPackageElement> distributedElements = new ArrayList<MediaPackageElement>();
for (MediaPackageElement element : elements) {
MediaPackageElement distributedElement = distributeElement(channelId, mediapackage, element, checkAvailability, preserveReference);
distributedElements.add(distributedElement);
}
return distributedElements.toArray(new MediaPackageElement[distributedElements.size()]);
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class DownloadDistributionServiceImpl method process.
/**
* {@inheritDoc}
*
* @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
*/
@Override
protected String process(Job job) throws Exception {
Operation op = null;
String operation = job.getOperation();
List<String> arguments = job.getArguments();
try {
op = Operation.valueOf(operation);
String channelId = arguments.get(0);
MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
}.getType());
switch(op) {
case Distribute:
Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
Boolean preserveReference = Boolean.parseBoolean(arguments.get(4));
MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds, checkAvailability, preserveReference);
return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
case Retract:
MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
default:
throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
}
} catch (IllegalArgumentException e) {
throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
} catch (IndexOutOfBoundsException e) {
throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
} catch (Exception e) {
throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
}
}
Aggregations