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));
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations