Search in sources :

Example 31 with DublinCoreCatalog

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

the class LiveScheduleServiceImplTest method testCreateLiveEvent.

@Test
public void testCreateLiveEvent() throws Exception {
    URI mpURI = LiveScheduleServiceImplTest.class.getResource("/assetmanager-mp.xml").toURI();
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mpURI.toURL().openStream());
    setUpAssetManager(mp);
    URI catalogURI = LiveScheduleServiceImplTest.class.getResource("/episode.xml").toURI();
    DublinCoreCatalog episodeDC = DublinCores.read(catalogURI.toURL().openStream());
    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);
    EasyMock.expect(serviceRegistry.getJob(1L)).andReturn(job).anyTimes();
    Job jobPub = createJob(2L, "anything", "anything");
    Capture<MediaPackage> capturedMp = Capture.newInstance();
    EasyMock.expect(searchService.add(EasyMock.capture(capturedMp))).andReturn(jobPub);
    EasyMock.expect(serviceRegistry.getJob(2L)).andReturn(job).anyTimes();
    Capture<MediaPackage> capturedSnapshotMp = Capture.newInstance();
    Version v = EasyMock.createNiceMock(Version.class);
    Snapshot s = EasyMock.createNiceMock(Snapshot.class);
    EasyMock.expect(s.getVersion()).andReturn(v);
    EasyMock.replay(s, v);
    EasyMock.expect(assetManager.takeSnapshot(EasyMock.capture(capturedSnapshotMp))).andReturn(s);
    replayServices();
    service.setDownloadDistributionService(downloadDistributionService);
    service.createLiveEvent(MP_ID, episodeDC);
    // Check published live media package
    MediaPackage searchMp = capturedMp.getValue();
    Assert.assertEquals(MP_ID, searchMp.getIdentifier().compact());
    Assert.assertEquals(DURATION, searchMp.getDuration().longValue());
    Assert.assertEquals(2, searchMp.getCatalogs().length);
    assertExpectedLiveTracks(searchMp.getTracks(), DURATION, CAPTURE_AGENT_NAME, "_suffix", false);
    // Check archived media package
    MediaPackage archivedMp = capturedSnapshotMp.getValue();
    Assert.assertEquals(MP_ID, archivedMp.getIdentifier().compact());
    Assert.assertEquals(1, archivedMp.getPublications().length);
    Assert.assertEquals(LiveScheduleService.CHANNEL_ID, archivedMp.getPublications()[0].getChannel());
    // Check that version got into local cache
    Assert.assertEquals(v, service.getSnapshotVersionCache().getIfPresent(MP_ID));
}
Also used : Snapshot(org.opencastproject.assetmanager.api.Snapshot) Set(java.util.Set) Version(org.opencastproject.assetmanager.api.Version) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Test(org.junit.Test)

Example 32 with DublinCoreCatalog

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

the class AnimateWorkflowOperationHandler method getMetadata.

private Map<String, String> getMetadata(MediaPackage mediaPackage) {
    Map<String, String> metadata = new HashMap<>();
    // get episode metadata
    MediaPackageElementFlavor[] flavors = { MediaPackageElements.EPISODE, MediaPackageElements.SERIES };
    for (MediaPackageElementFlavor flavor : flavors) {
        // Get metadata catalogs
        for (Catalog catalog : mediaPackage.getCatalogs(flavor)) {
            DublinCoreCatalog dc = DublinCoreUtil.loadDublinCore(workspace, catalog);
            for (Map.Entry<EName, List<DublinCoreValue>> entry : dc.getValues().entrySet()) {
                String key = String.format("%s.%s", flavor.getSubtype(), entry.getKey().getLocalName());
                String value = entry.getValue().get(0).getValue();
                metadata.put(key, value);
                logger.debug("metadata: {} -> {}", key, value);
            }
        }
    }
    return metadata;
}
Also used : EName(org.opencastproject.mediapackage.EName) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) HashMap(java.util.HashMap) Map(java.util.Map) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 33 with DublinCoreCatalog

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

the class SchedulerMigrationService method schedule.

void schedule(SchedulerTransaction tx, Event event) {
    final Map<String, String> wfProperties = Collections.emptyMap();
    final Map<String, String> caMetadata = PropertiesUtil.toMap(event.captureAgentProperites);
    final MediaPackage mp = mkMediaPackage();
    mp.setIdentifier(new IdImpl(event.mediaPackageId));
    // create the catalog
    final DublinCoreCatalog dc = event.dublinCore;
    mp.setSeries(dc.getFirst(DublinCore.PROPERTY_IS_PART_OF));
    // and make them available for download in the workspace
    dc.setURI(storeInWs(event.mediaPackageId, dc.getIdentifier(), "dc-episode.xml", inputStream(dc)));
    // add them to the media package
    mp.add(dc);
    // add acl to the media package
    for (AccessControlList acl : event.accessControlList) {
        authorizationService.setAcl(mp, AclScope.Episode, acl);
    }
    // 
    // add to scheduler service
    Tuple<Date, Date> schedulingDate = getSchedulingDate(dc);
    String caId = dc.getFirst(DublinCore.PROPERTY_SPATIAL);
    try {
        tx.addEvent(schedulingDate.getA(), schedulingDate.getB(), caId, Collections.<String>emptySet(), mp, wfProperties, caMetadata, Opt.some(event.optOut));
    } catch (UnauthorizedException e) {
        logger.error("Not authorized to schedule an event", e);
        chuck(e);
    } catch (SchedulerException e) {
        logger.warn("Not able to schedule event.", e);
        chuck(e);
    } catch (NotFoundException e) {
        logger.error("Transaction disappeared");
        chuck(e);
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) Date(java.util.Date)

Example 34 with DublinCoreCatalog

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

the class EmailTemplateServiceImpl method initCatalogs.

/**
 * Initializes the map with all fields from the dublin core catalogs.
 */
private HashMap<String, HashMap<String, String>> initCatalogs(MediaPackage mediaPackage) {
    HashMap<String, HashMap<String, String>> catalogs = new HashMap<String, HashMap<String, String>>();
    Catalog[] dcs = mediaPackage.getCatalogs(DublinCoreCatalog.ANY_DUBLINCORE);
    for (int i = 0; dcs != null && i < dcs.length; i++) {
        DublinCoreCatalog dc = null;
        InputStream in = null;
        try {
            File f = workspace.get(dcs[i].getURI());
            in = new FileInputStream(f);
            dc = DublinCores.read(in);
        } catch (Exception e) {
            logger.warn("Error when populating catalog data", e);
            // Don't include the info
            continue;
        } finally {
            IOUtils.closeQuietly(in);
        }
        if (dc != null) {
            String catalogFlavor = dcs[i].getFlavor().getSubtype();
            HashMap<String, String> catalogHash = new HashMap<String, String>();
            for (EName ename : dc.getProperties()) {
                String name = ename.getLocalName();
                catalogHash.put(name, dc.getAsText(ename, DublinCore.LANGUAGE_ANY, DEFAULT_DELIMITER_FOR_MULTIPLE));
            }
            catalogs.put(catalogFlavor, catalogHash);
        }
    }
    return catalogs;
}
Also used : EName(org.opencastproject.mediapackage.EName) HashMap(java.util.HashMap) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) FileInputStream(java.io.FileInputStream) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) File(java.io.File)

Example 35 with DublinCoreCatalog

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

the class SchedulerServiceImpl method getCalendar.

@Override
public String getCalendar(Opt<String> captureAgentId, Opt<String> seriesId, Opt<Date> cutoff) throws SchedulerException {
    try {
        AQueryBuilder query = assetManager.createQuery();
        Props p = new Props(query);
        Predicate predicate = withOrganization(query).and(withOwner(query)).and(query.hasPropertiesOf(p.namespace())).and(p.optOut().eq(false)).and(withVersion(query)).and(p.end().ge(DateTime.now().minusHours(1).toDate()));
        for (String agentId : captureAgentId) {
            predicate = predicate.and(p.agent().eq(agentId));
        }
        for (String series : seriesId) {
            predicate = predicate.and(query.seriesId().eq(series));
        }
        for (Date d : cutoff) {
            predicate = predicate.and(p.start().le(d));
        }
        ASelectQuery select = query.select(query.snapshot(), p.agent().target(), p.start().target(), p.end().target(), query.propertiesOf(CA_NAMESPACE)).where(predicate);
        Stream<ARecord> records = select.run().getRecords();
        CalendarGenerator cal = new CalendarGenerator(seriesService);
        for (ARecord record : records) {
            boolean blacklisted;
            // isBlacklisted() methods are not implemented in the persistence layer and return always false
            // try {
            // //blacklisted = isBlacklisted(record.getMediaPackageId());
            // } catch (NotFoundException e) {
            // continue;
            // }
            blacklisted = false;
            // Skip blacklisted events
            if (blacklisted)
                continue;
            Opt<MediaPackage> optMp = record.getSnapshot().map(episodeToMp);
            // If the event media package is empty, skip the event
            if (optMp.isNone()) {
                logger.warn("Mediapackage for event '{}' can't be found, event is not recorded", record.getMediaPackageId());
                continue;
            }
            Opt<DublinCoreCatalog> catalogOpt = loadEpisodeDublinCoreFromAsset(record.getSnapshot().get());
            if (catalogOpt.isNone()) {
                logger.warn("No episode catalog available, skipping!");
                continue;
            }
            Map<String, String> caMetadata = record.getProperties().filter(filterByNamespace._2(CA_NAMESPACE)).group(toKey, toValue);
            // If the even properties are empty, skip the event
            if (caMetadata.isEmpty()) {
                logger.warn("Properties for event '{}' can't be found, event is not recorded", record.getMediaPackageId());
                continue;
            }
            String agentId = record.getProperties().apply(Properties.getString(AGENT_CONFIG));
            Date start = record.getProperties().apply(Properties.getDate(START_DATE_CONFIG));
            Date end = record.getProperties().apply(Properties.getDate(END_DATE_CONFIG));
            Date lastModified = record.getSnapshot().get().getArchivalDate();
            // Add the entry to the calendar, skip it with a warning if adding fails
            try {
                cal.addEvent(optMp.get(), catalogOpt.get(), agentId, start, end, lastModified, toPropertyString(caMetadata));
            } catch (Exception e) {
                logger.warn("Error adding event '{}' to calendar, event is not recorded: {}", record.getMediaPackageId(), getStackTrace(e));
                continue;
            }
        }
        // Only validate calendars with events. Without any events, the iCalendar won't validate
        if (cal.getCalendar().getComponents().size() > 0) {
            try {
                cal.getCalendar().validate();
            } catch (ValidationException e) {
                logger.warn("Recording calendar could not be validated (returning it anyways): {}", getStackTrace(e));
            }
        }
        return cal.getCalendar().toString();
    } catch (Exception e) {
        if (e instanceof SchedulerException)
            throw e;
        logger.error("Failed getting calendar: {}", getStackTrace(e));
        throw new SchedulerException(e);
    }
}
Also used : ValidationException(net.fortuna.ical4j.model.ValidationException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) Log.getHumanReadableTimeString(org.opencastproject.util.Log.getHumanReadableTimeString) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) IOException(java.io.IOException) ServiceException(org.osgi.framework.ServiceException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SeriesException(org.opencastproject.series.api.SeriesException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ValidationException(net.fortuna.ical4j.model.ValidationException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) Predicate(org.opencastproject.assetmanager.api.query.Predicate) ARecord(org.opencastproject.assetmanager.api.query.ARecord) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ASelectQuery(org.opencastproject.assetmanager.api.query.ASelectQuery) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

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