use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method updateAcl.
@PUT
@Path("/acl/{aclId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateacl", description = "Update an ACL", returnDescription = "Update an ACL", pathParameters = { @RestParameter(name = "aclId", isRequired = true, description = "The ACL identifier", type = INTEGER) }, restParameters = { @RestParameter(name = "name", isRequired = true, description = "The ACL name", type = STRING), @RestParameter(name = "acl", isRequired = true, description = "The access control list", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has successfully been updated"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The ACL has not been found"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the ACL"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating the ACL") })
public String updateAcl(@PathParam("aclId") long aclId, @FormParam("name") String name, @FormParam("acl") String accessControlList) throws NotFoundException {
final Organization org = getSecurityService().getOrganization();
final AccessControlList acl = parseAcl.apply(accessControlList);
final ManagedAclImpl managedAcl = new ManagedAclImpl(aclId, name, org.getId(), acl);
if (!aclService().updateAcl(managedAcl)) {
logger.info("No ACL with id '{}' could be found under organization '{}'", aclId, org.getId());
throw new NotFoundException();
}
return JsonConv.full(managedAcl).toJson();
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method updateEpisodeTransition.
@PUT
@Path("/episode/{transitionId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "updateepisodetransition", description = "Update an existing episode transition", returnDescription = "Update an existing episode 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 = 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 updated"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during updating an episode transition") })
public String updateEpisodeTransition(@PathParam("transitionId") long transitionId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") Long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams) throws NotFoundException {
try {
final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
final EpisodeACLTransition t = aclService().updateEpisodeTransition(transitionId, option(managedAclId), at, workflow);
return JsonConv.full(t).toJson();
} catch (AclServiceException e) {
logger.warn("Error updating episode 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 AbstractAclServiceRestEndpoint method getTransitionsAsJson.
@GET
@Path("/transitions.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "gettransitionsasjson", description = "Get the transitions as json", returnDescription = "Get the transitions as json", restParameters = { @RestParameter(name = "after", isRequired = false, description = "All transitions with an application date after this one", type = STRING), @RestParameter(name = "before", isRequired = false, description = "All transitions with an application date before this one", type = STRING), @RestParameter(name = "scope", isRequired = false, description = "The transition scope", type = STRING), @RestParameter(name = "id", isRequired = false, description = "The series or episode identifier", type = STRING), @RestParameter(name = "transitionId", isRequired = false, description = "The transition identifier", type = STRING), @RestParameter(name = "managedAclId", isRequired = false, description = "The managed acl identifier", type = INTEGER), @RestParameter(name = "done", isRequired = false, description = "Indicates if already applied", type = BOOLEAN) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The request was processed succesfully"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Error parsing the given scope"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during processing the request") })
public Response getTransitionsAsJson(@QueryParam("after") String afterStr, @QueryParam("before") String beforeStr, @QueryParam("scope") String scopeStr, @QueryParam("id") String id, @QueryParam("transitionId") Long transitionId, @QueryParam("managedAclId") Long managedAclId, @QueryParam("done") Boolean done) {
try {
final TransitionQuery query = TransitionQuery.query();
if (StringUtils.isNotBlank(afterStr))
query.after(new Date(DateTimeSupport.fromUTC(afterStr)));
if (StringUtils.isNotBlank(beforeStr))
query.before(new Date(DateTimeSupport.fromUTC(beforeStr)));
if (StringUtils.isNotBlank(id))
query.withId(id);
if (StringUtils.isNotBlank(scopeStr)) {
if ("episode".equalsIgnoreCase(scopeStr))
query.withScope(AclScope.Episode);
else if ("series".equalsIgnoreCase(scopeStr))
query.withScope(AclScope.Series);
else
return badRequest();
}
if (transitionId != null)
query.withTransitionId(transitionId);
if (managedAclId != null)
query.withAclId(managedAclId);
if (done != null)
query.withDone(done);
final AclService aclService = aclService();
// run query
final TransitionResult r = aclService().getTransitions(query);
// episodeId -> [transitions]
final Map<String, List<EpisodeACLTransition>> episodeGroup = groupByEpisodeId(r.getEpisodeTransistions());
// seriesId -> [transitions]
final Map<String, List<SeriesACLTransition>> seriesGroup = groupBySeriesId(r.getSeriesTransistions());
final Jsons.Obj episodesObj = buildEpisodesObj(episodeGroup);
final Jsons.Obj seriesObj = buildSeriesObj(seriesGroup);
// create final response
return ok(obj(p("episodes", episodesObj), p("series", seriesObj)).toJson());
} catch (Exception e) {
logger.error("Error generating getTransitions response", e);
return serverError();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method addSeriesTransition.
@POST
@Path("/series/{seriesId}")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "addseriestransition", description = "Add a series transition", returnDescription = "Add a series transition", pathParameters = { @RestParameter(name = "seriesId", isRequired = true, description = "The series 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 added"), @RestResponse(responseCode = SC_CONFLICT, description = "The series transition with the applicationDate already exists"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "The given managed acl id could not be found"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding a series transition") })
public String addSeriesTransition(@PathParam("seriesId") String seriesId, @FormParam("applicationDate") String applicationDate, @FormParam("managedAclId") long managedAclId, @FormParam("workflowDefinitionId") String workflowDefinitionId, @FormParam("workflowParams") String workflowParams, @FormParam("override") boolean override) {
try {
final Date at = new Date(DateTimeSupport.fromUTC(applicationDate));
final Option<ConfiguredWorkflowRef> workflow = createConfiguredWorkflowRef(workflowDefinitionId, workflowParams);
SeriesACLTransition seriesTransition = aclService().addSeriesTransition(seriesId, managedAclId, at, override, workflow);
return JsonConv.full(seriesTransition).toJson();
} catch (AclServiceNoReferenceException e) {
logger.info("Managed acl with id '{}' coudl not be found", managedAclId);
throw new WebApplicationException(Status.BAD_REQUEST);
} catch (AclTransitionDbDuplicatedException e) {
logger.info("Error adding series transition: transition with date {} already exists", applicationDate);
throw new WebApplicationException(Status.CONFLICT);
} catch (AclServiceException e) {
logger.warn("Error adding series 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.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractAclServiceRestEndpoint method createAcl.
@POST
@Path("/acl")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "createacl", description = "Create an ACL", returnDescription = "Create an ACL", restParameters = { @RestParameter(name = "name", isRequired = true, description = "The ACL name", type = STRING), @RestParameter(name = "acl", isRequired = true, description = "The access control list", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has successfully been added"), @RestResponse(responseCode = SC_CONFLICT, description = "An ACL with the same name already exists"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the ACL"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Error during adding the ACL") })
public String createAcl(@FormParam("name") String name, @FormParam("acl") String accessControlList) {
final AccessControlList acl = parseAcl.apply(accessControlList);
final Option<ManagedAcl> managedAcl = aclService().createAcl(acl, name);
if (managedAcl.isNone()) {
logger.info("An ACL with the same name '{}' already exists", name);
throw new WebApplicationException(Response.Status.CONFLICT);
}
return JsonConv.full(managedAcl.get()).toJson();
}
Aggregations