use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class SchedulerUtil method toHumanReadableString.
/**
* Converts a scheduler event to a human readable string
*
* @param workspace
* the workspace
* @param catalogFlavors
* the event catalog flavors
* @param event
* the scheduler event
* @return a human readable string
*/
public static String toHumanReadableString(Workspace workspace, List<MediaPackageElementFlavor> catalogFlavors, SchedulerEvent event) {
TechnicalMetadata technicalMetadata = event.getTechnicalMetadata();
StringBuilder sb = new StringBuilder("Event: ").append(CharUtils.LF);
sb.append("- ").append(event.getEventId()).append(CharUtils.LF);
sb.append(CharUtils.LF);
sb.append("Version").append(CharUtils.LF);
sb.append("- ").append(event.getVersion()).append(CharUtils.LF);
sb.append(CharUtils.LF);
sb.append("Start").append(CharUtils.LF);
sb.append("- ").append(DateTimeSupport.toUTC(technicalMetadata.getStartDate().getTime())).append(CharUtils.LF);
sb.append(CharUtils.LF);
sb.append("End").append(CharUtils.LF);
sb.append("- ").append(DateTimeSupport.toUTC(technicalMetadata.getEndDate().getTime())).append(CharUtils.LF);
sb.append(CharUtils.LF);
sb.append("Room").append(CharUtils.LF);
sb.append("- ").append(technicalMetadata.getAgentId()).append(CharUtils.LF);
sb.append(CharUtils.LF);
sb.append("Scheduling configuration").append(CharUtils.LF);
sb.append("- optout: ").append(technicalMetadata.isOptOut()).append(CharUtils.LF);
for (Entry<String, String> entry : technicalMetadata.getCaptureAgentConfiguration().entrySet()) {
sb.append("- ").append(entry.getKey()).append(": ").append(entry.getValue()).append(CharUtils.LF);
}
sb.append(CharUtils.LF);
sb.append("Presenters").append(CharUtils.LF);
for (String presenter : technicalMetadata.getPresenters()) {
sb.append("- ").append(presenter).append(CharUtils.LF);
}
sb.append(CharUtils.LF);
sb.append("Workflow configuration").append(CharUtils.LF);
for (Entry<String, String> entry : technicalMetadata.getWorkflowProperties().entrySet()) {
sb.append("- ").append(entry.getKey()).append(": ").append(entry.getValue()).append(CharUtils.LF);
}
sb.append(CharUtils.LF);
for (Catalog c : $(event.getMediaPackage().getCatalogs())) {
if (!catalogFlavors.contains(c.getFlavor()))
continue;
DublinCoreCatalog dublinCore;
try {
dublinCore = DublinCoreUtil.loadDublinCore(workspace, c);
} catch (Exception e) {
logger.error("Unable to read event dublincore: {}", ExceptionUtils.getStackTrace(e));
continue;
}
sb.append("Event metadata ").append("(").append(c.getFlavor().toString()).append(")").append(CharUtils.LF);
for (Entry<EName, List<DublinCoreValue>> entry : dublinCore.getValues().entrySet()) {
EName eName = entry.getKey();
for (DublinCoreValue value : entry.getValue()) {
sb.append("- ").append(eName.getNamespaceURI()).append(":").append(eName.getLocalName()).append(": ").append(value.getValue());
boolean hasLanguageDefined = !DublinCore.LANGUAGE_UNDEFINED.equals(value.getLanguage());
if (hasLanguageDefined || value.getEncodingScheme().isSome()) {
sb.append(" (");
if (hasLanguageDefined) {
sb.append("lang:").append(value.getLanguage());
if (value.getEncodingScheme().isSome())
sb.append("/");
}
for (EName schema : value.getEncodingScheme()) {
sb.append(schema.getLocalName());
}
sb.append(")");
}
sb.append(CharUtils.LF);
}
}
sb.append(CharUtils.LF);
}
return sb.toString();
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class SchedulerUtil method calculateChecksum.
public static String calculateChecksum(Workspace workspace, List<MediaPackageElementFlavor> eventCatalogUIAdapterFlavors, Date startDateTime, Date endDateTime, String captureAgentId, Set<String> userIds, MediaPackage mediaPackage, Opt<DublinCoreCatalog> episodeDublincore, Map<String, String> wfProperties, Map<String, String> finalCaProperties, boolean optOut, AccessControlList acl) {
List<String> userIdsList = new ArrayList<>(userIds);
Collections.sort(userIdsList);
final MessageDigest messageDigest = mkMd5MessageDigest();
messageDigest.update(mkChecksumInput(startDateTime));
messageDigest.update(mkChecksumInput(endDateTime));
messageDigest.update(mkChecksumInput(captureAgentId));
for (String user : userIdsList) {
messageDigest.update(mkChecksumInput(user));
}
if (episodeDublincore.isSome()) {
Catalog episodeCatalog = $(mediaPackage.getCatalogs()).filter(MediaPackageSupport.Filters.isEpisodeDublinCore.toFn()).head2();
Checksum checksum = episodeCatalog.getChecksum();
if (checksum == null) {
checksum = DublinCoreUtil.calculateChecksum(episodeDublincore.get());
episodeCatalog.setChecksum(checksum);
}
messageDigest.update(mkChecksumInput(checksum.toString()));
}
// Add extended metadata to calculation
for (Catalog c : $(mediaPackage.getCatalogs()).sort(sortCatalogById)) {
if (eventCatalogUIAdapterFlavors.contains(c.getFlavor())) {
Checksum checksum = c.getChecksum();
if (checksum == null) {
DublinCoreCatalog dublinCore = DublinCoreUtil.loadDublinCore(workspace, c);
checksum = DublinCoreUtil.calculateChecksum(dublinCore);
c.setChecksum(checksum);
}
messageDigest.update(mkChecksumInput(checksum.toString()));
}
}
messageDigest.update(mkChecksumInput(AccessControlUtil.calculateChecksum(acl).toString()));
for (Entry<String, String> entry : new TreeMap<>(wfProperties).entrySet()) {
messageDigest.update(mkChecksumInput(entry.getKey()));
messageDigest.update(mkChecksumInput(entry.getValue()));
}
for (Entry<String, String> entry : new TreeMap<>(finalCaProperties).entrySet()) {
messageDigest.update(mkChecksumInput(entry.getKey()));
messageDigest.update(mkChecksumInput(entry.getValue()));
}
messageDigest.update(mkChecksumInput(optOut));
return Checksum.convertToHex(messageDigest.digest());
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class SchedulerUtilTest method testSortByCatalogId.
@Test
public void testSortByCatalogId() throws Exception {
String catalogId = "b";
Catalog catalog = CatalogImpl.fromURI(new URI("location" + catalogId));
catalog.setIdentifier(catalogId);
String extendedCatalogId = "a";
Catalog extendedCatalog = CatalogImpl.fromURI(new URI("location" + extendedCatalogId));
extendedCatalog.setIdentifier(extendedCatalogId);
Assert.assertEquals(1, SchedulerUtil.sortCatalogById.compare(catalog, extendedCatalog));
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class SchedulerRestService method addCatalog.
private MediaPackage addCatalog(Workspace workspace, InputStream in, String fileName, MediaPackageElementFlavor flavor, MediaPackage mediaPackage) throws IOException {
Catalog[] catalogs = mediaPackage.getCatalogs(flavor);
Catalog c = null;
if (catalogs.length == 1)
c = catalogs[0];
// If catalog found, create a new one
if (c == null) {
c = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(MediaPackageElement.Type.Catalog, flavor);
c.setIdentifier(UUID.randomUUID().toString());
logger.info("Adding catalog with flavor {} to mediapackage {}", flavor, mediaPackage);
mediaPackage.add(c);
}
// Update comments catalog
try {
URI catalogUrl = workspace.put(mediaPackage.getIdentifier().compact(), c.getIdentifier(), fileName, in);
c.setURI(catalogUrl);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
} finally {
IOUtils.closeQuietly(in);
}
return mediaPackage;
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class CaptureNowProlongingService method prolongEvent.
/**
* Extends the current recording.
*
* @param event
* the recording's media package
* @param dublinCore
* the recording's dublin core catalog
* @param agentId
* the agent
* @throws UnauthorizedException
* if the event cannot be updated due to a lack of access rights
* @throws NotFoundException
* if the event cannot be found
* @throws SchedulerException
* if updating the scheduling data fails
* @throws IOException
* if updating the calendar to the worksapce fails
* @throws IllegalArgumentException
* if a URI cannot be created using the arguments provided
*/
public void prolongEvent(MediaPackage event, DublinCoreCatalog dublinCore, String agentId) throws UnauthorizedException, NotFoundException, SchedulerException, IllegalArgumentException, IOException {
String eventId = event.getIdentifier().compact();
DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(dublinCore.getFirst(DublinCore.PROPERTY_TEMPORAL));
Date prolongedEndDate = new DateTime(period.getEnd()).plus(getProlongingTime()).toDate();
dublinCore.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(period.getStart(), prolongedEndDate), Precision.Second));
List<MediaPackage> events = schedulerService.findConflictingEvents(agentId, period.getStart(), prolongedEndDate);
for (MediaPackage conflictMediaPackage : events) {
if (eventId.equals(conflictMediaPackage.getIdentifier().compact()))
continue;
Opt<DublinCoreCatalog> conflictingDc = DublinCoreUtil.loadEpisodeDublinCore(workspace, conflictMediaPackage);
if (conflictingDc.isNone())
continue;
Date conflictingStartDate = EncodingSchemeUtils.decodeMandatoryPeriod(conflictingDc.get().getFirst(DublinCore.PROPERTY_TEMPORAL)).getStart();
prolongedEndDate = new DateTime(conflictingStartDate).minusMinutes(1).toDate();
dublinCore.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(period.getStart(), prolongedEndDate), Precision.Second));
logger.info("A scheduled event is preventing the current recording on agent '{}' to be further extended. Extending to one minute before the conflicting event", agentId);
stop(agentId);
break;
}
// Update the episode dublin core
Catalog[] episodeCatalogs = event.getCatalogs(MediaPackageElements.EPISODE);
if (episodeCatalogs.length > 0) {
Catalog c = episodeCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(event.getIdentifier().toString(), c.getIdentifier(), filename, IOUtils.toInputStream(dublinCore.toXmlString(), "UTF-8"));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
}
schedulerService.updateEvent(eventId, Opt.<Date>none(), Opt.some(prolongedEndDate), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(event), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
}
Aggregations