use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class IndexServiceImplTest method setupAuthorizationService.
private AuthorizationService setupAuthorizationService(MediaPackage mediapackage) {
// Setup Authorization Service
Tuple<MediaPackage, Attachment> returnValue = new Tuple<>(mediapackage, null);
AuthorizationService authorizationService = EasyMock.createMock(AuthorizationService.class);
EasyMock.expect(authorizationService.setAcl(EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(AclScope.class), EasyMock.anyObject(AccessControlList.class))).andReturn(returnValue).anyTimes();
EasyMock.replay(authorizationService);
return authorizationService;
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class IndexServiceImplTest method testAddAssetsToMp.
@Test
public void testAddAssetsToMp() throws org.json.simple.parser.ParseException, IOException, ConfigurationException, MediaPackageException, HandleException, IngestException, NotFoundException {
MediaPackage mediapackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
JSONArray assetMetadata = (JSONArray) new JSONParser().parse("[{\"id\":\"attachment_attachment_notes\", " + "\"title\": \"class handout notes\"," + "\"flavorType\": \"attachment\"," + "\"flavorSubType\": \"notes\"," + "\"type\": \"attachment\"}]");
// a test asset input stream
List<String> assetList = new LinkedList<String>();
assetList.add("attachment_attachment_notes");
MediaPackageElementFlavor elemflavor = new MediaPackageElementFlavor("attachment_attachment_notes", "*");
MediaPackageElementFlavor newElemflavor = new MediaPackageElementFlavor("attachment", "notes");
// Set up the mock Ingest Service's attachment
Attachment attachment = new AttachmentImpl();
attachment.setFlavor(elemflavor);
mediapackage.add(attachment);
// Run Test
IndexServiceImpl indexServiceImpl = new IndexServiceImpl();
indexServiceImpl.setIngestService(setupIngestService(mediapackage, Capture.<InputStream>newInstance()));
mediapackage = indexServiceImpl.updateMpAssetFlavor(assetList, mediapackage, assetMetadata, true);
assertTrue("The mediapackage attachment has the updated flavor", mediapackage.getAttachments(newElemflavor).length == 1);
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class AbstractEventEndpoint method getAttachment.
@GET
@Path("{eventId}/asset/attachment/{id}.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getAttachment", description = "Returns the details of an attachment from the given event and attachment id as JSON", returnDescription = "The details of an attachment from the given event and attachment id as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "id", description = "The attachment id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns the details of an attachment from the given event and attachment id as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event or attachment with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getAttachment(@PathParam("eventId") String eventId, @PathParam("id") String id) throws NotFoundException, SearchIndexException, IndexServiceException {
MediaPackage mp = getMediaPackageByEventId(eventId);
Attachment attachment = mp.getAttachment(id);
if (attachment == null)
return notFound("Cannot find an attachment with id '%s'.", id);
return okJson(attachmentToJSON(attachment));
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class ConfigurableWorkflowOperationHandlerBase method retractPublicationElements.
/**
* Remove the {@link Publication}'s {@link MediaPackageElement}s from a given channel.
*
* @param channelId
* The channel to remove the {@link MediaPackageElement}s from.
* @param publication
* The {@link Publication} that is being removed.
* @param mp
* The {@link MediaPackage} that the {@link Publication} is part of.
* @return the number of {@link MediaPackageElement}s that have been retracted
* @throws WorkflowOperationException
* Thrown if unable to retract the {@link MediaPackageElement}s.
*/
private int retractPublicationElements(String channelId, Publication publication, MediaPackage mp) throws WorkflowOperationException {
assert ((channelId != null) && (publication != null) && (mp != null));
MediaPackage mediapackageWithPublicationElements = (MediaPackage) mp.clone();
// Add the publications to the mediapackage so that we can use the standard retract
addPublicationElementsToMediaPackage(publication, mediapackageWithPublicationElements);
Set<String> elementIds = new HashSet<>();
for (Attachment attachment : publication.getAttachments()) {
elementIds.add(attachment.getIdentifier());
}
for (Catalog catalog : publication.getCatalogs()) {
elementIds.add(catalog.getIdentifier());
}
for (Track track : publication.getTracks()) {
elementIds.add(track.getIdentifier());
}
if (elementIds.size() > 0) {
logger.info("Retracting {} elements of media package {} from publication channel {}", elementIds.size(), mp, channelId);
Job job = null;
try {
job = getDistributionService().retract(channelId, mediapackageWithPublicationElements, elementIds);
} catch (DistributionException e) {
logger.error("Error while retracting '{}' elements from channel '{}' of distribution '{}': {}", elementIds.size(), channelId, getDistributionService(), getStackTrace(e));
throw new WorkflowOperationException("The retraction job did not complete successfully");
}
if (!waitForStatus(job).isSuccess()) {
throw new WorkflowOperationException("The retraction job did not complete successfully");
}
} else {
logger.debug("No publication elements were found for retraction");
}
return elementIds.size();
}
use of org.opencastproject.mediapackage.Attachment in project opencast by opencast.
the class PublishOaiPmhWorkflowOperationHandler method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowOperationHandler#start(org.opencastproject.workflow.api.WorkflowInstance,
* JobContext)
*/
@Override
public WorkflowOperationResult start(final WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
logger.debug("Running distribution workflow operation");
MediaPackage mediaPackage = workflowInstance.getMediaPackage();
// Check which tags have been configured
String downloadTags = StringUtils.trimToEmpty(workflowInstance.getCurrentOperation().getConfiguration(DOWNLOAD_TAGS));
String downloadFlavors = StringUtils.trimToEmpty(workflowInstance.getCurrentOperation().getConfiguration(DOWNLOAD_FLAVORS));
String streamingTags = StringUtils.trimToEmpty(workflowInstance.getCurrentOperation().getConfiguration(STREAMING_TAGS));
String streamingFlavors = StringUtils.trimToEmpty(workflowInstance.getCurrentOperation().getConfiguration(STREAMING_FLAVORS));
boolean checkAvailability = option(workflowInstance.getCurrentOperation().getConfiguration(CHECK_AVAILABILITY)).bind(trimToNone).map(toBool).getOrElse(true);
String repository = StringUtils.trimToNull(workflowInstance.getCurrentOperation().getConfiguration(REPOSITORY));
Opt<String> externalChannel = getOptConfig(workflowInstance.getCurrentOperation(), EXTERNAL_CHANNEL_NAME);
Opt<String> externalTempalte = getOptConfig(workflowInstance.getCurrentOperation(), EXTERNAL_TEMPLATE);
Opt<MimeType> externalMimetype = getOptConfig(workflowInstance.getCurrentOperation(), EXTERNAL_MIME_TYPE).bind(MimeTypes.toMimeType);
if (repository == null)
throw new IllegalArgumentException("No repository has been specified");
String[] sourceDownloadTags = StringUtils.split(downloadTags, ",");
String[] sourceDownloadFlavors = StringUtils.split(downloadFlavors, ",");
String[] sourceStreamingTags = StringUtils.split(streamingTags, ",");
String[] sourceStreamingFlavors = StringUtils.split(streamingFlavors, ",");
if (sourceDownloadTags.length == 0 && sourceDownloadFlavors.length == 0 && sourceStreamingTags.length == 0 && sourceStreamingFlavors.length == 0) {
logger.warn("No tags or flavors have been specified, so nothing will be published to the engage");
return createResult(mediaPackage, Action.CONTINUE);
}
final SimpleElementSelector downloadElementSelector = new SimpleElementSelector();
for (String flavor : sourceDownloadFlavors) {
downloadElementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
}
for (String tag : sourceDownloadTags) {
downloadElementSelector.addTag(tag);
}
final Collection<MediaPackageElement> downloadElements = downloadElementSelector.select(mediaPackage, false);
final Collection<MediaPackageElement> streamingElements;
if (distributeStreaming) {
final SimpleElementSelector streamingElementSelector = new SimpleElementSelector();
for (String flavor : sourceStreamingFlavors) {
streamingElementSelector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
}
for (String tag : sourceStreamingTags) {
streamingElementSelector.addTag(tag);
}
streamingElements = streamingElementSelector.select(mediaPackage, false);
} else {
streamingElements = list();
}
try {
Set<String> downloadElementIds = new HashSet<>();
Set<String> streamingElementIds = new HashSet<>();
// Look for elements matching the tag
for (MediaPackageElement elem : downloadElements) {
downloadElementIds.add(elem.getIdentifier());
}
for (MediaPackageElement elem : streamingElements) {
streamingElementIds.add(elem.getIdentifier());
}
// Also distribute the security configuration
// -----
// This was removed in the meantime by a fix for MH-8515, but could now be used again.
// -----
Attachment[] securityAttachments = mediaPackage.getAttachments(MediaPackageElements.XACML_POLICY);
if (securityAttachments != null && securityAttachments.length > 0) {
for (Attachment a : securityAttachments) {
downloadElementIds.add(a.getIdentifier());
streamingElementIds.add(a.getIdentifier());
}
}
Job publishJob = null;
try {
publishJob = publicationService.publish(mediaPackage, repository, downloadElementIds, streamingElementIds, checkAvailability);
} catch (MediaPackageException e) {
throw new WorkflowOperationException("Error parsing media package", e);
} catch (PublicationException e) {
throw new WorkflowOperationException("Error parsing media package", e);
}
// Wait until the publication job has returned
if (!waitForStatus(publishJob).isSuccess())
throw new WorkflowOperationException("Mediapackage " + mediaPackage.getIdentifier() + " could not be published to OAI-PMH repository " + repository);
// The job has passed
Job job = serviceRegistry.getJob(publishJob.getId());
// If there is no payload, then the item has not been published.
if (job.getPayload() == null) {
logger.warn("Publish to OAI-PMH repository '{}' failed, no payload from publication job: {}", repository, job);
return createResult(mediaPackage, Action.CONTINUE);
}
Publication newElement = null;
try {
newElement = (Publication) MediaPackageElementParser.getFromXml(job.getPayload());
} catch (MediaPackageException e) {
throw new WorkflowOperationException(e);
}
if (newElement == null) {
logger.warn("Publication to OAI-PMH repository '{}' failed, unable to parse the payload '{}' from job '{}' to a mediapackage element", repository, job.getPayload(), job.toString());
return createResult(mediaPackage, Action.CONTINUE);
}
for (Publication existingPublication : $(mediaPackage.getPublications()).find(ofChannel(newElement.getChannel()).toFn())) {
mediaPackage.remove(existingPublication);
}
mediaPackage.add(newElement);
if (externalChannel.isSome() && externalMimetype.isSome() && externalTempalte.isSome()) {
String template = externalTempalte.get().replace("{event}", mediaPackage.getIdentifier().compact());
if (StringUtils.isNotBlank(mediaPackage.getSeries()))
template = template.replace("{series}", mediaPackage.getSeries());
Publication externalElement = PublicationImpl.publication(UUID.randomUUID().toString(), externalChannel.get(), URI.create(template), externalMimetype.get());
for (Publication existingPublication : $(mediaPackage.getPublications()).find(ofChannel(externalChannel.get()).toFn())) {
mediaPackage.remove(existingPublication);
}
mediaPackage.add(externalElement);
}
logger.debug("Publication to OAI-PMH repository '{}' operation completed", repository);
} catch (Exception e) {
if (e instanceof WorkflowOperationException) {
throw (WorkflowOperationException) e;
} else {
throw new WorkflowOperationException(e);
}
}
return createResult(mediaPackage, Action.CONTINUE);
}
Aggregations