Search in sources :

Example 1 with PublicationImpl

use of org.opencastproject.mediapackage.PublicationImpl 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)

Example 2 with PublicationImpl

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

the class PublicationBuilderPlugin method elementFromManifest.

@Override
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer) throws UnsupportedElementException {
    String id = null;
    MimeType mimeType = null;
    MediaPackageElementFlavor flavor = null;
    String reference = null;
    String channel = null;
    URI url = null;
    long size = -1;
    Checksum checksum = null;
    try {
        // id
        id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);
        if (StringUtils.isEmpty(id)) {
            throw new UnsupportedElementException("Unvalid or missing id argument!");
        }
        // url
        url = serializer.decodeURI(new URI(xpath.evaluate("url/text()", elementNode).trim()));
        // channel
        channel = xpath.evaluate("@channel", elementNode).trim();
        if (StringUtils.isEmpty(channel)) {
            throw new UnsupportedElementException("Unvalid or missing channel argument!");
        }
        // reference
        reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);
        // size
        String trackSize = xpath.evaluate("size/text()", elementNode).trim();
        if (!"".equals(trackSize))
            size = Long.parseLong(trackSize);
        // flavor
        String flavorValue = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(flavorValue))
            flavor = MediaPackageElementFlavor.parseFlavor(flavorValue);
        // checksum
        String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
        String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
            checksum = Checksum.create(checksumType.trim(), checksumValue.trim());
        // mimetype
        String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotEmpty(mimeTypeValue)) {
            mimeType = MimeTypes.parseMimeType(mimeTypeValue);
        } else {
            throw new UnsupportedElementException("Unvalid or missing mimetype argument!");
        }
        // Build the publication element
        PublicationImpl publication = new PublicationImpl(id, channel, url, mimeType);
        if (StringUtils.isNotBlank(id))
            publication.setIdentifier(id);
        // Add url
        publication.setURI(url);
        // Add reference
        if (StringUtils.isNotEmpty(reference))
            publication.referTo(MediaPackageReferenceImpl.fromString(reference));
        // Set size
        if (size > 0)
            publication.setSize(size);
        // Set checksum
        if (checksum != null)
            publication.setChecksum(checksum);
        // Set mimetpye
        if (mimeType != null)
            publication.setMimeType(mimeType);
        if (flavor != null)
            publication.setFlavor(flavor);
        // description
        String description = (String) xpath.evaluate("description/text()", elementNode, XPathConstants.STRING);
        if (StringUtils.isNotBlank(description))
            publication.setElementDescription(description.trim());
        // tags
        NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
        for (int i = 0; i < tagNodes.getLength(); i++) {
            publication.addTag(tagNodes.item(i).getTextContent());
        }
        return publication;
    } catch (XPathExpressionException e) {
        throw new UnsupportedElementException("Error while reading track information from manifest: " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
    } catch (URISyntaxException e) {
        throw new UnsupportedElementException("Error while reading presenter track " + url + ": " + e.getMessage());
    }
}
Also used : XPathExpressionException(javax.xml.xpath.XPathExpressionException) NodeList(org.w3c.dom.NodeList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) URISyntaxException(java.net.URISyntaxException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) URI(java.net.URI) MimeType(org.opencastproject.util.MimeType) PublicationImpl(org.opencastproject.mediapackage.PublicationImpl) UnsupportedElementException(org.opencastproject.mediapackage.UnsupportedElementException) Checksum(org.opencastproject.util.Checksum)

Example 3 with PublicationImpl

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

the class PublicationBuilderPlugin method newElement.

@Override
public MediaPackageElement newElement(Type type, MediaPackageElementFlavor flavor) {
    Publication element = new PublicationImpl();
    element.setFlavor(flavor);
    return element;
}
Also used : PublicationImpl(org.opencastproject.mediapackage.PublicationImpl) Publication(org.opencastproject.mediapackage.Publication)

Example 4 with PublicationImpl

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

the class PublicationBuilderPlugin method elementFromURI.

@Override
public MediaPackageElement elementFromURI(URI uri) throws UnsupportedElementException {
    // TODO Auto-generated method stub
    logger.trace("Creating publication element from " + uri);
    Publication publication = new PublicationImpl();
    publication.setURI(uri);
    return publication;
}
Also used : PublicationImpl(org.opencastproject.mediapackage.PublicationImpl) Publication(org.opencastproject.mediapackage.Publication)

Example 5 with PublicationImpl

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

the class TestEventEndpoint method createEvent.

private Event createEvent(String id, String title, Source source) throws URISyntaxException {
    Event event = EasyMock.createNiceMock(Event.class);
    EasyMock.expect(event.getIdentifier()).andReturn(id).anyTimes();
    EasyMock.expect(event.getTitle()).andReturn(title).anyTimes();
    EasyMock.expect(event.getSeriesId()).andReturn("seriesId").anyTimes();
    EasyMock.expect(event.getReviewStatus()).andReturn(ReviewStatus.UNSENT.toString()).anyTimes();
    EasyMock.expect(event.getEventStatus()).andReturn("EVENTS.EVENTS.STATUS.ARCHIVE").anyTimes();
    EasyMock.expect(event.getOptedOut()).andReturn(true).anyTimes();
    EasyMock.expect(event.getRecordingStartDate()).andReturn("2013-03-20T04:00:00Z").anyTimes();
    EasyMock.expect(event.getRecordingEndDate()).andReturn("2013-03-20T05:00:00Z").anyTimes();
    EasyMock.expect(event.getTechnicalStartTime()).andReturn("2013-03-20T04:00:00Z").anyTimes();
    EasyMock.expect(event.getTechnicalEndTime()).andReturn("2013-03-20T05:00:00Z").anyTimes();
    EasyMock.expect(event.getWorkflowState()).andReturn(WorkflowInstance.WorkflowState.SUCCEEDED.name()).anyTimes();
    List<Publication> publist = new ArrayList<>();
    publist.add(new PublicationImpl("engage", "rest", new URI("engage.html?e=p-1"), MimeType.mimeType("text", "xml")));
    EasyMock.expect(event.getPublications()).andReturn(publist).anyTimes();
    EasyMock.expect(event.getAccessPolicy()).andReturn("{\"acl\":{\"ace\":[{\"allow\":true,\"action\":\"read\",\"role\":\"ROLE_ADMIN\"},{\"allow\":true,\"action\":\"write\",\"role\":\"ROLE_ADMIN\"}]}}\"").anyTimes();
    EasyMock.expect(event.hasRecordingStarted()).andReturn(true);
    // Simulate different event sources
    switch(source) {
        case ARCHIVE:
            EasyMock.expect(event.getArchiveVersion()).andReturn(1000L).anyTimes();
            break;
        case SCHEDULE:
            EasyMock.expect(event.getWorkflowId()).andReturn(1000L).anyTimes();
            break;
        default:
    }
    EasyMock.replay(event);
    return event;
}
Also used : PublicationImpl(org.opencastproject.mediapackage.PublicationImpl) ArrayList(java.util.ArrayList) Event(org.opencastproject.index.service.impl.index.event.Event) Publication(org.opencastproject.mediapackage.Publication) URI(java.net.URI)

Aggregations

PublicationImpl (org.opencastproject.mediapackage.PublicationImpl)5 Publication (org.opencastproject.mediapackage.Publication)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 Test (org.junit.Test)1 DownloadDistributionService (org.opencastproject.distribution.api.DownloadDistributionService)1 Event (org.opencastproject.index.service.impl.index.event.Event)1 Job (org.opencastproject.job.api.Job)1 Status (org.opencastproject.job.api.Job.Status)1 Result (org.opencastproject.job.api.JobBarrier.Result)1 JobContext (org.opencastproject.job.api.JobContext)1 Attachment (org.opencastproject.mediapackage.Attachment)1 Catalog (org.opencastproject.mediapackage.Catalog)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)1 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)1