use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class AbstractEventEndpoint method hasActiveTransaction.
@GET
@Path("{eventId}/hasActiveTransaction")
@Produces(MediaType.TEXT_PLAIN)
@RestQuery(name = "hasactivetransaction", description = "Returns whether there is currently a transaction in progress for the given event", returnDescription = "Whether there is currently a transaction in progress for the given event", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns whether there is currently a transaction in progress for the given event", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response hasActiveTransaction(@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);
JSONObject json = new JSONObject();
if (WorkflowInstance.WorkflowState.RUNNING.toString().equals(optEvent.get().getWorkflowState())) {
json.put("active", true);
} else {
json.put("active", false);
}
return Response.ok(json.toJSONString()).build();
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class AbstractEventEndpoint method resolveEventComment.
@POST
@Path("{eventId}/comment/{commentId}")
@RestQuery(name = "resolveeventcomment", description = "Resolves an event comment", returnDescription = "The resolved comment.", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "commentId", isRequired = true, description = "The comment identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_NOT_FOUND, description = "The event or comment to resolve has not been found."), @RestResponse(responseCode = SC_OK, description = "The resolved comment as JSON.") })
public Response resolveEventComment(@PathParam("eventId") String eventId, @PathParam("commentId") long commentId) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
try {
EventComment dto = getEventCommentService().getComment(commentId);
EventComment updatedComment = EventComment.create(dto.getId(), dto.getEventId(), dto.getOrganization(), dto.getText(), dto.getAuthor(), dto.getReason(), true, dto.getCreationDate(), new Date(), dto.getReplies());
updatedComment = getEventCommentService().updateComment(updatedComment);
List<EventComment> comments = getEventCommentService().getComments(eventId);
getIndexService().updateCommentCatalog(optEvent.get(), comments);
return Response.ok(updatedComment.toJson().toJson()).build();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not resolve comment {}: {}", commentId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e);
}
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class AbstractEventEndpoint method getMediaList.
@GET
@Path("{eventId}/asset/media/media.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getMediaList", description = "Returns a list of media from the given event as JSON", returnDescription = "The list of media 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 media 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 getMediaList(@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(getEventMediaPackageElements(mp.getTracks())));
}
use of org.opencastproject.index.service.impl.index.event.Event 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.index.service.impl.index.event.Event in project opencast by opencast.
the class TestSeriesEndpoint method createEvents.
@SuppressWarnings("unchecked")
private SearchResultItem<Event>[] createEvents(int readyCount, int blacklistedCount, int optedOutCount) {
SearchResultItem<Event>[] eventitems = new SearchResultItem[readyCount + blacklistedCount + optedOutCount];
int total = 1;
String orgId = new DefaultOrganization().getId();
for (int i = 0; i < readyCount; i++) {
Event readyEvent = new Event(Integer.toString(i + total), orgId);
readyEvent.setOptedOut(false);
SearchResultItem<Event> eventItem = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(eventItem.getSource()).andReturn(readyEvent);
EasyMock.replay(eventItem);
eventitems[total - 1] = eventItem;
total++;
}
for (int i = 0; i < blacklistedCount; i++) {
Event blacklistedEvent = new Event(Integer.toString(i + total), orgId);
blacklistedEvent.setBlacklisted(true);
SearchResultItem<Event> eventItem = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(eventItem.getSource()).andReturn(blacklistedEvent);
EasyMock.replay(eventItem);
eventitems[total - 1] = eventItem;
total++;
}
for (int i = 0; i < optedOutCount; i++) {
Event optedOutEvent = new Event(Integer.toString(i + total), orgId);
optedOutEvent.setOptedOut(true);
SearchResultItem<Event> eventItem = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(eventItem.getSource()).andReturn(optedOutEvent);
EasyMock.replay(eventItem);
eventitems[total - 1] = eventItem;
total++;
}
return eventitems;
}
Aggregations