use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class CommonEventCatalogUIAdapter method storeFields.
@Override
public Catalog storeFields(MediaPackage mediaPackage, MetadataCollection abstractMetadata) {
Catalog storeFields = super.storeFields(mediaPackage, abstractMetadata);
// Update the metadata stored in the mediapackage
MetadataField<?> presenters = abstractMetadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName());
if (presenters != null && presenters.isUpdated() && presenters.getValue() instanceof Iterable<?>) {
String[] creators = mediaPackage.getCreators();
for (String creator : creators) {
mediaPackage.removeCreator(creator);
}
for (String presenter : MetadataUtils.getIterableStringMetadata(presenters)) {
mediaPackage.addCreator(presenter);
}
}
MetadataField<?> series = abstractMetadata.getOutputFields().get(DublinCore.PROPERTY_IS_PART_OF.getLocalName());
if (series.getValue().isSome() && series.isUpdated()) {
if (isNotBlank(series.getValue().get().toString())) {
mediaPackage.setSeries(series.getValue().get().toString());
final Opt<String> seriesTitle = getSeriesTitle(series);
if (seriesTitle.isSome())
mediaPackage.setSeriesTitle(seriesTitle.get());
} else {
mediaPackage.setSeries(null);
mediaPackage.setSeriesTitle(null);
}
}
Opt<Date> startDate = MetadataUtils.getUpdatedDateMetadata(abstractMetadata, "startDate");
if (startDate != null && startDate.isSome())
mediaPackage.setDate(startDate.get());
// Update all the metadata related to the episode dublin core catalog
MetadataField<?> title = abstractMetadata.getOutputFields().get(DublinCore.PROPERTY_TITLE.getLocalName());
if (title != null && title.isUpdated()) {
mediaPackage.setTitle(title.getValue().get().toString());
}
return storeFields;
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class IndexServiceImpl method removeCatalogByFlavor.
@Override
public void removeCatalogByFlavor(Event event, MediaPackageElementFlavor flavor) throws IndexServiceException, NotFoundException, UnauthorizedException {
MediaPackage mediaPackage = getEventMediapackage(event);
Catalog[] catalogs = mediaPackage.getCatalogs(flavor);
if (catalogs.length == 0) {
throw new NotFoundException(String.format("Cannot find a catalog with flavor '%s' for event with id '%s'.", flavor.toString(), event.getIdentifier()));
}
for (Catalog catalog : catalogs) {
mediaPackage.remove(catalog);
}
switch(getEventSource(event)) {
case WORKFLOW:
Opt<WorkflowInstance> workflowInstance = getCurrentWorkflowInstance(event.getIdentifier());
if (workflowInstance.isNone()) {
logger.error("No workflow instance for event {} found!", event.getIdentifier());
throw new IndexServiceException("No workflow instance found for event " + event.getIdentifier());
}
try {
WorkflowInstance instance = workflowInstance.get();
instance.setMediaPackage(mediaPackage);
updateWorkflowInstance(instance);
} catch (WorkflowException e) {
logger.error("Unable to remove catalog with flavor {} by updating workflow event {} because {}", flavor, event.getIdentifier(), getStackTrace(e));
throw new IndexServiceException("Unable to update workflow event " + event.getIdentifier());
}
break;
case ARCHIVE:
assetManager.takeSnapshot(DEFAULT_OWNER, mediaPackage);
break;
case SCHEDULE:
try {
schedulerService.updateEvent(event.getIdentifier(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mediaPackage), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
} catch (SchedulerException e) {
logger.error("Unable to remove catalog with flavor {} by updating scheduled event {} because {}", flavor, event.getIdentifier(), getStackTrace(e));
throw new IndexServiceException("Unable to update scheduled event " + event.getIdentifier());
}
break;
default:
throw new IndexServiceException(String.format("Unable to handle event source type '%s'", getEventSource(event)));
}
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class EventIndexUtils method updateEvent.
/**
* Update the given {@link Event} with the given {@link MediaPackage}.
*
* @param event
* the event to update
* @param mp
* the mediapackage containing the metadata for the update
* @return the updated event
*/
public static Event updateEvent(Event event, MediaPackage mp) {
// Tracks
List<String> trackMimeTypes = new ArrayList<String>();
List<String> trackStreamResolutions = new ArrayList<String>();
List<String> trackFlavors = new ArrayList<String>();
for (Track t : mp.getTracks()) {
if (t.getMimeType() != null)
trackMimeTypes.add(t.getMimeType().toString());
if (t.getFlavor() != null)
trackFlavors.add(t.getFlavor().toString());
VideoStream[] streams = TrackSupport.byType(t.getStreams(), VideoStream.class);
for (VideoStream s : streams) {
trackStreamResolutions.add(s.getFrameWidth() + "x" + s.getFrameHeight());
}
}
event.setTrackMimetypes(trackMimeTypes);
event.setTrackStreamResolutions(trackStreamResolutions);
event.setTrackFlavors(trackFlavors);
// Metadata
List<String> metadataFlavors = new ArrayList<String>();
List<String> metadataMimetypes = new ArrayList<String>();
for (Catalog c : mp.getCatalogs()) {
if (c.getFlavor() != null)
metadataFlavors.add(c.getFlavor().toString());
if (c.getMimeType() != null)
metadataMimetypes.add(c.getMimeType().toString());
}
event.setMetadataFlavors(metadataFlavors);
event.setMetadataMimetypes(metadataMimetypes);
// Attachments
List<String> attachmentFlavors = new ArrayList<String>();
for (Attachment a : mp.getAttachments()) {
if (a.getFlavor() != null)
attachmentFlavors.add(a.getFlavor().toString());
}
event.setAttachmentFlavors(attachmentFlavors);
// Publications
List<Publication> publications = new ArrayList<Publication>();
for (Publication p : mp.getPublications()) {
publications.add(p);
}
event.setPublications(publications);
event.setSeriesName(mp.getSeriesTitle());
return event;
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class ConfigurableEventDCCatalogUIAdapter method getFields.
@Override
public MetadataCollection getFields(MediaPackage mediapackage) {
DublinCoreMetadataCollection dublinCoreMetadata = new DublinCoreMetadataCollection();
Set<String> emptyFields = new TreeSet<>(dublinCoreProperties.keySet());
if (mediapackage != null) {
for (Catalog catalog : mediapackage.getCatalogs(getFlavor())) {
getFieldValuesFromCatalog(dublinCoreMetadata, emptyFields, catalog);
}
}
populateEmptyFields(dublinCoreMetadata, emptyFields);
return dublinCoreMetadata;
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class ConfigurableEventDCCatalogUIAdapter method storeFields.
@Override
public Catalog storeFields(MediaPackage mediaPackage, MetadataCollection abstractMetadata) {
Catalog[] catalogs = mediaPackage.getCatalogs(getFlavor());
final Catalog catalog;
final DublinCoreCatalog dc;
final String filename;
if (catalogs.length == 0) {
catalog = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(org.opencastproject.mediapackage.MediaPackageElement.Type.Catalog, getFlavor());
catalog.setIdentifier(UUID.randomUUID().toString());
mediaPackage.add(catalog);
dc = DublinCores.mkSimple();
dc.addBindings(config.getXmlNamespaceContext());
dc.setRootTag(new EName(config.getCatalogXmlRootNamespace(), config.getCatalogXmlRootElementName()));
filename = "dublincore.xml";
} else {
catalog = catalogs[0];
dc = DublinCoreUtil.loadDublinCore(getWorkspace(), catalog);
dc.addBindings(config.getXmlNamespaceContext());
filename = FilenameUtils.getName(catalog.getURI().toString());
}
DublinCoreMetadataUtil.updateDublincoreCatalog(dc, abstractMetadata);
URI uri;
InputStream inputStream = null;
try {
inputStream = IOUtils.toInputStream(dc.toXmlString(), "UTF-8");
uri = getWorkspace().put(mediaPackage.getIdentifier().toString(), catalog.getIdentifier(), filename, inputStream);
catalog.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
catalog.setChecksum(null);
} catch (IOException e) {
logger.error("Unable to store catalog {} metadata to workspace: {}", catalog, ExceptionUtils.getStackTrace(e));
} finally {
IoSupport.closeQuietly(inputStream);
}
return catalog;
}
Aggregations