Search in sources :

Example 6 with ConfiguredWorkflowRef

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);
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) Date(java.util.Date) AclTransitionDbDuplicatedException(org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException) SeriesException(org.opencastproject.series.api.SeriesException) WebApplicationException(javax.ws.rs.WebApplicationException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) AclServiceNoReferenceException(org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 7 with ConfiguredWorkflowRef

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();
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) Option(org.opencastproject.util.data.Option) AclService(org.opencastproject.authorization.xacml.manager.api.AclService) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 8 with ConfiguredWorkflowRef

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");
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) JSONException(org.codehaus.jettison.json.JSONException) Date(java.util.Date) JSONObject(org.json.simple.JSONObject) Event(org.opencastproject.index.service.impl.index.event.Event) ParseException(java.text.ParseException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)8 ConfiguredWorkflowRef (org.opencastproject.workflow.api.ConfiguredWorkflowRef)8 Path (javax.ws.rs.Path)7 RestQuery (org.opencastproject.util.doc.rest.RestQuery)7 Date (java.util.Date)6 WebApplicationException (javax.ws.rs.WebApplicationException)6 NotFoundException (org.opencastproject.util.NotFoundException)5 POST (javax.ws.rs.POST)4 Produces (javax.ws.rs.Produces)4 AclServiceNoReferenceException (org.opencastproject.authorization.xacml.manager.api.AclServiceNoReferenceException)4 AclTransitionDbDuplicatedException (org.opencastproject.authorization.xacml.manager.impl.AclTransitionDbDuplicatedException)4 SeriesException (org.opencastproject.series.api.SeriesException)4 PUT (javax.ws.rs.PUT)3 ParseException (java.text.ParseException)2 JSONException (org.codehaus.jettison.json.JSONException)2 JSONObject (org.json.simple.JSONObject)2 EpisodeACLTransition (org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition)2 SeriesACLTransition (org.opencastproject.authorization.xacml.manager.api.SeriesACLTransition)2 Event (org.opencastproject.index.service.impl.index.event.Event)2 Option (org.opencastproject.util.data.Option)2