use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method updateSeriesTransition.
@PUT
@Path("/series/{transitionId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateseriestransition", description = "Update an existing series transition", returnDescription = "Update an existing series transition", pathParameters = { @RestParameter(name = "transitionId", isRequired = true, description = "The transition id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = true, description = "The managed access control list id", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The workflow definition identifier", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "The workflow parameters as JSON", type = STRING), @RestParameter(name = "override", isRequired = false, description = "If to override the episode ACL's", type = STRING, defaultValue = "false") }, reponses = { @RestResponse(responseCode = SC_OK, description = "The series transition has successfully been updated"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The given managed acl id could not be found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating a series transition") })
public String updateSeriesTransition(@PathParam("transitionId") long transitionId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams, @FormParam("override") boolean override) throws NotFoundException {
try {
final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
final SeriesACLTransition t = aclService().updateSeriesTransition(transitionId, managedAclId, at, workflow, override);
return JsonConv.full(t).toJson();
} catch (AclServiceNoReferenceException e) {
logger.info("Managed acl with id '{}' could not be found", managedAclId);
throw new WebApplicationException(Status.BAD_REQUEST);
} catch (AclServiceException e) {
logger.warn("Error updating series transition:", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.warn("Unable to parse the application date");
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class IngestRestService method addMediaPackageCatalog.
@POST
@Produces(MediaType.TEXT_XML)
@Path("addCatalog")
@RestQuery(name = "addCatalogURL", description = "Add a metadata catalog to a given media package using an URL", restParameters = { @RestParameter(description = "The location of the catalog", isRequired = true, name = "url", type = RestParameter.Type.STRING), @RestParameter(description = "The kind of catalog", isRequired = true, name = "flavor", type = RestParameter.Type.STRING), @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addMediaPackageCatalog(@FormParam("url") String url, @FormParam("flavor") String flavor, @FormParam("mediaPackage") String mpx) {
logger.trace("add catalog with url: {} flavor: {} mediaPackage: {}", url, flavor, mpx);
try {
MediaPackage mp = factory.newMediaPackageBuilder().loadFromXml(mpx);
if (MediaPackageSupport.sanityCheck(mp).isSome())
return Response.serverError().status(Status.BAD_REQUEST).build();
MediaPackage resultingMediaPackage = ingestService.addCatalog(new URI(url), MediaPackageElementFlavor.parseFlavor(flavor), mp);
return Response.ok(resultingMediaPackage).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class IngestRestService method addDCCatalog.
/**
* Adds a dublinCore metadata catalog to the MediaPackage and returns the grown mediaPackage. JQuery Ajax functions
* doesn't support multipart/form-data encoding.
*
* @param mp
* MediaPackage
* @param dc
* DublinCoreCatalog
* @return grown MediaPackage XML
*/
@POST
@Produces(MediaType.TEXT_XML)
@Path("addDCCatalog")
@RestQuery(name = "addDCCatalog", description = "Add a dublincore episode catalog to a given media package using an url", restParameters = { @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT), @RestParameter(description = "DublinCore catalog as XML", isRequired = true, name = "dublinCore", type = RestParameter.Type.TEXT), @RestParameter(defaultValue = "dublincore/episode", description = "DublinCore Flavor", isRequired = false, name = "flavor", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addDCCatalog(@FormParam("mediaPackage") String mp, @FormParam("dublinCore") String dc, @FormParam("flavor") String flavor) {
logger.trace("add DC catalog: {} with flavor: {} to media package: {}", dc, flavor, mp);
MediaPackageElementFlavor dcFlavor = MediaPackageElements.EPISODE;
if (flavor != null) {
try {
dcFlavor = MediaPackageElementFlavor.parseFlavor(flavor);
} catch (IllegalArgumentException e) {
logger.warn("Unable to set dublin core flavor to {}, using {} instead", flavor, MediaPackageElements.EPISODE);
}
}
MediaPackage mediaPackage;
/* Check if we got a proper mediapackage and try to parse it */
try {
mediaPackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(mp);
} catch (MediaPackageException e) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
if (MediaPackageSupport.sanityCheck(mediaPackage).isSome()) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
/* Check if we got a proper catalog */
if (StringUtils.isBlank(dc)) {
return Response.serverError().status(Status.BAD_REQUEST).build();
}
InputStream in = null;
try {
in = IOUtils.toInputStream(dc, "UTF-8");
mediaPackage = ingestService.addCatalog(in, "dublincore.xml", dcFlavor, mediaPackage);
} catch (MediaPackageException e) {
return Response.serverError().status(Status.BAD_REQUEST).build();
} catch (IOException e) {
/* Return an internal server error if we could not write to disk */
logger.error("Could not write catalog to disk: {}", e.getMessage());
return Response.serverError().build();
} catch (Exception e) {
logger.error(e.getMessage());
return Response.serverError().build();
} finally {
IOUtils.closeQuietly(in);
}
return Response.ok(mediaPackage).build();
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class IngestRestService method addMediaPackagePartialTrack.
@POST
@Produces(MediaType.TEXT_XML)
@Path("addPartialTrack")
@RestQuery(name = "addPartialTrackURL", description = "Add a partial media track to a given media package using an URL", restParameters = { @RestParameter(description = "The location of the media", isRequired = true, name = "url", type = RestParameter.Type.STRING), @RestParameter(description = "The kind of media", isRequired = true, name = "flavor", type = RestParameter.Type.STRING), @RestParameter(description = "The start time in milliseconds", isRequired = true, name = "startTime", type = RestParameter.Type.INTEGER), @RestParameter(description = "The media package as XML", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Returns augmented media package", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) }, returnDescription = "")
public Response addMediaPackagePartialTrack(@FormParam("url") String url, @FormParam("flavor") String flavor, @FormParam("startTime") Long startTime, @FormParam("mediaPackage") String mpx) {
logger.trace("add partial track with url: {} flavor: {} startTime: {} mediaPackage: {}", url, flavor, startTime, mpx);
try {
MediaPackage mp = factory.newMediaPackageBuilder().loadFromXml(mpx);
if (MediaPackageSupport.sanityCheck(mp).isSome())
return Response.serverError().status(Status.BAD_REQUEST).build();
mp = ingestService.addPartialTrack(new URI(url), MediaPackageElementFlavor.parseFlavor(flavor), startTime, mp);
return Response.ok(mp).build();
} catch (Exception e) {
logger.warn(e.getMessage(), e);
return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
}
}
use of org.opencastproject.util.doc.rest.RestQuery 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();
}
}
Aggregations