use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class IngestServiceImpl method addCatalog.
/**
* {@inheritDoc}
*
* @see org.opencastproject.ingest.api.IngestService#addCatalog(java.io.InputStream, java.lang.String,
* org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
*/
@Override
public MediaPackage addCatalog(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
Job job = null;
try {
job = serviceRegistry.createJob(JOB_TYPE, INGEST_CATALOG, null, null, false, ingestFileJobLoad);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
String elementId = UUID.randomUUID().toString();
logger.info("Start adding catalog {} from input stream on mediapackage {}", elementId, mediaPackage);
URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
if (MediaPackageElements.SERIES.equals(flavor)) {
updateSeries(newUrl);
}
MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Catalog, flavor);
if (tags != null && tags.length > 0) {
MediaPackageElement trackElement = mp.getCatalog(elementId);
for (String tag : tags) {
logger.info("Adding Tag: " + tag + " to Element: " + elementId);
trackElement.addTag(tag);
}
}
job.setStatus(Job.Status.FINISHED);
logger.info("Successful added catalog {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
return mp;
} catch (ServiceRegistryException e) {
throw new IngestException(e);
} catch (NotFoundException e) {
throw new IngestException("Unable to update ingest job", e);
} finally {
finallyUpdateJob(job);
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class IngestServiceImpl method addTrack.
/**
* {@inheritDoc}
*
* @see org.opencastproject.ingest.api.IngestService#addTrack(java.net.URI,
* org.opencastproject.mediapackage.MediaPackageElementFlavor, String[] ,
* org.opencastproject.mediapackage.MediaPackage)
*/
@Override
public MediaPackage addTrack(URI uri, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
Job job = null;
try {
job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK_FROM_URI, Arrays.asList(uri.toString(), flavor == null ? null : flavor.toString(), MediaPackageParser.getAsXml(mediaPackage)), null, false, ingestFileJobLoad);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
String elementId = UUID.randomUUID().toString();
logger.info("Start adding track {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
if (tags != null && tags.length > 0) {
MediaPackageElement trackElement = mp.getTrack(elementId);
for (String tag : tags) {
logger.info("Adding Tag: " + tag + " to Element: " + elementId);
trackElement.addTag(tag);
}
}
job.setStatus(Job.Status.FINISHED);
logger.info("Successful added track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
return mp;
} catch (IOException e) {
throw e;
} catch (ServiceRegistryException e) {
throw new IngestException(e);
} catch (NotFoundException e) {
throw new IngestException("Unable to update ingest job", e);
} finally {
finallyUpdateJob(job);
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class IngestServiceImpl method schedule.
@Override
public void schedule(MediaPackage mediaPackage, String workflowDefinitionID, Map<String, String> properties) throws IllegalStateException, IngestException, NotFoundException, UnauthorizedException, SchedulerException {
MediaPackageElement[] mediaPackageElements = mediaPackage.getElementsByFlavor(MediaPackageElements.EPISODE);
if (mediaPackageElements.length != 1) {
logger.debug("There can be only one (and exactly one) episode dublin core catalog: https://youtu.be/_J3VeogFUOs");
throw new IngestException("There can be only one (and exactly one) episode dublin core catalog");
}
InputStream inputStream;
DublinCoreCatalog dublinCoreCatalog;
try {
inputStream = workingFileRepository.get(mediaPackage.getIdentifier().toString(), mediaPackageElements[0].getIdentifier());
dublinCoreCatalog = dublinCoreService.load(inputStream);
} catch (IOException e) {
throw new IngestException(e);
}
EName temporal = new EName(DublinCore.TERMS_NS_URI, "temporal");
List<DublinCoreValue> periods = dublinCoreCatalog.get(temporal);
if (periods.size() != 1) {
logger.debug("There can be only one (and exactly one) period");
throw new IngestException("There can be only one (and exactly one) period");
}
DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(periods.get(0));
if (!period.hasStart() || !period.hasEnd()) {
logger.debug("A scheduled recording needs to have a start and end.");
throw new IngestException("A scheduled recording needs to have a start and end.");
}
EName createdEName = new EName(DublinCore.TERMS_NS_URI, "created");
List<DublinCoreValue> created = dublinCoreCatalog.get(createdEName);
if (created.size() == 0) {
logger.debug("Created not set");
} else if (created.size() == 1) {
Date date = EncodingSchemeUtils.decodeMandatoryDate(created.get(0));
if (date.getTime() != period.getStart().getTime()) {
logger.debug("start and created date differ ({} vs {})", date.getTime(), period.getStart().getTime());
throw new IngestException("Temporal start and created date differ");
}
} else {
logger.debug("There can be only one created date");
throw new IngestException("There can be only one created date");
}
// spatial
EName spatial = new EName(DublinCore.TERMS_NS_URI, "spatial");
List<DublinCoreValue> captureAgents = dublinCoreCatalog.get(spatial);
if (captureAgents.size() != 1) {
logger.debug("Exactly one capture agent needs to be set");
throw new IngestException("Exactly one capture agent needs to be set");
}
String captureAgent = captureAgents.get(0).getValue();
// Go through properties
Map<String, String> agentProperties = new HashMap<>();
Map<String, String> workflowProperties = new HashMap<>();
for (String key : properties.keySet()) {
if (key.startsWith("org.opencastproject.workflow.config.")) {
workflowProperties.put(key, properties.get(key));
} else {
agentProperties.put(key, properties.get(key));
}
}
try {
schedulerService.addEvent(period.getStart(), period.getEnd(), captureAgent, new HashSet<>(), mediaPackage, workflowProperties, agentProperties, Opt.none(), Opt.none(), "ingest-service");
} finally {
for (MediaPackageElement mediaPackageElement : mediaPackage.getElements()) {
try {
workingFileRepository.delete(mediaPackage.getIdentifier().toString(), mediaPackageElement.getIdentifier());
} catch (IOException e) {
logger.warn("Failed to delete media package element", e);
}
}
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class IngestServiceImpl method addAttachment.
/**
* {@inheritDoc}
*
* @see org.opencastproject.ingest.api.IngestService#addAttachment(java.io.InputStream, java.lang.String,
* org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
*/
@Override
public MediaPackage addAttachment(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
Job job = null;
try {
job = serviceRegistry.createJob(JOB_TYPE, INGEST_ATTACHMENT, null, null, false, ingestFileJobLoad);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
String elementId = UUID.randomUUID().toString();
logger.info("Start adding attachment {} from input stream on mediapackage {}", elementId, mediaPackage);
URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Attachment, flavor);
if (tags != null && tags.length > 0) {
MediaPackageElement trackElement = mp.getAttachment(elementId);
for (String tag : tags) {
logger.info("Adding Tag: " + tag + " to Element: " + elementId);
trackElement.addTag(tag);
}
}
job.setStatus(Job.Status.FINISHED);
logger.info("Successful added attachment {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
return mp;
} catch (ServiceRegistryException e) {
throw new IngestException(e);
} catch (NotFoundException e) {
throw new IngestException("Unable to update ingest job", e);
} finally {
finallyUpdateJob(job);
}
}
use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.
the class IngestServiceImpl method addSmilCatalog.
/**
* Adds a SMIL catalog to a mediapackage if it's not already existing.
*
* @param smilDocument
* the smil document
* @param mediaPackage
* the mediapackage to extend with the SMIL catalog
* @return the augmented mediapcakge
* @throws IOException
* if reading or writing of the SMIL catalog fails
* @throws IngestException
* if the SMIL catalog already exists
*/
private MediaPackage addSmilCatalog(org.w3c.dom.Document smilDocument, MediaPackage mediaPackage) throws IOException, IngestException {
Option<org.w3c.dom.Document> optSmilDocument = loadSmilDocument(workingFileRepository, mediaPackage);
if (optSmilDocument.isSome())
throw new IngestException("SMIL already exists!");
InputStream in = null;
try {
in = XmlUtil.serializeDocument(smilDocument);
String elementId = UUID.randomUUID().toString();
URI uri = workingFileRepository.put(mediaPackage.getIdentifier().compact(), elementId, PARTIAL_SMIL_NAME, in);
MediaPackageElement mpe = mediaPackage.add(uri, MediaPackageElement.Type.Catalog, MediaPackageElements.SMIL);
mpe.setIdentifier(elementId);
// Reset the checksum since it changed
mpe.setChecksum(null);
mpe.setMimeType(MimeTypes.SMIL);
return mediaPackage;
} finally {
IoSupport.closeQuietly(in);
}
}
Aggregations