Search in sources :

Example 36 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class EventTest method testValueOf.

@Ignore
@Test
public void testValueOf() throws ParseException, IOException, JSONException, XMLStreamException, JAXBException {
    Event event = Event.valueOf(IOUtils.toInputStream(eventXml));
    assertEquals(id, event.getIdentifier());
    assertEquals(title, event.getTitle());
    assertEquals(description, event.getDescription());
    assertEquals(subject, event.getSubject());
    assertEquals(location, event.getLocation());
    assertEquals(presenter1, event.getPresenters().get(0));
    assertEquals(presenter2, event.getPresenters().get(1));
    assertEquals(presenter3, event.getPresenters().get(2));
    assertEquals(contributor1, event.getContributors().get(0));
    assertEquals(contributor2, event.getContributors().get(1));
    assertEquals(contributor3, event.getContributors().get(2));
}
Also used : Event(org.opencastproject.index.service.impl.index.event.Event) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class AbstractEventEndpoint method applyAclToEvent.

@POST
@Path("{eventId}/access")
@RestQuery(name = "applyAclToEvent", description = "Immediate application of an ACL to an event", returnDescription = "Status code", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event ID", type = STRING) }, restParameters = { @RestParameter(name = "acl", isRequired = true, description = "The ACL to apply", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The ACL has been successfully applied"), @RestResponse(responseCode = SC_BAD_REQUEST, description = "Unable to parse the given ACL"), @RestResponse(responseCode = SC_NOT_FOUND, description = "The the event has not been found"), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "Not authorized to perform this action"), @RestResponse(responseCode = SC_INTERNAL_SERVER_ERROR, description = "Internal error") })
public Response applyAclToEvent(@PathParam("eventId") String eventId, @FormParam("acl") String acl) throws NotFoundException, UnauthorizedException, SearchIndexException, IndexServiceException {
    final AccessControlList accessControlList;
    try {
        accessControlList = AccessControlParser.parseAcl(acl);
    } catch (Exception e) {
        logger.warn("Unable to parse ACL '{}'", acl);
        return badRequest();
    }
    try {
        final Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
        if (optEvent.isNone()) {
            logger.warn("Unable to find the event '{}'", eventId);
            return notFound();
        }
        Source eventSource = getIndexService().getEventSource(optEvent.get());
        if (eventSource == Source.ARCHIVE) {
            if (getAclService().applyAclToEpisode(eventId, accessControlList, Option.<ConfiguredWorkflowRef>none())) {
                return ok();
            } else {
                logger.warn("Unable to find the event '{}'", eventId);
                return notFound();
            }
        } else if (eventSource == Source.WORKFLOW) {
            logger.warn("An ACL cannot be edited while an event is part of a current workflow because it might" + " lead to inconsistent ACLs i.e. changed after distribution so that the old ACL is still " + "being used by the distribution channel.");
            JSONObject json = new JSONObject();
            json.put("Error", "Unable to edit an ACL for a current workflow.");
            return conflict(json.toJSONString());
        } else {
            MediaPackage mediaPackage = getIndexService().getEventMediapackage(optEvent.get());
            mediaPackage = getAuthorizationService().setAcl(mediaPackage, AclScope.Episode, accessControlList).getA();
            getSchedulerService().updateEvent(eventId, Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), some(mediaPackage), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
            return ok();
        }
    } catch (AclServiceException e) {
        logger.error("Error applying acl '{}' to event '{}' because: {}", accessControlList, eventId, ExceptionUtils.getStackTrace(e));
        return serverError();
    } catch (SchedulerException e) {
        logger.error("Error applying ACL to scheduled event {} because {}", eventId, ExceptionUtils.getStackTrace(e));
        return serverError();
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) Set(java.util.Set) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) EventCommentException(org.opencastproject.event.comment.EventCommentException) JSONException(org.codehaus.jettison.json.JSONException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) Source(org.opencastproject.index.service.api.IndexService.Source) Date(java.util.Date) Opt(com.entwinemedia.fn.data.Opt) JSONObject(org.json.simple.JSONObject) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 38 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class AbstractEventEndpoint method getEventAccessInformation.

@GET
@Path("{eventId}/access.json")
@SuppressWarnings("unchecked")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getEventAccessInformation", description = "Get the access information of an event", returnDescription = "The access information", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required form params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event has not been found."), @RestResponse(responseCode = SC_OK, description = "The access information ") })
public Response getEventAccessInformation(@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);
    // Add all available ACLs to the response
    JSONArray systemAclsJson = new JSONArray();
    List<ManagedAcl> acls = getAclService().getAcls();
    for (ManagedAcl acl : acls) {
        systemAclsJson.add(AccessInformationUtil.serializeManagedAcl(acl));
    }
    // Get the episode ACL
    final TransitionQuery q = TransitionQuery.query().withId(eventId).withScope(AclScope.Episode);
    List<EpisodeACLTransition> episodeTransistions;
    JSONArray transitionsJson = new JSONArray();
    try {
        episodeTransistions = getAclService().getTransitions(q).getEpisodeTransistions();
        for (EpisodeACLTransition trans : episodeTransistions) {
            transitionsJson.add(AccessInformationUtil.serializeEpisodeACLTransition(trans));
        }
    } catch (AclServiceException e) {
        logger.error("There was an error while trying to get the ACL transitions for series '{}' from the ACL service: {}", eventId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
    AccessControlList activeAcl = new AccessControlList();
    try {
        if (optEvent.get().getAccessPolicy() != null)
            activeAcl = AccessControlParser.parseAcl(optEvent.get().getAccessPolicy());
    } catch (Exception e) {
        logger.error("Unable to parse access policy because: {}", ExceptionUtils.getStackTrace(e));
    }
    Option<ManagedAcl> currentAcl = AccessInformationUtil.matchAcls(acls, activeAcl);
    JSONObject episodeAccessJson = new JSONObject();
    episodeAccessJson.put("current_acl", currentAcl.isSome() ? currentAcl.get().getId() : 0L);
    episodeAccessJson.put("acl", AccessControlParser.toJsonSilent(activeAcl));
    episodeAccessJson.put("privileges", AccessInformationUtil.serializePrivilegesByRole(activeAcl));
    episodeAccessJson.put("transitions", transitionsJson);
    if (StringUtils.isNotBlank(optEvent.get().getWorkflowState()) && WorkflowUtil.isActive(WorkflowInstance.WorkflowState.valueOf(optEvent.get().getWorkflowState())))
        episodeAccessJson.put("locked", true);
    JSONObject jsonReturnObj = new JSONObject();
    jsonReturnObj.put("episode_access", episodeAccessJson);
    jsonReturnObj.put("system_acls", systemAclsJson);
    return Response.ok(jsonReturnObj.toString()).build();
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) JSONArray(org.json.simple.JSONArray) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) EventCommentException(org.opencastproject.event.comment.EventCommentException) JSONException(org.codehaus.jettison.json.JSONException) JobEndpointException(org.opencastproject.adminui.exception.JobEndpointException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowStateException(org.opencastproject.workflow.api.WorkflowStateException) JSONObject(org.json.simple.JSONObject) TransitionQuery(org.opencastproject.authorization.xacml.manager.api.TransitionQuery) Event(org.opencastproject.index.service.impl.index.event.Event) EpisodeACLTransition(org.opencastproject.authorization.xacml.manager.api.EpisodeACLTransition) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 39 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class AbstractEventEndpoint method addEventTransition.

@POST
@Path("{eventId}/transitions")
@RestQuery(name = "addEventTransition", description = "Adds an ACL transition to an event", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(name = "transition", isRequired = true, description = "The transition (JSON object) to add", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required params were missing in the request."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method doesn't return any content"), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event has not been found.") })
public Response addEventTransition(@PathParam("eventId") String eventId, @FormParam("transition") String transitionStr) throws SearchIndexException {
    if (StringUtils.isBlank(eventId) || 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().addEpisodeTransition(eventId, managedAclId, new Date(DateTimeSupport.fromUTC(t.getString("application_date"))), workflowRef);
        return Response.noContent().build();
    } catch (AclServiceException e) {
        logger.error("Error while trying to get ACL transitions for event '{}' from ACL service: {}", eventId, e);
        throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
    } 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 (ParseException e) {
        return RestUtil.R.badRequest("The date could not be parsed");
    }
}
Also used : AclServiceException(org.opencastproject.authorization.xacml.manager.api.AclServiceException) WebApplicationException(javax.ws.rs.WebApplicationException) JSONException(org.codehaus.jettison.json.JSONException) Date(java.util.Date) JSONObject(org.json.simple.JSONObject) Event(org.opencastproject.index.service.impl.index.event.Event) ParseException(java.text.ParseException) ConfiguredWorkflowRef(org.opencastproject.workflow.api.ConfiguredWorkflowRef) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 40 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class AbstractEventEndpoint method getEventGeneralTab.

@GET
@Path("{eventId}/general.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "geteventgeneral", description = "Returns all the data related to the general tab in the event details modal as JSON", returnDescription = "All the data related to the event general tab as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id (mediapackage id).", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns all the data related to the event general tab as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getEventGeneralTab(@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);
    // Quick actions have been temporally removed from the general tab
    // ---------------------------------------------------------------
    // List<JValue> actions = new ArrayList<JValue>();
    // List<WorkflowDefinition> workflowsDefinitions = getWorkflowService().listAvailableWorkflowDefinitions();
    // for (WorkflowDefinition wflDef : workflowsDefinitions) {
    // if (wflDef.containsTag(WORKFLOWDEF_TAG)) {
    // 
    // actions.add(obj(f("id", v(wflDef.getId())), f("title", v(Opt.nul(wflDef.getTitle()).or(""))),
    // f("description", v(Opt.nul(wflDef.getDescription()).or(""))),
    // f("configuration_panel", v(Opt.nul(wflDef.getConfigurationPanel()).or("")))));
    // }
    // }
    Event event = optEvent.get();
    List<JValue> pubJSON = eventPublicationsToJson(event);
    return okJson(obj(f("publications", arr(pubJSON)), f("optout", v(event.getOptedOut(), Jsons.BLANK)), f("blacklisted", v(event.getBlacklisted(), Jsons.BLANK)), f("review-status", v(event.getReviewStatus(), Jsons.BLANK)), f("start-date", v(event.getRecordingStartDate(), Jsons.BLANK)), f("end-date", v(event.getRecordingEndDate(), Jsons.BLANK))));
}
Also used : JValue(com.entwinemedia.fn.data.json.JValue) Event(org.opencastproject.index.service.impl.index.event.Event) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

Event (org.opencastproject.index.service.impl.index.event.Event)67 Path (javax.ws.rs.Path)35 RestQuery (org.opencastproject.util.doc.rest.RestQuery)34 NotFoundException (org.opencastproject.util.NotFoundException)26 WebApplicationException (javax.ws.rs.WebApplicationException)24 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)22 Produces (javax.ws.rs.Produces)21 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)19 MediaPackage (org.opencastproject.mediapackage.MediaPackage)19 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)19 ParseException (java.text.ParseException)17 JSONException (org.codehaus.jettison.json.JSONException)17 UrlSigningException (org.opencastproject.security.urlsigning.exception.UrlSigningException)17 GET (javax.ws.rs.GET)16 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)16 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)16 EventCommentException (org.opencastproject.event.comment.EventCommentException)15 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)15 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)14 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)14