use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class InspectWorkflowOperationHandler method updateDublinCore.
/**
* Updates those dublin core fields that can be gathered from the technical metadata.
*
* @param mediaPackage
* the media package
*/
protected void updateDublinCore(MediaPackage mediaPackage) throws Exception {
// Complete episode dublin core catalog (if available)
Catalog[] dcCatalogs = mediaPackage.getCatalogs(MediaPackageElements.EPISODE, MediaPackageReferenceImpl.ANY_MEDIAPACKAGE);
if (dcCatalogs.length > 0) {
DublinCoreCatalog dublinCore = loadDublinCoreCatalog(dcCatalogs[0]);
// Extent
if (mediaPackage.getDuration() != null && !dublinCore.hasValue(DublinCore.PROPERTY_EXTENT)) {
DublinCoreValue extent = EncodingSchemeUtils.encodeDuration(mediaPackage.getDuration());
dublinCore.set(DublinCore.PROPERTY_EXTENT, extent);
logger.debug("Setting dc:extent to '{}'", extent.getValue());
}
// Date created
if (mediaPackage.getDate() != null && !dublinCore.hasValue(DublinCore.PROPERTY_CREATED)) {
DublinCoreValue date = EncodingSchemeUtils.encodeDate(mediaPackage.getDate(), Precision.Minute);
dublinCore.set(DublinCore.PROPERTY_CREATED, date);
logger.debug("Setting dc:date to '{}'", date.getValue());
}
// Serialize changed dublin core
InputStream in = dcService.serialize(dublinCore);
String mpId = mediaPackage.getIdentifier().toString();
String elementId = dcCatalogs[0].getIdentifier();
workspace.put(mpId, elementId, FilenameUtils.getName(dcCatalogs[0].getURI().getPath()), in);
dcCatalogs[0].setURI(workspace.getURI(mpId, elementId));
}
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class AbstractEventEndpoint method getCatalog.
@GET
@Path("{eventId}/asset/catalog/{id}.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getCatalog", description = "Returns the details of a catalog from the given event and catalog id as JSON", returnDescription = "The details of a catalog from the given event and catalog id as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "id", description = "The catalog id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns the details of a catalog from the given event and catalog id as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event or catalog with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getCatalog(@PathParam("eventId") String eventId, @PathParam("id") String id) throws NotFoundException, SearchIndexException, IndexServiceException {
MediaPackage mp = getMediaPackageByEventId(eventId);
Catalog catalog = mp.getCatalog(id);
if (catalog == null)
return notFound("Cannot find a catalog with id '%s'.", id);
return okJson(catalogToJSON(catalog));
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class ConfigurableWorkflowOperationHandlerBase method retractPublicationElements.
/**
* Remove the {@link Publication}'s {@link MediaPackageElement}s from a given channel.
*
* @param channelId
* The channel to remove the {@link MediaPackageElement}s from.
* @param publication
* The {@link Publication} that is being removed.
* @param mp
* The {@link MediaPackage} that the {@link Publication} is part of.
* @return the number of {@link MediaPackageElement}s that have been retracted
* @throws WorkflowOperationException
* Thrown if unable to retract the {@link MediaPackageElement}s.
*/
private int retractPublicationElements(String channelId, Publication publication, MediaPackage mp) throws WorkflowOperationException {
assert ((channelId != null) && (publication != null) && (mp != null));
MediaPackage mediapackageWithPublicationElements = (MediaPackage) mp.clone();
// Add the publications to the mediapackage so that we can use the standard retract
addPublicationElementsToMediaPackage(publication, mediapackageWithPublicationElements);
Set<String> elementIds = new HashSet<>();
for (Attachment attachment : publication.getAttachments()) {
elementIds.add(attachment.getIdentifier());
}
for (Catalog catalog : publication.getCatalogs()) {
elementIds.add(catalog.getIdentifier());
}
for (Track track : publication.getTracks()) {
elementIds.add(track.getIdentifier());
}
if (elementIds.size() > 0) {
logger.info("Retracting {} elements of media package {} from publication channel {}", elementIds.size(), mp, channelId);
Job job = null;
try {
job = getDistributionService().retract(channelId, mediapackageWithPublicationElements, elementIds);
} catch (DistributionException e) {
logger.error("Error while retracting '{}' elements from channel '{}' of distribution '{}': {}", elementIds.size(), channelId, getDistributionService(), getStackTrace(e));
throw new WorkflowOperationException("The retraction job did not complete successfully");
}
if (!waitForStatus(job).isSuccess()) {
throw new WorkflowOperationException("The retraction job did not complete successfully");
}
} else {
logger.debug("No publication elements were found for retraction");
}
return elementIds.size();
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class CatalogBuilderPlugin method elementFromURI.
/**
* @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#elementFromURI(URI)
*/
@Override
public MediaPackageElement elementFromURI(URI uri) throws UnsupportedElementException {
logger.trace("Creating video track from " + uri);
Catalog track = CatalogImpl.fromURI(uri);
return track;
}
use of org.opencastproject.mediapackage.Catalog in project opencast by opencast.
the class CatalogBuilderPlugin method elementFromManifest.
/**
* {@inheritDoc}
*
* @see org.opencastproject.mediapackage.elementbuilder.MediaPackageElementBuilderPlugin#elementFromManifest(org.w3c.dom.Node,
* org.opencastproject.mediapackage.MediaPackageSerializer)
*/
@Override
public MediaPackageElement elementFromManifest(Node elementNode, MediaPackageSerializer serializer) throws UnsupportedElementException {
String id = null;
String flavor = null;
URI url = null;
long size = -1;
Checksum checksum = null;
MimeType mimeType = null;
String reference = null;
try {
// id
id = (String) xpath.evaluate("@id", elementNode, XPathConstants.STRING);
// url
url = serializer.decodeURI(new URI(xpath.evaluate("url/text()", elementNode).trim()));
// flavor
flavor = (String) xpath.evaluate("@type", elementNode, XPathConstants.STRING);
// reference
reference = (String) xpath.evaluate("@ref", elementNode, XPathConstants.STRING);
// size
String documentSize = xpath.evaluate("size/text()", elementNode).trim();
if (!"".equals(documentSize))
size = Long.parseLong(documentSize);
// checksum
String checksumValue = (String) xpath.evaluate("checksum/text()", elementNode, XPathConstants.STRING);
String checksumType = (String) xpath.evaluate("checksum/@type", elementNode, XPathConstants.STRING);
if (StringUtils.isNotEmpty(checksumValue) && checksumType != null)
checksum = Checksum.create(checksumType.trim(), checksumValue.trim());
// mimetype
String mimeTypeValue = (String) xpath.evaluate("mimetype/text()", elementNode, XPathConstants.STRING);
if (StringUtils.isNotEmpty(mimeTypeValue))
mimeType = MimeTypes.parseMimeType(mimeTypeValue);
// create the catalog
Catalog dc = CatalogImpl.fromURI(url);
if (StringUtils.isNotEmpty(id))
dc.setIdentifier(id);
// Add url
dc.setURI(url);
// Add flavor
if (flavor != null)
dc.setFlavor(MediaPackageElementFlavor.parseFlavor(flavor));
// Add reference
if (StringUtils.isNotEmpty(reference))
dc.referTo(MediaPackageReferenceImpl.fromString(reference));
// Set size
if (size > 0)
dc.setSize(size);
// Set checksum
if (checksum != null)
dc.setChecksum(checksum);
// Set Mimetype
if (mimeType != null)
dc.setMimeType(mimeType);
// Tags
NodeList tagNodes = (NodeList) xpath.evaluate("tags/tag", elementNode, XPathConstants.NODESET);
for (int i = 0; i < tagNodes.getLength(); i++) {
dc.addTag(tagNodes.item(i).getTextContent());
}
return dc;
} catch (XPathExpressionException e) {
throw new UnsupportedElementException("Error while reading catalog information from manifest: " + e.getMessage());
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedElementException("Unsupported digest algorithm: " + e.getMessage());
} catch (URISyntaxException e) {
throw new UnsupportedElementException("Error while reading dublin core catalog " + url + ": " + e.getMessage());
}
}
Aggregations