use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class IndexServiceImpl method updateDublincCoreCatalog.
/**
* @param mp
* the mediapackage to update
* @param dc
* the dublincore metadata to use to update the mediapackage
* @return the updated mediapackage
* @throws IOException
* Thrown if an IO error occurred adding the dc catalog file
* @throws MediaPackageException
* Thrown if an error occurred updating the mediapackage
* @throws IngestException
* Thrown if an error occurred attaching the catalog to the mediapackage
*/
private MediaPackage updateDublincCoreCatalog(MediaPackage mp, DublinCoreCatalog dc) throws IOException, MediaPackageException, IngestException {
try (InputStream inputStream = IOUtils.toInputStream(dc.toXmlString(), "UTF-8")) {
// Update dublincore catalog
Catalog[] catalogs = mp.getCatalogs(MediaPackageElements.EPISODE);
if (catalogs.length > 0) {
Catalog catalog = catalogs[0];
URI uri = workspace.put(mp.getIdentifier().toString(), catalog.getIdentifier(), "dublincore.xml", inputStream);
catalog.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
catalog.setChecksum(null);
} else {
mp = ingestService.addCatalog(inputStream, "dublincore.xml", MediaPackageElements.EPISODE, mp);
}
}
return mp;
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class IndexServiceImpl method createSeries.
@Override
public String createSeries(MetadataList metadataList, Map<String, String> options, Opt<AccessControlList> optAcl, Opt<Long> optThemeId) throws IndexServiceException {
DublinCoreCatalog dc = DublinCores.mkOpencastSeries().getCatalog();
dc.set(PROPERTY_IDENTIFIER, UUID.randomUUID().toString());
dc.set(DublinCore.PROPERTY_CREATED, EncodingSchemeUtils.encodeDate(new Date(), Precision.Second));
for (Entry<String, String> entry : options.entrySet()) {
dc.set(new EName(DublinCores.OC_PROPERTY_NS_URI, entry.getKey()), entry.getValue());
}
Opt<MetadataCollection> seriesMetadata = metadataList.getMetadataByFlavor(MediaPackageElements.SERIES.toString());
if (seriesMetadata.isSome()) {
DublinCoreMetadataUtil.updateDublincoreCatalog(dc, seriesMetadata.get());
}
AccessControlList acl;
if (optAcl.isSome()) {
acl = optAcl.get();
} else {
acl = new AccessControlList();
}
String seriesId;
try {
DublinCoreCatalog createdSeries = seriesService.updateSeries(dc);
seriesId = createdSeries.getFirst(PROPERTY_IDENTIFIER);
seriesService.updateAccessControl(seriesId, acl);
for (Long id : optThemeId) seriesService.updateSeriesProperty(seriesId, THEME_PROPERTY_NAME, Long.toString(id));
} catch (Exception e) {
logger.error("Unable to create new series: {}", getStackTrace(e));
throw new IndexServiceException("Unable to create new series");
}
updateSeriesMetadata(seriesId, metadataList);
return seriesId;
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SeriesMessageReceiverImpl method execute.
@Override
protected void execute(SeriesItem seriesItem) {
Series series = null;
String organization = getSecurityService().getOrganization().getId();
User user = getSecurityService().getUser();
switch(seriesItem.getType()) {
case UpdateCatalog:
logger.debug("Received Update Series for index {}", getSearchIndex().getIndexName());
DublinCoreCatalog dc = seriesItem.getMetadata();
String seriesId = dc.getFirst(DublinCoreCatalog.PROPERTY_IDENTIFIER);
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesId, organization, user, getSearchIndex());
series.setCreator(getSecurityService().getUser().getName());
SeriesIndexUtils.updateSeries(series, dc);
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesId, ExceptionUtils.getStackTrace(e));
return;
}
// Update the event series titles if they changed
try {
SeriesIndexUtils.updateEventSeriesTitles(series, organization, getSecurityService().getUser(), getSearchIndex());
} catch (SearchIndexException e) {
logger.error("Error updating the series name of series {} from the associated events: {}", series.getIdentifier(), ExceptionUtils.getStackTrace(e));
}
// Persist the series
update(seriesItem.getSeriesId(), series);
break;
case UpdateAcl:
logger.debug("Received Update Series ACL for index {}", getSearchIndex().getIndexName());
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesItem.getSeriesId(), organization, user, getSearchIndex());
List<ManagedAcl> acls = aclServiceFactory.serviceFor(getSecurityService().getOrganization()).getAcls();
Option<ManagedAcl> managedAcl = AccessInformationUtil.matchAcls(acls, seriesItem.getAcl());
if (managedAcl.isSome())
series.setManagedAcl(managedAcl.get().getName());
series.setAccessPolicy(AccessControlParser.toJsonSilent(seriesItem.getAcl()));
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
// Persist the updated series
update(seriesItem.getSeriesId(), series);
break;
case UpdateOptOut:
logger.debug("Received update opt out status of series {} for index {}", seriesItem.getSeriesId(), getSearchIndex().getIndexName());
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesItem.getSeriesId(), organization, user, getSearchIndex());
series.setOptOut(seriesItem.getOptOut());
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
// Persist the updated series
update(seriesItem.getSeriesId(), series);
break;
case UpdateProperty:
logger.debug("Received update property of series {} for index {}", seriesItem.getSeriesId(), getSearchIndex().getIndexName());
if (!THEME_PROPERTY_NAME.equals(seriesItem.getPropertyName()))
break;
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesItem.getSeriesId(), organization, user, getSearchIndex());
series.setTheme(Opt.nul(seriesItem.getPropertyValue()).bind(Strings.toLong).orNull());
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
// Persist the updated series
update(seriesItem.getSeriesId(), series);
break;
case Delete:
logger.debug("Received Delete Series Event {} for index {}", seriesItem.getSeriesId(), getSearchIndex().getIndexName());
// Remove the series from the search index
try {
getSearchIndex().delete(Series.DOCUMENT_TYPE, seriesItem.getSeriesId().concat(organization));
logger.debug("Series {} removed from search index", seriesItem.getSeriesId());
} catch (SearchIndexException e) {
logger.error("Error deleting the series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
return;
case UpdateElement:
// nothing to do
break;
default:
throw new IllegalArgumentException("Unhandled type of SeriesItem");
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class WorkflowMessageReceiverImpl method execute.
@Override
protected void execute(WorkflowItem workflowItem) {
String organization = getSecurityService().getOrganization().getId();
User user = getSecurityService().getUser();
String eventId = null;
switch(workflowItem.getType()) {
case UpdateInstance:
logger.debug("Received Update Workflow instance Entry for index {}", getSearchIndex().getIndexName());
WorkflowInstance wf = workflowItem.getWorkflowInstance();
MediaPackage mp = wf.getMediaPackage();
eventId = mp.getIdentifier().toString();
// Load or create the corresponding recording event
Event event = null;
try {
event = getOrCreateEvent(eventId, organization, user, getSearchIndex());
event.setCreator(getSecurityService().getUser().getName());
event.setWorkflowId(wf.getId());
event.setWorkflowDefinitionId(wf.getTemplate());
event.setWorkflowState(wf.getState());
WorkflowInstance.WorkflowState state = wf.getState();
if (!(WorkflowInstance.WorkflowState.SUCCEEDED.equals(state) || WorkflowInstance.WorkflowState.FAILED.equals(state) || WorkflowInstance.WorkflowState.STOPPED.equals(state))) {
Tuple<AccessControlList, AclScope> activeAcl = authorizationService.getActiveAcl(mp);
List<ManagedAcl> acls = aclServiceFactory.serviceFor(getSecurityService().getOrganization()).getAcls();
Option<ManagedAcl> managedAcl = AccessInformationUtil.matchAcls(acls, activeAcl.getA());
if (managedAcl.isSome()) {
event.setManagedAcl(managedAcl.get().getName());
}
event.setAccessPolicy(AccessControlParser.toJsonSilent(activeAcl.getA()));
try {
Opt<DublinCoreCatalog> loadedDC = DublinCoreUtil.loadEpisodeDublinCore(workspace, mp);
if (loadedDC.isSome())
updateEvent(event, loadedDC.get());
} catch (Throwable t) {
logger.warn("Unable to load dublincore catalog for the workflow {}", wf.getId(), t);
}
}
updateEvent(event, mp);
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
return;
}
// Update series name if not already done
try {
EventIndexUtils.updateSeriesName(event, organization, user, getSearchIndex());
} catch (SearchIndexException e) {
logger.error("Error updating the series name of the event to index: {}", ExceptionUtils.getStackTrace(e));
}
// Persist the scheduling event
try {
getSearchIndex().addOrUpdate(event);
logger.debug("Workflow instance {} updated in the search index", event.getIdentifier());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
return;
}
return;
case DeleteInstance:
logger.debug("Received Delete Workflow instance Entry {}", eventId);
eventId = workflowItem.getWorkflowInstance().getMediaPackage().getIdentifier().toString();
// Remove the Workflow instance entry from the search index
try {
getSearchIndex().deleteWorkflow(organization, user, eventId, workflowItem.getWorkflowInstanceId());
logger.debug("Workflow instance mediapackage {} removed from search index", eventId);
} catch (NotFoundException e) {
logger.warn("Workflow instance mediapackage {} not found for deletion", eventId);
} catch (SearchIndexException e) {
logger.error("Error deleting the Workflow instance entry {} from the search index: {}", eventId, ExceptionUtils.getStackTrace(e));
}
return;
case AddDefinition:
// TODO: Update the index with it as soon as the definition are part of it
return;
case DeleteDefinition:
// TODO: Update the index with it as soon as the definition are part of it
return;
default:
throw new IllegalArgumentException("Unhandled type of WorkflowItem");
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class AssetManagerUpdatedEventHandler method handleEvent.
public void handleEvent(final SeriesItem seriesItem) {
// A series or its ACL has been updated. Find any mediapackages with that series, and update them.
logger.debug("Handling {}", seriesItem);
String seriesId = seriesItem.getSeriesId();
// We must be an administrative user to make this query
final User prevUser = securityService.getUser();
final Organization prevOrg = securityService.getOrganization();
try {
securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
final AQueryBuilder q = assetManager.createQuery();
final AResult result = q.select(q.snapshot()).where(q.seriesId().eq(seriesId).and(q.version().isLatest())).run();
for (Snapshot snapshot : enrich(result).getSnapshots()) {
final String orgId = snapshot.getOrganizationId();
final Organization organization = organizationDirectoryService.getOrganization(orgId);
if (organization == null) {
logger.warn("Skipping update of episode {} since organization {} is unknown", snapshot.getMediaPackage().getIdentifier().compact(), orgId);
continue;
}
securityService.setOrganization(organization);
MediaPackage mp = snapshot.getMediaPackage();
// Update the series XACML file
if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
// Build a new XACML file for this mediapackage
authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl());
}
// Update the series dublin core or extended metadata
if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType()) || SeriesItem.Type.UpdateElement.equals(seriesItem.getType())) {
DublinCoreCatalog seriesDublinCore = null;
MediaPackageElementFlavor catalogType = null;
if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
seriesDublinCore = seriesItem.getMetadata();
mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
catalogType = MediaPackageElements.SERIES;
} else {
seriesDublinCore = seriesItem.getExtendedMetadata();
catalogType = MediaPackageElementFlavor.flavor(seriesItem.getElementType(), "series");
}
// Update the series dublin core
Catalog[] seriesCatalogs = mp.getCatalogs(catalogType);
if (seriesCatalogs.length == 1) {
Catalog c = seriesCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
}
}
// Remove the series catalogs and isPartOf from episode catalog
if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
mp.setSeries(null);
mp.setSeriesTitle(null);
for (Catalog seriesCatalog : mp.getCatalogs(MediaPackageElements.SERIES)) {
mp.remove(seriesCatalog);
}
authorizationService.removeAcl(mp, AclScope.Series);
for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
episodeCatalog.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
episodeCatalog.setChecksum(null);
}
// here we don't know the series extended metadata types,
// we assume that all series catalog flavors have a fixed subtype: series
MediaPackageElementFlavor seriesFlavor = MediaPackageElementFlavor.flavor("*", "series");
for (Catalog catalog : mp.getCatalogs()) {
if (catalog.getFlavor().matches(seriesFlavor))
mp.remove(catalog);
}
}
try {
// Update the asset manager with the modified mediapackage
assetManager.takeSnapshot(snapshot.getOwner(), mp);
} catch (AssetManagerException e) {
logger.error("Error updating mediapackage {}", mp.getIdentifier().compact(), e);
}
}
} catch (NotFoundException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.warn(e.getMessage());
} finally {
securityService.setOrganization(prevOrg);
securityService.setUser(prevUser);
}
}
Aggregations