use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method workflowAction.
@PUT
@Path("{eventId}/workflows/{workflowId}/action/{action}")
@RestQuery(name = "workflowAction", description = "Performs the given action for the given workflow.", returnDescription = "", pathParameters = { @RestParameter(name = "eventId", description = "The id of the media package", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "workflowId", description = "The id of the workflow", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "action", description = "The action to take: STOP, RETRY or NONE (abort processing)", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Workflow resumed."), @RestResponse(responseCode = SC_NOT_FOUND, description = "Event or workflow instance not found."), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Invalid action entered."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "You do not have permission to perform the action. Maybe you need to authenticate."), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "An exception occurred.") })
public Response workflowAction(@PathParam("eventId") String id, @PathParam("workflowId") long wfId, @PathParam("action") String action) {
if (StringUtils.isEmpty(id) || StringUtils.isEmpty(action)) {
return badRequest();
}
try {
final Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
if (optEvent.isNone()) {
return notFound("Cannot find an event with id '%s'.", id);
}
final WorkflowInstance wfInstance = getWorkflowService().getWorkflowById(wfId);
if (!wfInstance.getMediaPackage().getIdentifier().toString().equals(id)) {
return badRequest(String.format("Workflow %s is not associated to event %s", wfId, id));
}
if (RetryStrategy.NONE.toString().equalsIgnoreCase(action) || RetryStrategy.RETRY.toString().equalsIgnoreCase(action)) {
getWorkflowService().resume(wfId, Collections.singletonMap("retryStrategy", action));
return ok();
}
if (WORKFLOW_ACTION_STOP.equalsIgnoreCase(action)) {
getWorkflowService().stop(wfId);
return ok();
}
return badRequest("Action not supported: " + action);
} catch (NotFoundException e) {
return notFound("Workflow not found: '%d'.", wfId);
} catch (IllegalStateException e) {
return badRequest(String.format("Action %s not allowed for current workflow state. EventId: %s", action, id));
} catch (UnauthorizedException e) {
return forbidden();
} catch (Exception e) {
return serverError();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method getCatalogAdapters.
@GET
@Path("catalogAdapters")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getcataloguiadapters", description = "Returns the available catalog UI adapters as JSON", returnDescription = "The catalog UI adapters as JSON", reponses = { @RestResponse(description = "Returns the available catalog UI adapters as JSON", responseCode = HttpServletResponse.SC_OK) })
public Response getCatalogAdapters() {
List<JValue> adapters = new ArrayList<>();
for (EventCatalogUIAdapter adapter : getIndexService().getEventCatalogUIAdapters()) {
List<Field> fields = new ArrayList<>();
fields.add(f("flavor", v(adapter.getFlavor().toString())));
fields.add(f("title", v(adapter.getUITitle())));
adapters.add(obj(fields));
}
return okJson(arr(adapters));
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method getPublication.
@GET
@Path("{eventId}/asset/publication/{id}.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getPublication", description = "Returns the details of a publication from the given event and publication id as JSON", returnDescription = "The details of a publication from the given event and publication id as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "id", description = "The publication id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns the publication of a catalog from the given event and publication id as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event or publication with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getPublication(@PathParam("eventId") String eventId, @PathParam("id") String id) throws NotFoundException, SearchIndexException, IndexServiceException {
MediaPackage mp = getMediaPackageByEventId(eventId);
Publication publication = null;
for (Publication p : mp.getPublications()) {
if (id.equals(p.getIdentifier())) {
publication = p;
break;
}
}
if (publication == null)
return notFound("Cannot find publication with id '%s'.", id);
return okJson(publicationToJSON(publication));
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AclEndpoint method getAclsAsJson.
@GET
@Path("acls.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "allaclasjson", description = "Returns a list of acls", returnDescription = "Returns a JSON representation of the list of acls available the current user's organization", restParameters = { @RestParameter(name = "filter", isRequired = false, description = "The filter used for the query. They should be formated like that: 'filter1:value1,filter2:value2'", type = STRING), @RestParameter(name = "sort", isRequired = false, description = "The sort order. May include any of the following: NAME. Add '_DESC' to reverse the sort order (e.g. NAME_DESC).", type = STRING), @RestParameter(defaultValue = "100", description = "The maximum number of items to return per page.", isRequired = false, name = "limit", type = RestParameter.Type.STRING), @RestParameter(defaultValue = "0", description = "The page number.", isRequired = false, name = "offset", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The list of ACL's has successfully been returned") })
public Response getAclsAsJson(@QueryParam("filter") String filter, @QueryParam("sort") String sort, @QueryParam("offset") int offset, @QueryParam("limit") int limit) throws IOException {
if (limit < 1)
limit = 100;
Opt<String> optSort = Opt.nul(trimToNull(sort));
Option<String> filterName = Option.none();
Option<String> filterText = Option.none();
Map<String, String> filters = RestUtils.parseFilter(filter);
for (String name : filters.keySet()) {
String value = filters.get(name);
if (AclsListQuery.FILTER_NAME_NAME.equals(name)) {
filterName = Option.some(value);
} else if ((AclsListQuery.FILTER_TEXT_NAME.equals(name)) && (StringUtils.isNotBlank(value))) {
filterText = Option.some(value);
}
}
// Filter acls by filter criteria
List<ManagedAcl> filteredAcls = new ArrayList<>();
for (ManagedAcl acl : aclService().getAcls()) {
// Filter list
if ((filterName.isSome() && !filterName.get().equals(acl.getName())) || (filterText.isSome() && !TextFilter.match(filterText.get(), acl.getName()))) {
continue;
}
filteredAcls.add(acl);
}
int total = filteredAcls.size();
// Sort by name, description or role
if (optSort.isSome()) {
final Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(optSort.get());
Collections.sort(filteredAcls, new Comparator<ManagedAcl>() {
@Override
public int compare(ManagedAcl acl1, ManagedAcl acl2) {
for (SortCriterion criterion : sortCriteria) {
Order order = criterion.getOrder();
switch(criterion.getFieldName()) {
case "name":
if (order.equals(Order.Descending))
return ObjectUtils.compare(acl2.getName(), acl1.getName());
return ObjectUtils.compare(acl1.getName(), acl2.getName());
default:
logger.info("Unkown sort type: {}", criterion.getFieldName());
return 0;
}
}
return 0;
}
});
}
// Apply Limit and offset
List<JValue> aclJSON = Stream.$(filteredAcls).drop(offset).apply(limit > 0 ? StreamOp.<ManagedAcl>id().take(limit) : StreamOp.<ManagedAcl>id()).map(fullManagedAcl).toList();
return okJsonList(aclJSON, offset, limit, total);
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AclEndpoint method createAcl.
@POST
@Path("")
@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") })
public Response createAcl(@FormParam("name") String name, @FormParam("acl") String accessControlList) {
final AccessControlList acl = parseAcl.apply(accessControlList);
final Opt<ManagedAcl> managedAcl = aclService().createAcl(acl, name).toOpt();
if (managedAcl.isNone()) {
logger.info("An ACL with the same name '{}' already exists", name);
throw new WebApplicationException(Response.Status.CONFLICT);
}
return RestUtils.okJson(full(managedAcl.get()));
}
Aggregations