Search in sources :

Example 1 with Val

use of org.opencastproject.util.Jsons.Val in project opencast by opencast.

the class AbstractEventEndpoint method getEventComments.

@GET
@Path("{eventId}/comments")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "geteventcomments", description = "Returns all the data related to the comments tab in the event details modal as JSON", returnDescription = "All the data related to the event comments tab as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns all the data related to the event comments tab as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getEventComments(@PathParam("eventId") String eventId) throws Exception {
    Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
    if (optEvent.isNone())
        return notFound("Cannot find an event with id '%s'.", eventId);
    try {
        List<EventComment> comments = getEventCommentService().getComments(eventId);
        List<Val> commentArr = new ArrayList<>();
        for (EventComment c : comments) {
            commentArr.add(c.toJson());
        }
        return Response.ok(org.opencastproject.util.Jsons.arr(commentArr).toJson(), MediaType.APPLICATION_JSON_TYPE).build();
    } catch (EventCommentException e) {
        logger.error("Unable to get comments from event {}: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e);
    }
}
Also used : Val(org.opencastproject.util.Jsons.Val) EventComment(org.opencastproject.event.comment.EventComment) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) Event(org.opencastproject.index.service.impl.index.event.Event) EventCommentException(org.opencastproject.event.comment.EventCommentException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 2 with Val

use of org.opencastproject.util.Jsons.Val in project opencast by opencast.

the class EventComment method toJson.

public Obj toJson() {
    Obj authorObj = Jsons.obj(Jsons.p("name", author.getName()), Jsons.p("username", author.getUsername()), Jsons.p("email", author.getEmail()));
    List<Val> replyArr = new ArrayList<Val>();
    for (EventCommentReply reply : replies) {
        replyArr.add(reply.toJson());
    }
    Val idValue = Jsons.ZERO_VAL;
    if (id.isSome())
        idValue = Jsons.v(id.get());
    return Jsons.obj(Jsons.p("id", idValue), Jsons.p("text", text), Jsons.p("creationDate", DateTimeSupport.toUTC(creationDate.getTime())), Jsons.p("modificationDate", DateTimeSupport.toUTC(modificationDate.getTime())), Jsons.p("author", authorObj), Jsons.p("reason", reason), Jsons.p("resolvedStatus", resolvedStatus), Jsons.p("replies", Jsons.arr(replyArr)));
}
Also used : Val(org.opencastproject.util.Jsons.Val) Obj(org.opencastproject.util.Jsons.Obj) ArrayList(java.util.ArrayList)

Example 3 with Val

use of org.opencastproject.util.Jsons.Val in project opencast by opencast.

the class EventCommentReply method toJson.

public Obj toJson() {
    Obj authorObj = Jsons.obj(Jsons.p("name", author.getName()), Jsons.p("username", author.getUsername()), Jsons.p("email", author.getEmail()));
    Val idValue = Jsons.ZERO_VAL;
    if (id.isSome())
        idValue = Jsons.v(id.get());
    return Jsons.obj(Jsons.p("id", idValue), Jsons.p("text", text), Jsons.p("author", authorObj), Jsons.p("creationDate", DateTimeSupport.toUTC(creationDate.getTime())), Jsons.p("modificationDate", DateTimeSupport.toUTC(modificationDate.getTime())));
}
Also used : Val(org.opencastproject.util.Jsons.Val) Obj(org.opencastproject.util.Jsons.Obj)

Example 4 with Val

use of org.opencastproject.util.Jsons.Val in project opencast by opencast.

the class SchedulerRestService method getTechnicalMetadataJSON.

/**
 * Gets a XML with the media package for the specified event.
 *
 * @param eventId
 *          The unique ID of the event.
 * @return media package XML for the event
 */
@GET
@Produces(MediaType.TEXT_XML)
@Path("{id:.+}/technical.json")
@RestQuery(name = "gettechnicalmetadatajson", description = "Retrieves the technical metadata for specified event", returnDescription = "technical metadata as JSON", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "ID of event for which the technical metadata will be retrieved", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "technical metadata of event is in the body of response"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "Event with specified ID does not exist"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to remove the event. Maybe you need to authenticate.") })
public Response getTechnicalMetadataJSON(@PathParam("id") String eventId) throws UnauthorizedException {
    try {
        TechnicalMetadata metadata = service.getTechnicalMetadata(eventId);
        Val state = v("");
        Val lastHeard = v("");
        if (metadata.getRecording().isSome()) {
            state = v(metadata.getRecording().get().getState());
            lastHeard = v(DateTimeSupport.toUTC(metadata.getRecording().get().getLastCheckinTime()));
        }
        Arr presenters = arr(mlist(metadata.getPresenters()).map(Jsons.stringVal));
        List<Prop> wfProperties = new ArrayList<>();
        for (Entry<String, String> entry : metadata.getWorkflowProperties().entrySet()) {
            wfProperties.add(p(entry.getKey(), entry.getValue()));
        }
        List<Prop> agentConfig = new ArrayList<>();
        for (Entry<String, String> entry : metadata.getCaptureAgentConfiguration().entrySet()) {
            agentConfig.add(p(entry.getKey(), entry.getValue()));
        }
        return RestUtil.R.ok(obj(p("id", metadata.getEventId()), p("location", metadata.getAgentId()), p("start", DateTimeSupport.toUTC(metadata.getStartDate().getTime())), p("end", DateTimeSupport.toUTC(metadata.getEndDate().getTime())), p("optOut", metadata.isOptOut()), p("presenters", presenters), p("wfProperties", obj(wfProperties.toArray(new Prop[wfProperties.size()]))), p("agentConfig", obj(agentConfig.toArray(new Prop[agentConfig.size()]))), p("state", state), p("lastHeardFrom", lastHeard)));
    } catch (NotFoundException e) {
        logger.info("Event with id '{}' does not exist.", eventId);
        return Response.status(Status.NOT_FOUND).build();
    } catch (SchedulerException e) {
        logger.error("Unable to retrieve event with id '{}': {}", eventId, getMessage(e));
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : Val(org.opencastproject.util.Jsons.Val) Arr(org.opencastproject.util.Jsons.Arr) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) Prop(org.opencastproject.util.Jsons.Prop) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

Val (org.opencastproject.util.Jsons.Val)4 ArrayList (java.util.ArrayList)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Obj (org.opencastproject.util.Jsons.Obj)2 RestQuery (org.opencastproject.util.doc.rest.RestQuery)2 EventComment (org.opencastproject.event.comment.EventComment)1 EventCommentException (org.opencastproject.event.comment.EventCommentException)1 Event (org.opencastproject.index.service.impl.index.event.Event)1 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)1 TechnicalMetadata (org.opencastproject.scheduler.api.TechnicalMetadata)1 Arr (org.opencastproject.util.Jsons.Arr)1 Prop (org.opencastproject.util.Jsons.Prop)1 NotFoundException (org.opencastproject.util.NotFoundException)1