use of org.opencastproject.workflow.api.ConfiguredWorkflowRef in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method addEpisodeTransition.
@POST
@Path("/episode/{episodeId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "addepisodetransition", description = "Add an episode transition", returnDescription = "Add an episode transition", pathParameters = { @RestParameter(name = "episodeId", isRequired = true, description = "The episode id", type = STRING) }, restParameters = { @RestParameter(name = "applicationDate", isRequired = true, description = "The date to applicate", type = STRING), @RestParameter(name = "managedAclId", isRequired = false, 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) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The episode transition has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "The episode transition with the applicationDate already exists"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding an episode transition") })
public String addEpisodeTransition(@PathParam("episodeId") String episodeId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") Long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) {
try {
final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
final EpisodeACLTransition transition = aclService().addEpisodeTransition(episodeId, option(managedAclId), at, workflow);
return JsonConv.full(transition).toJson();
} catch (AclTransitionDbDuplicatedException e) {
logger.info("Error adding episode transition: transition with date {} already exists", applicationDate);
throw new WebApplicationException(Status.CONFLICT);
} catch (AclServiceException e) {
logger.warn("Error adding episode transition:", e);
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
} catch (Exception e) {
logger.warn("Unable to parse the application date");
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
use of org.opencastproject.workflow.api.ConfiguredWorkflowRef in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method applyAclToEpisode.
@POST
@Path("/apply/episode/{episodeId}")
@RestQuery(name = "applyAclToEpisode", description = "Immediate application of an ACL to an episode", returnDescription = "Status code", pathParameters = { @RestParameter(name = "episodeId", isRequired = true, description = "The episode ID", type = STRING) }, restParameters = { @RestParameter(name = "aclId", isRequired = false, description = "The ID of the ACL to apply. If missing the episode ACL will be deleted to fall back to the series ACL", type = INTEGER), @RestParameter(name = "workflowDefinitionId", isRequired = false, description = "The optional workflow to apply to the episode after", type = STRING), @RestParameter(name = "workflowParams", isRequired = false, description = "Parameters for the optional workflow", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The ACL or the episode has not been found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToEpisode(@PathParam("episodeId") String episodeId, @FormParam("aclId") Long aclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) {
final AclService aclService = aclService();
final Option<Option<ManagedAcl>> macl = option(aclId).map(getManagedAcl(aclService));
if (macl.isSome() && macl.get().isNone())
return notFound();
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
try {
if (aclService.applyAclToEpisode(episodeId, Options.join(macl), workflow))
return ok();
else
return notFound();
} catch (AclServiceException e) {
logger.error("Error applying acl to episode {}", episodeId);
return serverError();
}
}
use of org.opencastproject.workflow.api.ConfiguredWorkflowRef in project opencast by opencast.
the class AbstractEventEndpoint method addEventTransition.
@POST
@Path("{eventId}/transitions")
@RestQuery(name = "addEventTransition", description = "Adds an ACL transition to an event", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(name = "transition", isRequired = true, description = "The transition (JSON object) to add", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required params were missing in the request."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method doesn't return any content"), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event has not been found.") })
public Response addEventTransition(@PathParam("eventId") String eventId, @FormParam("transition") String transitionStr) throws SearchIndexException {
if (StringUtils.isBlank(eventId) || StringUtils.isBlank(transitionStr))
return RestUtil.R.badRequest("Missing parameters");
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
try {
final org.codehaus.jettison.json.JSONObject t = new org.codehaus.jettison.json.JSONObject(transitionStr);
Option<ConfiguredWorkflowRef> workflowRef;
if (t.has("workflow_id"))
workflowRef = Option.some(ConfiguredWorkflowRef.workflow(t.getString("workflow_id")));
else
workflowRef = Option.none();
Option<Long> managedAclId;
if (t.has("acl_id"))
managedAclId = Option.some(t.getLong("acl_id"));
else
managedAclId = Option.none();
getAclService().addEpisodeTransition(eventId, managedAclId, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))), workflowRef);
return Response.noContent().build();
} catch (AclServiceException e) {
logger.error("Error while trying to get ACL transitions for event '{}' from ACL service: {}", eventId, e);
throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
} catch (JSONException e) {
return RestUtil.R.badRequest("The transition object is not valid");
} catch (IllegalStateException e) {
// That should never happen
throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
} catch (ParseException e) {
return RestUtil.R.badRequest("The date could not be parsed");
}
}
Aggregations