use of org.opencastproject.ingest.api.IngestException 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.ingest.api.IngestException in project opencast by opencast.
the class IngestServiceImpl method createSmil.
private MediaPackage createSmil(MediaPackage mediaPackage) throws IOException, IngestException {
Stream<Track> partialTracks = Stream.empty();
for (Track track : mediaPackage.getTracks()) {
Long startTime = partialTrackStartTimes.getIfPresent(track.getIdentifier());
if (startTime == null)
continue;
partialTracks = partialTracks.append(Opt.nul(track));
}
// No partial track available return without adding SMIL catalog
if (partialTracks.isEmpty())
return mediaPackage;
// Inspect the partial tracks
List<Track> tracks = partialTracks.map(newEnrichJob(mediaInspectionService).toFn()).map(payloadAsTrack(getServiceRegistry()).toFn()).each(MediaPackageSupport.updateElement(mediaPackage).toFn().toFx()).toList();
// Create the SMIL document
org.w3c.dom.Document smilDocument = SmilUtil.createSmil();
for (Track track : tracks) {
Long startTime = partialTrackStartTimes.getIfPresent(track.getIdentifier());
if (startTime == null) {
logger.error("No start time found for track {}", track);
throw new IngestException("No start time found for track " + track.getIdentifier());
}
smilDocument = addSmilTrack(smilDocument, track, startTime);
partialTrackStartTimes.invalidate(track.getIdentifier());
}
// Store the SMIL document in the mediapackage
return addSmilCatalog(smilDocument, mediaPackage);
}
use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.
the class IngestServiceImpl method addPartialTrack.
@Override
public MediaPackage addPartialTrack(InputStream in, String fileName, MediaPackageElementFlavor flavor, long startTime, MediaPackage mediaPackage) throws IOException, IngestException {
Job job = null;
try {
job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK, null, null, false);
job.setStatus(Status.RUNNING);
job = serviceRegistry.updateJob(job);
String elementId = UUID.randomUUID().toString();
logger.info("Start adding partial track {} from input stream on mediapackage {}", elementId, mediaPackage);
URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
job.setStatus(Job.Status.FINISHED);
// store startTime
partialTrackStartTimes.put(elementId, startTime);
logger.debug("Added start time {} for track {}", startTime, elementId);
logger.info("Successful added partial track {} 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.ingest.api.IngestException 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.ingest.api.IngestException in project opencast by opencast.
the class IngestServiceImpl method loadMediaPackageFromManifest.
private MediaPackage loadMediaPackageFromManifest(InputStream manifest) throws IOException, MediaPackageException, IngestException {
// TODO: Uncomment the following line and remove the patch when the compatibility with pre-1.4 MediaPackages is
// discarded
//
// mp = builder.loadFromXml(manifestStream);
//
// =========================================================================================
// =================================== PATCH BEGIN =========================================
// =========================================================================================
ByteArrayOutputStream baos = null;
ByteArrayInputStream bais = null;
try {
Document domMP = new SAXBuilder().build(manifest);
String mpNSUri = "http://mediapackage.opencastproject.org";
Namespace oldNS = domMP.getRootElement().getNamespace();
Namespace newNS = Namespace.getNamespace(oldNS.getPrefix(), mpNSUri);
if (!newNS.equals(oldNS)) {
@SuppressWarnings("rawtypes") Iterator it = domMP.getDescendants(new ElementFilter(oldNS));
while (it.hasNext()) {
Element elem = (Element) it.next();
elem.setNamespace(newNS);
}
}
baos = new ByteArrayOutputStream();
new XMLOutputter().output(domMP, baos);
bais = new ByteArrayInputStream(baos.toByteArray());
return MediaPackageParser.getFromXml(IOUtils.toString(bais, "UTF-8"));
} catch (JDOMException e) {
throw new IngestException("Error unmarshalling mediapackage", e);
} finally {
IOUtils.closeQuietly(bais);
IOUtils.closeQuietly(baos);
IOUtils.closeQuietly(manifest);
}
// =========================================================================================
// =================================== PATCH END ===========================================
// =========================================================================================
}
Aggregations