Search in sources :

Example 1 with Publication

use of org.opencastproject.mediapackage.Publication in project opencast by opencast.

the class DuplicateEventWorkflowOperationHandlerTest method mockDependencies.

private void mockDependencies(int numberOfCopies) throws Exception {
    clonedMediaPackages = Capture.newInstance(CaptureType.ALL);
    reset(workspace, assetManager, distributionService);
    URI uriDc = getClass().getResource("/dublincore.xml").toURI();
    for (int i = 0; i < numberOfCopies; i++) {
        expect(workspace.read(eq(URI.create("dublincore.xml")))).andReturn(new FileInputStream(new File(uriDc))).times(1);
    }
    expect(workspace.get(anyObject())).andReturn(new File(getClass().getResource("/av.mov").toURI())).anyTimes();
    expect(workspace.put(anyString(), anyString(), eq("dublincore.xml"), anyObject())).andReturn(uriDc).times(numberOfCopies);
    replay(workspace);
    final AResult qResult = createNiceMock(AResult.class);
    expect(qResult.getRecords()).andReturn(Stream.empty()).anyTimes();
    replay(qResult);
    final ASelectQuery qSelect = createNiceMock(ASelectQuery.class);
    expect(qSelect.where(anyObject())).andReturn(qSelect).anyTimes();
    expect(qSelect.run()).andReturn(qResult).anyTimes();
    replay(qSelect);
    final AQueryBuilder qBuilder = createNiceMock(AQueryBuilder.class);
    expect(qBuilder.select(anyObject())).andReturn(qSelect).anyTimes();
    replay(qBuilder);
    expect(assetManager.createQuery()).andReturn(qBuilder).anyTimes();
    expect(assetManager.takeSnapshot(eq(AssetManager.DEFAULT_OWNER), capture(clonedMediaPackages))).andReturn(createNiceMock(Snapshot.class)).times(numberOfCopies);
    replay(assetManager);
    final Job distributionJob = createNiceMock(Job.class);
    final Publication internalPub = (Publication) mp.getElementById("pub-int");
    final List<MediaPackageElement> internalPubElements = new ArrayList<>();
    Collections.addAll(internalPubElements, (internalPub.getAttachments()));
    Collections.addAll(internalPubElements, (internalPub.getCatalogs()));
    Collections.addAll(internalPubElements, (internalPub.getTracks()));
    expect(distributionJob.getStatus()).andReturn(Job.Status.FINISHED).anyTimes();
    for (MediaPackageElement e : internalPubElements) {
        expect(distributionJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(e)).times(numberOfCopies);
    }
    replay(distributionJob);
    expect(distributionService.distribute(eq(InternalPublicationChannel.CHANNEL_ID), anyObject(), anyString())).andReturn(distributionJob).anyTimes();
    replay(distributionService);
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList) AResult(org.opencastproject.assetmanager.api.query.AResult) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) Publication(org.opencastproject.mediapackage.Publication) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) Job(org.opencastproject.job.api.Job) URI(java.net.URI) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with Publication

use of org.opencastproject.mediapackage.Publication in project opencast by opencast.

the class EventIndexUtils method updateEvent.

/**
 * Update the given {@link Event} with the given {@link MediaPackage}.
 *
 * @param event
 *          the event to update
 * @param mp
 *          the mediapackage containing the metadata for the update
 * @return the updated event
 */
public static Event updateEvent(Event event, MediaPackage mp) {
    // Tracks
    List<String> trackMimeTypes = new ArrayList<String>();
    List<String> trackStreamResolutions = new ArrayList<String>();
    List<String> trackFlavors = new ArrayList<String>();
    for (Track t : mp.getTracks()) {
        if (t.getMimeType() != null)
            trackMimeTypes.add(t.getMimeType().toString());
        if (t.getFlavor() != null)
            trackFlavors.add(t.getFlavor().toString());
        VideoStream[] streams = TrackSupport.byType(t.getStreams(), VideoStream.class);
        for (VideoStream s : streams) {
            trackStreamResolutions.add(s.getFrameWidth() + "x" + s.getFrameHeight());
        }
    }
    event.setTrackMimetypes(trackMimeTypes);
    event.setTrackStreamResolutions(trackStreamResolutions);
    event.setTrackFlavors(trackFlavors);
    // Metadata
    List<String> metadataFlavors = new ArrayList<String>();
    List<String> metadataMimetypes = new ArrayList<String>();
    for (Catalog c : mp.getCatalogs()) {
        if (c.getFlavor() != null)
            metadataFlavors.add(c.getFlavor().toString());
        if (c.getMimeType() != null)
            metadataMimetypes.add(c.getMimeType().toString());
    }
    event.setMetadataFlavors(metadataFlavors);
    event.setMetadataMimetypes(metadataMimetypes);
    // Attachments
    List<String> attachmentFlavors = new ArrayList<String>();
    for (Attachment a : mp.getAttachments()) {
        if (a.getFlavor() != null)
            attachmentFlavors.add(a.getFlavor().toString());
    }
    event.setAttachmentFlavors(attachmentFlavors);
    // Publications
    List<Publication> publications = new ArrayList<Publication>();
    for (Publication p : mp.getPublications()) {
        publications.add(p);
    }
    event.setPublications(publications);
    event.setSeriesName(mp.getSeriesTitle());
    return event;
}
Also used : ArrayList(java.util.ArrayList) VideoStream(org.opencastproject.mediapackage.VideoStream) Publication(org.opencastproject.mediapackage.Publication) Attachment(org.opencastproject.mediapackage.Attachment) Track(org.opencastproject.mediapackage.Track) Catalog(org.opencastproject.mediapackage.Catalog)

Example 3 with Publication

use of org.opencastproject.mediapackage.Publication in project opencast by opencast.

the class AbstractEventEndpoint method getPublication.

@GET
@Path("{eventId}/asset/publication/{id}.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getPublication", description = "Returns the details of a publication from the given event and publication id as JSON", returnDescription = "The details of a publication from the given event and publication id as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "id", description = "The publication id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns the publication of a catalog from the given event and publication id as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event or publication with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getPublication(@PathParam("eventId") String eventId, @PathParam("id") String id) throws NotFoundException, SearchIndexException, IndexServiceException {
    MediaPackage mp = getMediaPackageByEventId(eventId);
    Publication publication = null;
    for (Publication p : mp.getPublications()) {
        if (id.equals(p.getIdentifier())) {
            publication = p;
            break;
        }
    }
    if (publication == null)
        return notFound("Cannot find publication with id '%s'.", id);
    return okJson(publicationToJSON(publication));
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) Publication(org.opencastproject.mediapackage.Publication) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 4 with Publication

use of org.opencastproject.mediapackage.Publication in project opencast by opencast.

the class ConfigurablePublishWorkflowOperationHandler method start.

@Override
public WorkflowOperationResult start(WorkflowInstance workflowInstance, JobContext context) throws WorkflowOperationException {
    RequireUtil.notNull(workflowInstance, "workflowInstance");
    final MediaPackage mp = workflowInstance.getMediaPackage();
    final WorkflowOperationInstance op = workflowInstance.getCurrentOperation();
    final String channelId = StringUtils.trimToEmpty(op.getConfiguration(CHANNEL_ID_KEY));
    if ("".equals(channelId)) {
        throw new WorkflowOperationException("Unable to publish this mediapackage as the configuration key " + CHANNEL_ID_KEY + " is missing. Unable to determine where to publish these elements.");
    }
    final String urlPattern = StringUtils.trimToEmpty(op.getConfiguration(URL_PATTERN));
    MimeType mimetype = null;
    String mimetypeString = StringUtils.trimToEmpty(op.getConfiguration(MIME_TYPE));
    if (!"".equals(mimetypeString)) {
        try {
            mimetype = MimeTypes.parseMimeType(mimetypeString);
        } catch (IllegalArgumentException e) {
            throw new WorkflowOperationException("Unable to parse the provided configuration for " + MIME_TYPE, e);
        }
    }
    final boolean withPublishedElements = BooleanUtils.toBoolean(StringUtils.trimToEmpty(op.getConfiguration(WITH_PUBLISHED_ELEMENTS)));
    boolean checkAvailability = BooleanUtils.toBoolean(StringUtils.trimToEmpty(op.getConfiguration(CHECK_AVAILABILITY)));
    if (getPublications(mp, channelId).size() > 0) {
        final String rePublishStrategy = StringUtils.trimToEmpty(op.getConfiguration(STRATEGY));
        switch(rePublishStrategy) {
            case ("fail"):
                // fail is a dummy function for further distribution strategies
                fail(mp);
                break;
            case ("merge"):
                // nothing to do here. other publication strategies can be added to this list later on
                break;
            default:
                retract(mp, channelId);
        }
    }
    String mode = StringUtils.trimToEmpty(op.getConfiguration(MODE));
    if ("".equals(mode)) {
        mode = DEFAULT_MODE;
    } else if (!ArrayUtils.contains(KNOWN_MODES, mode)) {
        logger.error("Unknown value for configuration key mode: '{}'", mode);
        throw new IllegalArgumentException("Unknown value for configuration key mode");
    }
    final String[] sourceFlavors = StringUtils.split(StringUtils.trimToEmpty(op.getConfiguration(SOURCE_FLAVORS)), ",");
    final String[] sourceTags = StringUtils.split(StringUtils.trimToEmpty(op.getConfiguration(SOURCE_TAGS)), ",");
    String publicationUUID = UUID.randomUUID().toString();
    Publication publication = PublicationImpl.publication(publicationUUID, channelId, null, null);
    // Configure the element selector
    final SimpleElementSelector selector = new SimpleElementSelector();
    for (String flavor : sourceFlavors) {
        selector.addFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
    }
    for (String tag : sourceTags) {
        selector.addTag(tag);
    }
    if (sourceFlavors.length > 0 || sourceTags.length > 0) {
        if (!withPublishedElements) {
            Set<MediaPackageElement> elements = distribute(selector.select(mp, false), mp, channelId, mode, checkAvailability);
            if (elements.size() > 0) {
                for (MediaPackageElement element : elements) {
                    // Make sure the mediapackage is prompted to create a new identifier for this element
                    element.setIdentifier(null);
                    PublicationImpl.addElementToPublication(publication, element);
                }
            } else {
                logger.info("No element found for distribution in media package '{}'", mp);
                return createResult(mp, Action.CONTINUE);
            }
        } else {
            List<MediaPackageElement> publishedElements = new ArrayList<>();
            for (Publication alreadyPublished : mp.getPublications()) {
                publishedElements.addAll(Arrays.asList(alreadyPublished.getAttachments()));
                publishedElements.addAll(Arrays.asList(alreadyPublished.getCatalogs()));
                publishedElements.addAll(Arrays.asList(alreadyPublished.getTracks()));
            }
            for (MediaPackageElement element : selector.select(publishedElements, false)) {
                PublicationImpl.addElementToPublication(publication, element);
            }
        }
    }
    if (!"".equals(urlPattern)) {
        publication.setURI(populateUrlWithVariables(urlPattern, mp, publicationUUID));
    }
    if (mimetype != null) {
        publication.setMimeType(mimetype);
    }
    mp.add(publication);
    return createResult(mp, Action.CONTINUE);
}
Also used : ArrayList(java.util.ArrayList) Publication(org.opencastproject.mediapackage.Publication) SimpleElementSelector(org.opencastproject.mediapackage.selector.SimpleElementSelector) MimeType(org.opencastproject.util.MimeType) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException)

Example 5 with Publication

use of org.opencastproject.mediapackage.Publication in project opencast by opencast.

the class ConfigurablePublishWorkflowOperationHandlerTest method testNormal.

@Test
public void testNormal() throws WorkflowOperationException, URISyntaxException, DistributionException, MediaPackageException {
    String channelId = "engage-player";
    String attachmentId = "attachment-id";
    String catalogId = "catalog-id";
    String trackId = "track-id";
    Attachment attachment = new AttachmentImpl();
    attachment.addTag("engage-download");
    attachment.setIdentifier(attachmentId);
    attachment.setURI(new URI("http://api.com/attachment"));
    Catalog catalog = CatalogImpl.newInstance();
    catalog.addTag("engage-download");
    catalog.setIdentifier(catalogId);
    catalog.setURI(new URI("http://api.com/catalog"));
    Track track = new TrackImpl();
    track.addTag("engage-streaming");
    track.setIdentifier(trackId);
    track.setURI(new URI("http://api.com/track"));
    Publication publicationtest = new PublicationImpl(trackId, channelId, new URI("http://api.com/publication"), MimeType.mimeType(trackId, trackId));
    Track unrelatedTrack = new TrackImpl();
    unrelatedTrack.addTag("unrelated");
    Capture<MediaPackageElement> capturePublication = Capture.newInstance();
    MediaPackage mediapackageClone = EasyMock.createNiceMock(MediaPackage.class);
    EasyMock.expect(mediapackageClone.getElements()).andStubReturn(new MediaPackageElement[] { attachment, catalog, track, unrelatedTrack });
    EasyMock.expect(mediapackageClone.getIdentifier()).andStubReturn(new IdImpl("mp-id-clone"));
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackageClone);
    MediaPackage mediapackage = EasyMock.createNiceMock(MediaPackage.class);
    EasyMock.expect(mediapackage.getElements()).andStubReturn(new MediaPackageElement[] { attachment, catalog, track, unrelatedTrack });
    EasyMock.expect(mediapackage.clone()).andStubReturn(mediapackageClone);
    EasyMock.expect(mediapackage.getIdentifier()).andStubReturn(new IdImpl("mp-id"));
    mediapackage.add(EasyMock.capture(capturePublication));
    mediapackage.add(publicationtest);
    EasyMock.expect(mediapackage.getPublications()).andStubReturn(new Publication[] { publicationtest });
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackage);
    WorkflowOperationInstance op = EasyMock.createNiceMock(WorkflowOperationInstance.class);
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.CHANNEL_ID_KEY)).andStubReturn(channelId);
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.MIME_TYPE)).andStubReturn("text/html");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.URL_PATTERN)).andStubReturn("http://api.opencast.org/api/events/${event_id}");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.SOURCE_TAGS)).andStubReturn("engage-download,engage-streaming");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.CHECK_AVAILABILITY)).andStubReturn("true");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.STRATEGY)).andStubReturn("retract");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.MODE)).andStubReturn("single");
    EasyMock.replay(op);
    WorkflowInstance workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andStubReturn(mediapackage);
    EasyMock.expect(workflowInstance.getCurrentOperation()).andStubReturn(op);
    EasyMock.replay(workflowInstance);
    JobContext jobContext = EasyMock.createNiceMock(JobContext.class);
    EasyMock.replay(jobContext);
    Job attachmentJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(attachmentJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(attachment));
    EasyMock.replay(attachmentJob);
    Job catalogJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(catalogJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(catalog));
    EasyMock.replay(catalogJob);
    Job trackJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(trackJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(track));
    EasyMock.replay(trackJob);
    Job retractJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(retractJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(track));
    EasyMock.replay(retractJob);
    DownloadDistributionService distributionService = EasyMock.createNiceMock(DownloadDistributionService.class);
    // Make sure that all of the elements are distributed.
    EasyMock.expect(distributionService.distribute(channelId, mediapackage, attachmentId, true)).andReturn(attachmentJob);
    EasyMock.expect(distributionService.distribute(channelId, mediapackage, catalogId, true)).andReturn(catalogJob);
    EasyMock.expect(distributionService.distribute(channelId, mediapackage, trackId, true)).andReturn(trackJob);
    EasyMock.expect(distributionService.retract(channelId, mediapackage, channelId)).andReturn(retractJob);
    EasyMock.replay(distributionService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andStubReturn(org);
    EasyMock.replay(securityService);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.replay(serviceRegistry);
    // Override the waitForStatus method to not block the jobs
    ConfigurablePublishWorkflowOperationHandler configurePublish = new ConfigurablePublishWorkflowOperationHandler() {

        @Override
        protected Result waitForStatus(long timeout, Job... jobs) {
            HashMap<Job, Status> map = Stream.mk(jobs).foldl(new HashMap<Job, Status>(), new Fn2<HashMap<Job, Status>, Job, HashMap<Job, Status>>() {

                @Override
                public HashMap<Job, Status> apply(HashMap<Job, Status> a, Job b) {
                    a.put(b, Status.FINISHED);
                    return a;
                }
            });
            return new Result(map);
        }
    };
    configurePublish.setDownloadDistributionService(distributionService);
    configurePublish.setSecurityService(securityService);
    configurePublish.setServiceRegistry(serviceRegistry);
    WorkflowOperationResult result = configurePublish.start(workflowInstance, jobContext);
    assertNotNull(result.getMediaPackage());
    assertTrue("The publication element has not been added to the mediapackage.", capturePublication.hasCaptured());
    assertTrue("Some other type of element has been added to the mediapackage instead of the publication element.", capturePublication.getValue().getElementType().equals(MediaPackageElement.Type.Publication));
    Publication publication = (Publication) capturePublication.getValue();
    assertEquals(1, publication.getAttachments().length);
    assertNotEquals(attachment.getIdentifier(), publication.getAttachments()[0].getIdentifier());
    attachment.setIdentifier(publication.getAttachments()[0].getIdentifier());
    assertEquals(attachment, publication.getAttachments()[0]);
    assertEquals(1, publication.getCatalogs().length);
    assertNotEquals(catalog.getIdentifier(), publication.getCatalogs()[0].getIdentifier());
    catalog.setIdentifier(publication.getCatalogs()[0].getIdentifier());
    assertEquals(catalog, publication.getCatalogs()[0]);
    assertEquals(1, publication.getTracks().length);
    assertNotEquals(track.getIdentifier(), publication.getTracks()[0].getIdentifier());
    track.setIdentifier(publication.getTracks()[0].getIdentifier());
    assertEquals(track, publication.getTracks()[0]);
}
Also used : HashMap(java.util.HashMap) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Result(org.opencastproject.job.api.JobBarrier.Result) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) JobContext(org.opencastproject.job.api.JobContext) Job(org.opencastproject.job.api.Job) Status(org.opencastproject.job.api.Job.Status) Publication(org.opencastproject.mediapackage.Publication) Catalog(org.opencastproject.mediapackage.Catalog) DownloadDistributionService(org.opencastproject.distribution.api.DownloadDistributionService) PublicationImpl(org.opencastproject.mediapackage.PublicationImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Aggregations

Publication (org.opencastproject.mediapackage.Publication)37 MediaPackage (org.opencastproject.mediapackage.MediaPackage)21 ArrayList (java.util.ArrayList)17 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)15 Job (org.opencastproject.job.api.Job)12 URI (java.net.URI)11 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)9 HashSet (java.util.HashSet)8 SimpleElementSelector (org.opencastproject.mediapackage.selector.SimpleElementSelector)7 PublicationException (org.opencastproject.publication.api.PublicationException)7 Test (org.junit.Test)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 Ignore (org.junit.Ignore)4 DistributionException (org.opencastproject.distribution.api.DistributionException)4 Attachment (org.opencastproject.mediapackage.Attachment)4 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)4 PublicationImpl (org.opencastproject.mediapackage.PublicationImpl)4 Track (org.opencastproject.mediapackage.Track)4 NotFoundException (org.opencastproject.util.NotFoundException)4 Event (org.opencastproject.index.service.impl.index.event.Event)3