use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.
the class IngestRestService method schedule.
@POST
@Path("schedule/{wdID}")
@RestQuery(name = "schedule", description = "Schedule an event based on the given media package", pathParameters = { @RestParameter(description = "Workflow definition id", isRequired = true, name = "wdID", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(description = "The media package", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Event scheduled", responseCode = HttpServletResponse.SC_CREATED), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response schedule(@PathParam("wdID") String wdID, MultivaluedMap<String, String> formData) {
if (StringUtils.isBlank(wdID)) {
logger.trace("workflow definition id is not specified");
return Response.status(Response.Status.BAD_REQUEST).build();
}
Map<String, String> wfConfig = getWorkflowConfig(formData);
if (StringUtils.isNotBlank(wdID)) {
wfConfig.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, wdID);
}
logger.debug("Schedule with workflow definition '{}'", wfConfig.get(WORKFLOW_DEFINITION_ID_PARAM));
String mediaPackageXml = formData.getFirst("mediaPackage");
if (StringUtils.isBlank(mediaPackageXml)) {
logger.debug("Rejected schedule without media package");
return Response.status(Status.BAD_REQUEST).build();
}
MediaPackage mp = null;
try {
mp = factory.newMediaPackageBuilder().loadFromXml(mediaPackageXml);
if (MediaPackageSupport.sanityCheck(mp).isSome()) {
throw new MediaPackageException("Insane media package");
}
} catch (MediaPackageException e) {
logger.debug("Rejected ingest with invalid media package {}", mp);
return Response.status(Status.BAD_REQUEST).build();
}
MediaPackageElement[] mediaPackageElements = mp.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");
return Response.status(Status.BAD_REQUEST).build();
}
try {
ingestService.schedule(mp, wdID, wfConfig);
return Response.status(Status.CREATED).build();
} catch (IngestException e) {
return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
} catch (SchedulerConflictException e) {
return Response.status(Status.CONFLICT).entity(e.getMessage()).build();
} catch (NotFoundException | UnauthorizedException | SchedulerException e) {
return Response.serverError().build();
}
}
use of org.opencastproject.ingest.api.IngestException 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.ingest.api.IngestException 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.ingest.api.IngestException in project opencast by opencast.
the class IngestServiceImpl method mergeScheduledMediaPackage.
/**
* Merges the ingested mediapackage with the scheduled mediapackage. The ingested mediapackage takes precedence over
* the scheduled mediapackage.
*
* @param mp
* the ingested mediapackage
* @return the merged mediapackage
*/
private MediaPackage mergeScheduledMediaPackage(MediaPackage mp) throws IngestException {
if (schedulerService == null) {
logger.warn("No scheduler service available to merge mediapackage!");
return mp;
}
try {
MediaPackage scheduledMp = schedulerService.getMediaPackage(mp.getIdentifier().compact());
logger.info("Found matching scheduled event for id '{}', merging mediapackage...", mp.getIdentifier().compact());
mergeMediaPackageElements(mp, scheduledMp);
mergeMediaPackageMetadata(mp, scheduledMp);
return mp;
} catch (NotFoundException e) {
logger.debug("No scheduler mediapackage found with id {}, skip merging", mp.getIdentifier().compact());
return mp;
} catch (Exception e) {
logger.error("Unable to get event mediapackage from scheduler event {}", mp.getIdentifier().compact(), e);
throw new IngestException(e);
}
}
use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.
the class IngestServiceImpl method updateSeries.
/**
* Updates the persistent representation of a series based on a potentially modified dublin core document.
*
* @param uri
* the URI to the dublin core document containing series metadata.
* @return
* true, if the series is created or overwritten, false if the existing series remains intact.
*/
protected boolean updateSeries(URI uri) throws IOException, IngestException {
HttpResponse response = null;
InputStream in = null;
boolean isUpdated = false;
try {
HttpGet getDc = new HttpGet(uri);
response = httpClient.execute(getDc);
in = response.getEntity().getContent();
DublinCoreCatalog dc = dublinCoreService.load(in);
String id = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
if (id == null) {
logger.warn("Series dublin core document contains no identifier, rejecting ingested series cagtalog.");
} else {
try {
try {
seriesService.getSeries(id);
if (isOverwriteSeries) {
// Update existing series
seriesService.updateSeries(dc);
isUpdated = true;
logger.debug("Ingest is overwriting the existing series {} with the ingested series", id);
} else {
logger.debug("Series {} already exists. Ignoring series catalog from ingest.", id);
}
} catch (NotFoundException e) {
logger.info("Creating new series {} with default ACL", id);
seriesService.updateSeries(dc);
isUpdated = true;
String anonymousRole = securityService.getOrganization().getAnonymousRole();
AccessControlList acl = new AccessControlList(new AccessControlEntry(anonymousRole, "read", true));
seriesService.updateAccessControl(id, acl);
}
} catch (Exception e) {
throw new IngestException(e);
}
}
in.close();
} catch (IOException e) {
logger.error("Error updating series from DublinCoreCatalog: {}", e.getMessage());
} finally {
IOUtils.closeQuietly(in);
httpClient.close(response);
}
return isUpdated;
}
Aggregations