Search in sources :

Example 11 with Event

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

the class AbstractSearchIndex method deleteAssets.

/**
 * Delete an event from the asset manager.
 *
 * @param organization
 *          The organization the event is a part of.
 * @param user
 *          The user that is requesting to delete the event.
 * @param uid
 *          The identifier of the event.
 * @throws SearchIndexException
 *           Thrown if there is an issue with deleting the event.
 * @throws NotFoundException
 *           Thrown if the event cannot be found.
 */
public void deleteAssets(String organization, User user, String uid) throws SearchIndexException, NotFoundException {
    Event event = EventIndexUtils.getEvent(uid, organization, user, this);
    if (event == null)
        throw new NotFoundException("No event with id " + uid + " found.");
    event.setArchiveVersion(null);
    if (toDelete(event)) {
        delete(Event.DOCUMENT_TYPE, uid.concat(organization));
    } else {
        addOrUpdate(event);
    }
}
Also used : Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException)

Example 12 with Event

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

the class SchedulerMessageReceiverImpl method execute.

@Override
protected void execute(SchedulerItem schedulerItem) {
    DublinCoreCatalog dc = schedulerItem.getEvent();
    Event event = null;
    String organization = getSecurityService().getOrganization().getId();
    User user = getSecurityService().getUser();
    switch(schedulerItem.getType()) {
        case UpdateCatalog:
            logger.debug("Received Update Catalog");
            // Load or create the corresponding recording event
            try {
                event = getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                if (isBlank(event.getCreator()))
                    event.setCreator(getSecurityService().getUser().getName());
                if (event.getBlacklisted() == null)
                    event.setBlacklisted(false);
                if (event.getOptedOut() == null)
                    event.setOptedOut(false);
                if (dc != null)
                    EventIndexUtils.updateEvent(event, dc);
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Update series name if not already done
            try {
                EventIndexUtils.updateSeriesName(event, organization, user, getSearchIndex());
            } catch (SearchIndexException e) {
                logger.error("Error updating the series name of the event to index: {}", getStackTrace(e));
            }
            // Persist the scheduling event
            updateEvent(event);
            break;
        case UpdateAcl:
            logger.debug("Received Update ACL");
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setAccessPolicy(AccessControlParser.toJsonSilent(schedulerItem.getAcl()));
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateAgentId:
            logger.debug("Received update event '{}' with agent id to '{}'", schedulerItem.getId(), schedulerItem.getAgentId());
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setAgentId(schedulerItem.getAgentId());
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateProperties:
            logger.debug("Received update event '{}' CA Properties '{}'", schedulerItem.getId(), schedulerItem.getProperties());
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setAgentConfiguration(schedulerItem.getProperties());
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateOptOut:
            logger.debug("Received Update opt out status");
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setOptedOut(schedulerItem.getOptOut());
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateBlacklist:
            logger.debug("Received Update blacklist status");
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setBlacklisted(schedulerItem.getBlacklisted());
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateReviewStatus:
            logger.debug("Received Update review status");
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setReviewStatus(schedulerItem.getReviewStatus());
                if (schedulerItem.getReviewDate() != null)
                    event.setReviewDate(DateTimeSupport.toUTC(schedulerItem.getReviewDate().getTime()));
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateRecordingStatus:
            logger.debug("Received Update Recording {}", schedulerItem.getMediaPackageId());
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setRecordingStatus(schedulerItem.getRecordingState());
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case DeleteRecordingStatus:
            logger.debug("Received Delete recording status {}", schedulerItem.getMediaPackageId());
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setRecordingStatus(null);
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateEnd:
            String endTime = schedulerItem.getEnd() == null ? null : DateTimeSupport.toUTC(schedulerItem.getEnd().getTime());
            logger.debug("Received update event '{}' end time '{}'", schedulerItem.getId(), endTime);
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setTechnicalEndTime(endTime);
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdateStart:
            String startTime = schedulerItem.getStart() == null ? null : DateTimeSupport.toUTC(schedulerItem.getStart().getTime());
            logger.debug("Received update event '{}' start time '{}'", schedulerItem.getId(), startTime);
            // Load the corresponding recording event
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setTechnicalStartTime(startTime);
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case UpdatePresenters:
            logger.debug("Received update event '{}' with presenters '{}'", schedulerItem.getId(), schedulerItem.getPresenters());
            try {
                event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
                event.setTechnicalPresenters(new ArrayList<>(schedulerItem.getPresenters()));
            } catch (SearchIndexException e) {
                logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            // Persist the scheduling event
            updateEvent(event);
            return;
        case Delete:
            logger.debug("Received Delete Event {}", schedulerItem.getMediaPackageId());
            // Remove the scheduling from the search index
            try {
                getSearchIndex().deleteScheduling(organization, user, schedulerItem.getMediaPackageId());
                logger.debug("Scheduled recording {} removed from the {} search index", schedulerItem.getMediaPackageId(), getSearchIndex().getIndexName());
            } catch (NotFoundException e) {
                logger.warn("Scheduled recording {} not found for deletion", schedulerItem.getMediaPackageId());
            } catch (SearchIndexException e) {
                logger.error("Error deleting the recording event from the search index: {}", getStackTrace(e));
                return;
            }
            return;
        default:
            throw new IllegalArgumentException("Unhandled type of SchedulerItem");
    }
}
Also used : User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) EventIndexUtils.getOrCreateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.getOrCreateEvent) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 13 with Event

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

the class AssetManagerMessageReceiverImpl method handleMessage.

/**
 * Handle an update message.
 */
private void handleMessage(TakeSnapshot msg) {
    logger.debug("Received AssetManager take snapshot message");
    final MediaPackage mp = msg.getMediapackage();
    final Opt<DublinCoreCatalog> episodeDublincore = msg.getEpisodeDublincore();
    final String organization = getSecurityService().getOrganization().getId();
    final User user = getSecurityService().getUser();
    // Load or create the corresponding recording event
    final Event event;
    try {
        event = getOrCreateEvent(mp.getIdentifier().toString(), organization, user, getSearchIndex());
        final AccessControlList acl = msg.getAcl();
        List<ManagedAcl> acls = aclServiceFactory.serviceFor(getSecurityService().getOrganization()).getAcls();
        for (final ManagedAcl managedAcl : AccessInformationUtil.matchAcls(acls, acl)) {
            event.setManagedAcl(managedAcl.getName());
        }
        event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
        event.setArchiveVersion(msg.getVersion());
        if (isBlank(event.getCreator()))
            event.setCreator(getSecurityService().getUser().getName());
        updateEvent(event, mp);
        if (episodeDublincore.isSome()) {
            updateEvent(event, episodeDublincore.get());
        }
    } catch (SearchIndexException e) {
        logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
        return;
    }
    // Update series name if not already done
    try {
        EventIndexUtils.updateSeriesName(event, organization, user, getSearchIndex());
    } catch (SearchIndexException e) {
        logger.error("Error updating the series name of the event to index: {}", ExceptionUtils.getStackTrace(e));
    }
    // Persist the scheduling event
    try {
        getSearchIndex().addOrUpdate(event);
        logger.debug("Asset manager entry {} updated in the admin ui search index", event.getIdentifier());
    } catch (SearchIndexException e) {
        logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Event(org.opencastproject.index.service.impl.index.event.Event) EventIndexUtils.getOrCreateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.getOrCreateEvent) EventIndexUtils.updateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.updateEvent) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 14 with Event

use of org.opencastproject.index.service.impl.index.event.Event 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())));
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) 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)

Example 15 with Event

use of org.opencastproject.index.service.impl.index.event.Event 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);
    }
}
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) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

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