use of org.opencastproject.mediapackage.Catalog 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.mediapackage.Catalog in project opencast by opencast.
the class IndexServiceImpl method updateMediaPackageCommentCatalog.
private void updateMediaPackageCommentCatalog(MediaPackage mediaPackage, List<EventComment> comments) throws EventCommentException, IOException {
// Get the comments catalog
Catalog[] commentCatalogs = mediaPackage.getCatalogs(MediaPackageElements.COMMENTS);
Catalog c = null;
if (commentCatalogs.length == 1)
c = commentCatalogs[0];
if (comments.size() > 0) {
// If no comments catalog found, create a new one
if (c == null) {
c = (Catalog) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().newElement(Type.Catalog, MediaPackageElements.COMMENTS);
c.setIdentifier(UUID.randomUUID().toString());
mediaPackage.add(c);
}
// Update comments catalog
InputStream in = null;
try {
String commentCatalog = EventCommentParser.getAsXml(comments);
in = IOUtils.toInputStream(commentCatalog, "UTF-8");
URI uri = workspace.put(mediaPackage.getIdentifier().toString(), c.getIdentifier(), "comments.xml", in);
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
} finally {
IOUtils.closeQuietly(in);
}
} else {
// Remove comments catalog
if (c != null) {
mediaPackage.remove(c);
try {
workspace.delete(c.getURI());
} catch (NotFoundException e) {
logger.warn("Comments catalog {} not found to delete!", c.getURI());
}
}
}
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class EventIndexUtils method generatePublicationDoc.
/**
* Generate the document structure for the publication element
*
* @param publication
* the source publication element
* @return a map representing the ES document structure of the publication element
*/
private static HashMap<String, Object> generatePublicationDoc(Publication publication) {
HashMap<String, Object> pMap = new HashMap<String, Object>();
// Add first level elements
pMap.put(PublicationIndexSchema.CHANNEL, publication.getChannel());
addObjectStringtToMap(pMap, PublicationIndexSchema.MIMETYPE, publication.getMimeType());
// Attachments
Attachment[] attachments = publication.getAttachments();
HashMap<String, Object>[] attachmentsArray = new HashMap[attachments.length];
for (int i = 0; i < attachmentsArray.length; i++) {
Attachment attachment = attachments[i];
HashMap<String, Object> element = new HashMap<String, Object>();
element.put(PublicationIndexSchema.ELEMENT_ID, attachment.getIdentifier());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_MIMETYPE, attachment.getMimeType());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_TYPE, attachment.getElementType());
element.put(PublicationIndexSchema.ELEMENT_TAG, attachment.getTags());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_URL, attachment.getURI());
element.put(PublicationIndexSchema.ELEMENT_SIZE, attachment.getSize());
attachmentsArray[i] = element;
}
pMap.put(PublicationIndexSchema.ATTACHMENT, attachmentsArray);
// Catalogs
Catalog[] catalogs = publication.getCatalogs();
HashMap<String, Object>[] catalogsArray = new HashMap[catalogs.length];
for (int i = 0; i < catalogsArray.length; i++) {
Catalog catalog = catalogs[i];
HashMap<String, Object> element = new HashMap<String, Object>();
element.put(PublicationIndexSchema.ELEMENT_ID, catalog.getIdentifier());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_MIMETYPE, catalog.getMimeType());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_TYPE, catalog.getElementType());
element.put(PublicationIndexSchema.ELEMENT_TAG, catalog.getTags());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_URL, catalog.getURI());
element.put(PublicationIndexSchema.ELEMENT_SIZE, catalog.getSize());
catalogsArray[i] = element;
}
pMap.put(PublicationIndexSchema.CATALOG, catalogsArray);
// Tracks
Track[] tracks = publication.getTracks();
HashMap<String, Object>[] tracksArray = new HashMap[tracks.length];
for (int i = 0; i < tracksArray.length; i++) {
Track track = tracks[i];
HashMap<String, Object> element = new HashMap<String, Object>();
element.put(PublicationIndexSchema.ELEMENT_ID, track.getIdentifier());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_MIMETYPE, track.getMimeType());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_TYPE, track.getElementType());
element.put(PublicationIndexSchema.ELEMENT_TAG, track.getTags());
addObjectStringtToMap(element, PublicationIndexSchema.ELEMENT_URL, track.getURI());
element.put(PublicationIndexSchema.ELEMENT_SIZE, track.getSize());
element.put(PublicationIndexSchema.TRACK_DURATION, track.getDuration());
tracksArray[i] = element;
}
pMap.put(PublicationIndexSchema.TRACK, tracksArray);
return pMap;
}
use of org.opencastproject.mediapackage.Catalog 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);
}
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class SeriesUpdatedEventHandler method updateEpisodeCatalog.
private boolean updateEpisodeCatalog(MediaPackage mp) throws DistributionException, MediaPackageException, NotFoundException, ServiceRegistryException, IllegalArgumentException, IOException {
// Update the episode catalog
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);
// Distribute the updated episode dublincore
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, episodeCatalog.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(episodeCatalog);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute episode catalog {}", episodeCatalog.getIdentifier());
return false;
}
}
return true;
}
Aggregations