use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class UserTrackingRestService method addFootprint.
@PUT
@Path("")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "add", description = "Record a user action", returnDescription = "An XML representation of the user action", restParameters = { @RestParameter(name = "id", description = "The episode identifier", isRequired = true, type = Type.STRING), @RestParameter(name = "type", description = "The episode identifier", isRequired = true, type = Type.STRING), @RestParameter(name = "in", description = "The beginning of the time range", isRequired = true, type = Type.STRING), @RestParameter(name = "out", description = "The end of the time range", isRequired = false, type = Type.STRING), @RestParameter(name = "playing", description = "Whether the player is currently playing", isRequired = false, type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_CREATED, description = "An XML representation of the user action") })
public Response addFootprint(@FormParam("id") String mediapackageId, @FormParam("in") String inString, @FormParam("out") String outString, @FormParam("type") String type, @FormParam("playing") String isPlaying, @Context HttpServletRequest request) {
String sessionId = request.getSession().getId();
String userId = securityService.getUser().getUsername();
// Parse the in and out strings, which might be empty (hence, we can't let jax-rs handle them properly)
if (StringUtils.isEmpty(inString)) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity("in must be a non null integer").build());
}
Integer in = null;
try {
in = Integer.parseInt(StringUtils.trim(inString));
} catch (NumberFormatException e) {
throw new WebApplicationException(e, Response.status(Status.BAD_REQUEST).entity("in must be a non null integer").build());
}
Integer out = null;
if (StringUtils.isEmpty(outString)) {
out = in;
} else {
try {
out = Integer.parseInt(StringUtils.trim(outString));
} catch (NumberFormatException e) {
throw new WebApplicationException(e, Response.status(Status.BAD_REQUEST).entity("out must be a non null integer").build());
}
}
// MH-8616 the connection might be via a proxy
String clientIP = request.getHeader("X-FORWARDED-FOR");
if (clientIP == null) {
clientIP = request.getRemoteAddr();
}
logger.debug("Got client ip: {}", clientIP);
UserSession s = new UserSessionImpl();
s.setSessionId(sessionId);
s.setUserIp(clientIP);
s.setUserId(userId);
// Column length is currently 255, let's limit it to that.
String userAgent = StringUtils.trimToNull(request.getHeader("User-Agent"));
if (userAgent != null && userAgent.length() > 255) {
s.setUserAgent(userAgent.substring(0, 255));
} else {
s.setUserAgent(userAgent);
}
UserActionImpl a = new UserActionImpl();
a.setMediapackageId(mediapackageId);
a.setSession(s);
a.setInpoint(in);
a.setOutpoint(out);
a.setType(type);
a.setIsPlaying(Boolean.valueOf(isPlaying));
try {
if ("FOOTPRINT".equals(type)) {
a = (UserActionImpl) usertrackingService.addUserFootprint(a, s);
} else {
a = (UserActionImpl) usertrackingService.addUserTrackingEvent(a, s);
}
} catch (UserTrackingException e) {
throw new WebApplicationException(e);
}
URI uri;
try {
uri = new URI(UrlSupport.concat(new String[] { serverUrl, serviceUrl, "action", a.getId().toString(), ".xml" }));
} catch (URISyntaxException e) {
throw new WebApplicationException(e);
}
return Response.created(uri).entity(a).build();
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class VideoEditorServiceEndpoint method processSmil.
@POST
@Path("/process-smil")
@Produces({ MediaType.APPLICATION_XML })
@RestQuery(name = "processsmil", description = "Create smil processing jobs.", returnDescription = "Smil processing jobs.", restParameters = { @RestParameter(name = "smil", type = RestParameter.Type.TEXT, description = "Smil document to process.", isRequired = true) }, reponses = { @RestResponse(description = "Smil processing jobs created successfully.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Internal server error.", responseCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR) })
public Response processSmil(@FormParam("smil") String smilStr) {
Smil smil;
try {
smil = smilService.fromXml(smilStr).getSmil();
List<Job> jobs = videoEditorService.processSmil(smil);
return Response.ok(new JaxbJobList(jobs)).build();
} catch (Exception ex) {
return Response.serverError().entity(ex.getMessage()).build();
}
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class UserEndpoint method getUsersAsXml.
@GET
@Path("users.xml")
@Produces(MediaType.APPLICATION_XML)
@RestQuery(name = "allusersasxml", description = "Returns a list of users", returnDescription = "Returns a XML representation of the list of user accounts", restParameters = { @RestParameter(description = "The search query, must be at lest 3 characters long.", isRequired = false, name = "query", type = RestParameter.Type.STRING), @RestParameter(defaultValue = "100", description = "The maximum number of items to return per page.", isRequired = false, name = "limit", type = RestParameter.Type.INTEGER), @RestParameter(defaultValue = "0", description = "The page number.", isRequired = false, name = "offset", type = RestParameter.Type.INTEGER) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The user accounts.") })
public Response getUsersAsXml(@QueryParam("query") String queryString, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws IOException {
if (limit < 1)
limit = 100;
String query = "%";
if (StringUtils.isNotBlank(queryString)) {
if (queryString.trim().length() < 3)
return Response.status(Status.BAD_REQUEST).build();
query = queryString;
}
JaxbUserList userList = new JaxbUserList();
for (Iterator<User> i = userDirectoryService.findUsers(query, offset, limit); i.hasNext(); ) {
userList.add(i.next());
}
return Response.ok(userList).build();
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method getPublicationList.
@GET
@Path("{eventId}/asset/publication/publications.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getPublicationList", description = "Returns a list of publications from the given event as JSON", returnDescription = "The list of publications from the given event as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns a list of publications from the given event as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getPublicationList(@PathParam("eventId") String id) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", id);
MediaPackage mp = getIndexService().getEventMediapackage(optEvent.get());
return okJson(arr(getEventPublications(mp.getPublications())));
}
use of org.opencastproject.util.doc.rest.RestQuery in project opencast by opencast.
the class AbstractEventEndpoint method updateEventTransition.
@PUT
@Path("{eventId}/transitions/{transitionId}")
@RestQuery(name = "updateEventTransition", description = "Updates an ACL transition of an event", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING), @RestParameter(name = "transitionId", isRequired = true, description = "The transition identifier", type = RestParameter.Type.INTEGER) }, restParameters = { @RestParameter(name = "transition", isRequired = true, description = "The updated transition (JSON object)", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event or transtion has not been found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method doesn't return any content") })
public Response updateEventTransition(@PathParam("eventId") String eventId, @PathParam("transitionId") long transitionId, @FormParam("transition") String transitionStr) throws NotFoundException, SearchIndexException {
if (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().updateEpisodeTransition(transitionId, managedAclId, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))), workflowRef);
return Response.noContent().build();
} 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 (AclServiceException e) {
logger.error("Unable to update transtion {} of event {}: {}", transitionId, eventId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
} catch (ParseException e) {
// That should never happen
throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
}
}
Aggregations