Search in sources :

Example 36 with Attachment

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;
}
Also used : AuthorizationService(org.opencastproject.security.api.AuthorizationService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) Tuple(org.opencastproject.util.data.Tuple)

Example 37 with Attachment

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);
}
Also used : InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) Attachment(org.opencastproject.mediapackage.Attachment) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 38 with Attachment

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));
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 39 with 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();
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Attachment(org.opencastproject.mediapackage.Attachment) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job) Catalog(org.opencastproject.mediapackage.Catalog) Track(org.opencastproject.mediapackage.Track) HashSet(java.util.HashSet)

Example 40 with Attachment

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);
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) PublicationException(org.opencastproject.publication.api.PublicationException) Publication(org.opencastproject.mediapackage.Publication) Attachment(org.opencastproject.mediapackage.Attachment) SimpleElementSelector(org.opencastproject.mediapackage.selector.SimpleElementSelector) MimeType(org.opencastproject.util.MimeType) PublicationException(org.opencastproject.publication.api.PublicationException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet)

Aggregations

Attachment (org.opencastproject.mediapackage.Attachment)64 MediaPackage (org.opencastproject.mediapackage.MediaPackage)28 URI (java.net.URI)24 IOException (java.io.IOException)20 Job (org.opencastproject.job.api.Job)20 NotFoundException (org.opencastproject.util.NotFoundException)19 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)18 Track (org.opencastproject.mediapackage.Track)16 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)16 Test (org.junit.Test)15 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)15 Catalog (org.opencastproject.mediapackage.Catalog)14 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)12 InputStream (java.io.InputStream)11 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)10 File (java.io.File)9 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 AttachmentImpl (org.opencastproject.mediapackage.attachment.AttachmentImpl)8 Workspace (org.opencastproject.workspace.api.Workspace)8