Search in sources :

Example 66 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class LiveScheduleServiceImpl method addAndDistributeElements.

MediaPackage addAndDistributeElements(Snapshot snapshot) throws LiveScheduleException {
    try {
        MediaPackage mp = (MediaPackage) snapshot.getMediaPackage().clone();
        Set<String> elementIds = new HashSet<String>();
        // Then, add series catalog if needed
        if (StringUtils.isNotEmpty(mp.getSeries())) {
            DublinCoreCatalog catalog = seriesService.getSeries(mp.getSeries());
            // Create temporary catalog and save to workspace
            mp.add(catalog);
            URI uri = workspace.put(mp.getIdentifier().toString(), catalog.getIdentifier(), "series.xml", dublinCoreService.serialize(catalog));
            catalog.setURI(uri);
            catalog.setChecksum(null);
            catalog.setFlavor(MediaPackageElements.SERIES);
            elementIds.add(catalog.getIdentifier());
        }
        if (mp.getCatalogs(MediaPackageElements.EPISODE).length > 0)
            elementIds.add(mp.getCatalogs(MediaPackageElements.EPISODE)[0].getIdentifier());
        if (mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE).length > 0)
            elementIds.add(mp.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE)[0].getIdentifier());
        // Distribute element(s)
        Job distributionJob = downloadDistributionService.distribute(CHANNEL_ID, mp, elementIds, false);
        if (!waitForStatus(distributionJob).isSuccess())
            throw new LiveScheduleException("Element(s) for live media package " + mp.getIdentifier() + " could not be distributed");
        for (String id : elementIds) {
            MediaPackageElement e = mp.getElementById(id);
            // Cleanup workspace/wfr
            mp.remove(e);
            workspace.delete(e.getURI());
        }
        // Add distributed element(s) to mp
        List<MediaPackageElement> distributedElements = (List<MediaPackageElement>) MediaPackageElementParser.getArrayFromXml(distributionJob.getPayload());
        for (MediaPackageElement mpe : distributedElements) mp.add(mpe);
        return mp;
    } catch (LiveScheduleException e) {
        throw e;
    } catch (Exception e) {
        throw new LiveScheduleException(e);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) List(java.util.List) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) LiveScheduleException(org.opencastproject.liveschedule.api.LiveScheduleException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) HashSet(java.util.HashSet)

Example 67 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SchedulerUpdateHandler method execute.

@Override
protected void execute(MessageItem messageItem) {
    SchedulerItem schedulerItem = (SchedulerItem) messageItem;
    String mpId = schedulerItem.getMediaPackageId();
    try {
        logger.debug("Scheduler message handler START for mp {} event type {} in thread {}", mpId, schedulerItem.getType(), Thread.currentThread().getId());
        switch(schedulerItem.getType()) {
            case UpdateCatalog:
                if (isLive(mpId))
                    liveScheduleService.createOrUpdateLiveEvent(mpId, schedulerItem.getEvent());
                break;
            case UpdateAcl:
                if (isLive(mpId))
                    liveScheduleService.updateLiveEventAcl(mpId, schedulerItem.getAcl());
                break;
            case UpdateProperties:
                // Workflow properties may have been updated (publishLive configuration)
                String publishLive = schedulerItem.getProperties().get(PUBLISH_LIVE_PROPERTY);
                if (publishLive == null)
                    // Not specified so we do nothing. We don't want to delete if we got incomplete props.
                    return;
                else if (BooleanUtils.toBoolean(publishLive)) {
                    DublinCoreCatalog episodeDC = schedulerService.getDublinCore(mpId);
                    liveScheduleService.createOrUpdateLiveEvent(mpId, episodeDC);
                } else
                    liveScheduleService.deleteLiveEvent(mpId);
                break;
            case Delete:
            case DeleteRecordingStatus:
                if (isLive(mpId))
                    liveScheduleService.deleteLiveEvent(mpId);
                break;
            case UpdateAgentId:
            case UpdateStart:
            case UpdateEnd:
                if (isLive(mpId)) {
                    DublinCoreCatalog episodeDC = schedulerService.getDublinCore(mpId);
                    liveScheduleService.createOrUpdateLiveEvent(mpId, episodeDC);
                }
                break;
            case UpdateRecordingStatus:
                String state = schedulerItem.getRecordingState();
                if (RecordingState.CAPTURE_FINISHED.equals(state) || RecordingState.UPLOADING.equals(state) || RecordingState.UPLOADING.equals(state) || RecordingState.CAPTURE_ERROR.equals(state) || RecordingState.UPLOAD_ERROR.equals(state))
                    if (isLive(mpId))
                        liveScheduleService.deleteLiveEvent(mpId);
                break;
            case UpdateOptOut:
            case UpdateBlacklist:
            case UpdatePresenters:
            case UpdateReviewStatus:
                break;
            default:
                throw new IllegalArgumentException("Unhandled type of SchedulerItem");
        }
    } catch (Exception e) {
        logger.warn(String.format("Exception occurred for mp %s, event type %s", mpId, schedulerItem.getType()), e);
    } finally {
        logger.debug("Scheduler message handler END for mp {} event type {} in thread {}", mpId, schedulerItem.getType(), Thread.currentThread().getId());
    }
}
Also used : SchedulerItem(org.opencastproject.message.broker.api.scheduler.SchedulerItem) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 68 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class LiveScheduleServiceImplTest method testAddAndDistributeElements.

@Test
public void testAddAndDistributeElements() throws Exception {
    URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/series.xml").toURI();
    DublinCoreCatalog seriesDC = DublinCores.read(catalogURI.toURL().openStream());
    EasyMock.expect(seriesService.getSeries(SERIES_ID)).andReturn(seriesDC).anyTimes();
    Job job = createJob(1L, "anything", "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"9ad6ebcb-b414-4b15-ab62-5e5ddede447e\" type=\"dublincore/episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/episode.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<catalog id=\"23113662-1a84-457a-85d5-0b3e32d2413a\" type=\"dublincore/series\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/series.xml</url></catalog>" + "###<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<attachment id=\"security-policy-episode\" type=\"security/xacml+episode\" xmlns=\"http://mediapackage.opencastproject.org\">" + "<mimetype>text/xml</mimetype>" + "<url>http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml</url></attachment>");
    EasyMock.expect(downloadDistributionService.distribute(EasyMock.anyString(), EasyMock.anyObject(MediaPackage.class), EasyMock.anyObject(Set.class), EasyMock.anyBoolean())).andReturn(job).once();
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    replayServices();
    Snapshot s = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(s.getMediaPackage()).andReturn(mp);
    EasyMock.replay(s);
    service.setDownloadDistributionService(downloadDistributionService);
    MediaPackage mp1 = service.addAndDistributeElements(s);
    Catalog[] catalogs = mp1.getCatalogs(MediaPackageElements.EPISODE);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    Catalog catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/episode.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/episode", catalog.getFlavor().toString());
    catalogs = mp1.getCatalogs(MediaPackageElements.SERIES);
    Assert.assertNotNull(catalogs);
    Assert.assertEquals(1, catalogs.length);
    catalog = catalogs[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/series.xml", catalog.getURI().toString());
    Assert.assertEquals("dublincore/series", catalog.getFlavor().toString());
    Attachment[] atts = mp1.getAttachments(MediaPackageElements.XACML_POLICY_EPISODE);
    Assert.assertNotNull(atts);
    Assert.assertEquals(1, atts.length);
    Attachment att = atts[0];
    Assert.assertEquals("http://10.10.10.50/static/mh_default_org/engage-live/security_policy_episode.xml", att.getURI().toString());
    Assert.assertEquals("security/xacml+episode", att.getFlavor().toString());
    EasyMock.verify(downloadDistributionService, workspace);
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Attachment(org.opencastproject.mediapackage.Attachment) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Catalog(org.opencastproject.mediapackage.Catalog) Test(org.junit.Test)

Example 69 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SchedulerMigrationService method transform.

/**
 * Transform the event result set into {@link Event}s.
 */
List<Event> transform(ResultSet resultSet) {
    try {
        List<Event> events = new ArrayList<>();
        while (resultSet.next()) {
            DublinCoreCatalog dc = readDublinCoreSilent(resultSet.getString(5));
            dc.setIdentifier(UUID.randomUUID().toString());
            dc.setFlavor(MediaPackageElements.EPISODE);
            dc.remove(DublinCore.PROPERTY_IDENTIFIER);
            Properties properties = parseProperties(resultSet.getString(4));
            AccessControlList acl = resultSet.getString(2) != null ? AccessControlParser.parseAclSilent(resultSet.getString(2)) : null;
            events.add(new Event(resultSet.getLong(1), resultSet.getString(6), dc, properties, acl, resultSet.getBoolean(7), ReviewStatus.valueOf(resultSet.getString(9)), resultSet.getDate(8)));
        }
        return events;
    } catch (Exception e) {
        return chuck(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ArrayList(java.util.ArrayList) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Properties(java.util.Properties) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) ConfigurationException(org.osgi.service.cm.ConfigurationException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SAXException(org.xml.sax.SAXException) SQLException(java.sql.SQLException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 70 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class IndexServiceImplTest method testUpdateMediaPackageMetadata.

@Test
public void testUpdateMediaPackageMetadata() throws Exception {
    // mock/initialize dependencies
    String username = "user1";
    String org = "mh_default_org";
    String testResourceLocation = "/events/update-event.json";
    String metadataJson = IOUtils.toString(getClass().getResourceAsStream(testResourceLocation));
    MetadataCollection metadataCollection = new DublinCoreMetadataCollection();
    metadataCollection.addField(MetadataField.createTextMetadataField("title", Opt.some("title"), "EVENTS.EVENTS.DETAILS.METADATA.TITLE", false, true, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    metadataCollection.addField(MetadataField.createTextLongMetadataField("creator", Opt.some("creator"), "EVENTS.EVENTS.DETAILS.METADATA.PRESENTERS", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    metadataCollection.addField(MetadataField.createTextMetadataField("isPartOf", Opt.some("isPartOf"), "EVENTS.EVENTS.DETAILS.METADATA.SERIES", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    MetadataList metadataList = new MetadataList(metadataCollection, metadataJson);
    String eventId = "event-1";
    Event event = new Event(eventId, org);
    event.setTitle("Test Event 1");
    SearchQuery query = EasyMock.createMock(SearchQuery.class);
    EasyMock.expect(query.getLimit()).andReturn(100);
    EasyMock.expect(query.getOffset()).andReturn(0);
    EasyMock.replay(query);
    SearchResultItemImpl<Event> searchResultItem = new SearchResultItemImpl<>(1.0, event);
    SearchResultImpl<Event> searchResult = new SearchResultImpl<>(query, 0, 0);
    searchResult.addResultItem(searchResultItem);
    SecurityService securityService = setupSecurityService(username, org);
    AbstractSearchIndex index = EasyMock.createMock(AbstractSearchIndex.class);
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(getClass().getResourceAsStream("/events/update-event-mp.xml"));
    EasyMock.expect(index.getByQuery(EasyMock.anyObject(EventSearchQuery.class))).andReturn(searchResult);
    EasyMock.replay(index);
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(getClass().getResource("/dublincore.xml").toURI()).anyTimes();
    EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
    EasyMock.replay(workspace);
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
    // Using scheduler as the source of the media package here.
    SchedulerService schedulerService = EasyMock.createMock(SchedulerService.class);
    EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(mp);
    Capture<Opt<MediaPackage>> mpCapture = new Capture<>();
    schedulerService.updateEvent(EasyMock.anyString(), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.capture(mpCapture), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyString());
    EasyMock.expectLastCall();
    EasyMock.replay(schedulerService);
    SeriesService seriesService = EasyMock.createMock(SeriesService.class);
    DublinCoreCatalog seriesDC = DublinCores.read(getClass().getResourceAsStream("/events/update-event-series.xml"));
    EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesDC);
    EasyMock.expect(seriesService.getSeriesAccessControl(EasyMock.anyString())).andReturn(null);
    EasyMock.expect(seriesService.getSeriesElements(EasyMock.anyString())).andReturn(Opt.none());
    EasyMock.replay(seriesService);
    // create service
    IndexServiceImpl indexService = new IndexServiceImpl();
    indexService.setSecurityService(securityService);
    indexService.setSchedulerService(schedulerService);
    indexService.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexService.addCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexService.setSeriesService(seriesService);
    indexService.setWorkspace(workspace);
    MetadataList updateEventMetadata = indexService.updateEventMetadata(org, metadataList, index);
    Assert.assertTrue(mpCapture.hasCaptured());
    Assert.assertEquals("series-1", mp.getSeries());
    Assert.assertEquals(1, mp.getCatalogs(MediaPackageElements.SERIES).length);
}
Also used : DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) SearchQuery(org.opencastproject.matterhorn.search.SearchQuery) SearchResultItemImpl(org.opencastproject.matterhorn.search.impl.SearchResultItemImpl) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) Capture(org.easymock.Capture) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) AbstractSearchIndex(org.opencastproject.index.service.impl.index.AbstractSearchIndex) Opt(com.entwinemedia.fn.data.Opt) SearchResultImpl(org.opencastproject.matterhorn.search.impl.SearchResultImpl) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Aggregations

DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)117 MediaPackage (org.opencastproject.mediapackage.MediaPackage)51 NotFoundException (org.opencastproject.util.NotFoundException)46 Test (org.junit.Test)44 Date (java.util.Date)40 IOException (java.io.IOException)30 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)29 URI (java.net.URI)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 SeriesException (org.opencastproject.series.api.SeriesException)20 ArrayList (java.util.ArrayList)18 Catalog (org.opencastproject.mediapackage.Catalog)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)18 EName (org.opencastproject.mediapackage.EName)17 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)15 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)15 InputStream (java.io.InputStream)14 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)14