Search in sources :

Example 11 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class EventsEndpoint method eventToJSON.

/**
 * Transform an {@link Event} to Json
 *
 * @param event
 *          The event to transform into json
 * @param withAcl
 *          Whether to add the acl information for the event
 * @param withMetadata
 *          Whether to add all the metadata for the event
 * @param withPublications
 *          Whether to add the publications
 * @param withSignedUrls
 *          Whether to sign the urls if they are protected by stream security.
 * @return The event in json format.
 * @throws IndexServiceException
 *           Thrown if unable to get the metadata for the event.
 * @throws SearchIndexException
 *           Thrown if unable to get event publications from search service
 * @throws NotFoundException
 *           Thrown if unable to find all of the metadata
 */
protected JValue eventToJSON(Event event, Boolean withAcl, Boolean withMetadata, Boolean withPublications, Boolean withSignedUrls) throws IndexServiceException, SearchIndexException, NotFoundException {
    List<Field> fields = new ArrayList<>();
    if (event.getArchiveVersion() != null)
        fields.add(f("archive_version", v(event.getArchiveVersion())));
    fields.add(f("created", v(event.getCreated(), Jsons.BLANK)));
    fields.add(f("creator", v(event.getCreator(), Jsons.BLANK)));
    fields.add(f("contributor", arr($(event.getContributors()).map(Functions.stringToJValue))));
    fields.add(f("description", v(event.getDescription(), Jsons.BLANK)));
    fields.add(f("has_previews", v(event.hasPreview())));
    fields.add(f("identifier", v(event.getIdentifier(), BLANK)));
    fields.add(f("location", v(event.getLocation(), BLANK)));
    fields.add(f("presenter", arr($(event.getPresenters()).map(Functions.stringToJValue))));
    List<JValue> publicationIds = new ArrayList<>();
    if (event.getPublications() != null) {
        for (Publication publication : event.getPublications()) {
            publicationIds.add(v(publication.getChannel()));
        }
    }
    fields.add(f("publication_status", arr(publicationIds)));
    fields.add(f("processing_state", v(event.getWorkflowState(), BLANK)));
    fields.add(f("start", v(event.getTechnicalStartTime(), BLANK)));
    if (event.getTechnicalEndTime() != null) {
        long duration = new DateTime(event.getTechnicalEndTime()).getMillis() - new DateTime(event.getTechnicalStartTime()).getMillis();
        fields.add(f("duration", v(duration)));
    }
    if (StringUtils.trimToNull(event.getSubject()) != null) {
        fields.add(f("subjects", arr(splitSubjectIntoArray(event.getSubject()))));
    } else {
        fields.add(f("subjects", arr()));
    }
    fields.add(f("title", v(event.getTitle(), BLANK)));
    if (withAcl != null && withAcl) {
        AccessControlList acl = getAclFromEvent(event);
        fields.add(f("acl", arr(AclUtils.serializeAclToJson(acl))));
    }
    if (withMetadata != null && withMetadata) {
        try {
            Opt<MetadataList> metadata = getEventMetadata(event);
            if (metadata.isSome()) {
                fields.add(f("metadata", metadata.get().toJSON()));
            }
        } catch (Exception e) {
            logger.error("Unable to get metadata for event '{}' because: {}", event.getIdentifier(), ExceptionUtils.getStackTrace(e));
            throw new IndexServiceException("Unable to add metadata to event", e);
        }
    }
    if (withPublications != null && withPublications) {
        List<JValue> publications = getPublications(event, withSignedUrls);
        fields.add(f("publications", arr(publications)));
    }
    return obj(fields);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ArrayList(java.util.ArrayList) Publication(org.opencastproject.mediapackage.Publication) DateTime(org.joda.time.DateTime) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) IngestException(org.opencastproject.ingest.api.IngestException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) ConfigurationException(org.osgi.service.cm.ConfigurationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UrlSigningException(org.opencastproject.security.urlsigning.exception.UrlSigningException) ParseException(org.json.simple.parser.ParseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) Field(com.entwinemedia.fn.data.json.Field) MetadataField(org.opencastproject.metadata.dublincore.MetadataField) JValue(com.entwinemedia.fn.data.json.JValue) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 12 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class EventsEndpoint method updateEvent.

private Response updateEvent(String eventId, HttpServletRequest request) {
    try {
        Opt<String> startDatePattern = configuredMetadataFields.containsKey("startDate") ? configuredMetadataFields.get("startDate").getPattern() : Opt.none();
        Opt<String> startTimePattern = configuredMetadataFields.containsKey("startTime") ? configuredMetadataFields.get("startTime").getPattern() : Opt.none();
        for (final Event event : indexService.getEvent(eventId, externalIndex)) {
            EventHttpServletRequest eventHttpServletRequest = EventHttpServletRequest.updateFromHttpServletRequest(event, request, getEventCatalogUIAdapters(), startDatePattern, startTimePattern);
            if (eventHttpServletRequest.getMetadataList().isSome()) {
                indexService.updateEventMetadata(eventId, eventHttpServletRequest.getMetadataList().get(), externalIndex);
            }
            if (eventHttpServletRequest.getAcl().isSome()) {
                indexService.updateEventAcl(eventId, eventHttpServletRequest.getAcl().get(), externalIndex);
            }
            return ApiResponses.Json.noContent(ApiVersion.VERSION_1_0_0);
        }
        return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
    } catch (NotFoundException e) {
        return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
    } catch (UnauthorizedException e) {
        return Response.status(Status.UNAUTHORIZED).build();
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
        return RestUtil.R.badRequest(e.getMessage());
    } catch (IndexServiceException e) {
        logger.error("Unable to get multi part fields or file for event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    } catch (SearchIndexException e) {
        logger.error("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : EventHttpServletRequest(org.opencastproject.index.service.impl.index.event.EventHttpServletRequest) WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 13 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class AbstractSearchIndex method recreateService.

/**
 * Ask for data to be rebuilt from a service.
 *
 * @param service
 *          The {@link IndexRecreateObject.Service} representing the service to start re-sending the data from.
 * @throws IndexServiceException
 *           Thrown if there is a problem re-sending the data from the service.
 * @throws InterruptedException
 *           Thrown if the process of re-sending the data is interupted.
 * @throws CancellationException
 *           Thrown if listening to messages has been canceled.
 * @throws ExecutionException
 *           Thrown if the process of re-sending the data has an error.
 */
private void recreateService(IndexRecreateObject.Service service) throws IndexServiceException, InterruptedException, CancellationException, ExecutionException {
    logger.info("Starting to recreate index for service '{}'", service);
    messageSender.sendObjectMessage(IndexProducer.RECEIVER_QUEUE + "." + service, MessageSender.DestinationType.Queue, IndexRecreateObject.start(getIndexName(), service));
    boolean done = false;
    // TODO Add a timeout for services that are not going to respond.
    while (!done) {
        FutureTask<Serializable> future = messageReceiver.receiveSerializable(IndexProducer.RESPONSE_QUEUE, MessageSender.DestinationType.Queue);
        executor.execute(future);
        BaseMessage message = (BaseMessage) future.get();
        if (message.getObject() instanceof IndexRecreateObject) {
            IndexRecreateObject indexRecreateObject = (IndexRecreateObject) message.getObject();
            switch(indexRecreateObject.getStatus()) {
                case Update:
                    logger.info("Updating service: '{}' with {}/{} finished, {}% complete.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal(), (int) (indexRecreateObject.getCurrent() * 100 / indexRecreateObject.getTotal()));
                    if (indexRecreateObject.getCurrent() == indexRecreateObject.getTotal()) {
                        logger.info("Waiting for service '{}' indexing to complete", indexRecreateObject.getService());
                    }
                    break;
                case End:
                    done = true;
                    logger.info("Finished re-creating data for service '{}'", indexRecreateObject.getService());
                    break;
                case Error:
                    logger.error("Error updating service '{}' with {}/{} finished.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal());
                    throw new IndexServiceException(format("Error updating service '%s' with %s/%s finished.", indexRecreateObject.getService(), indexRecreateObject.getCurrent(), indexRecreateObject.getTotal()));
                default:
                    logger.error("Unable to handle the status '{}' for service '{}'", indexRecreateObject.getStatus(), indexRecreateObject.getService());
                    throw new IllegalArgumentException(format("Unable to handle the status '%s' for service '%s'", indexRecreateObject.getStatus(), indexRecreateObject.getService()));
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) BaseMessage(org.opencastproject.message.broker.api.BaseMessage) IndexRecreateObject(org.opencastproject.message.broker.api.index.IndexRecreateObject) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 14 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class IndexServiceImpl method updateCommonEventMetadata.

@Override
public MetadataList updateCommonEventMetadata(String id, String metadataJSON, AbstractSearchIndex index) throws IllegalArgumentException, IndexServiceException, SearchIndexException, NotFoundException, UnauthorizedException {
    MetadataList metadataList;
    try {
        metadataList = getMetadataListWithCommonEventCatalogUIAdapter();
        metadataList.fromJSON(metadataJSON);
    } catch (Exception e) {
        logger.warn("Not able to parse the event metadata {}: {}", metadataJSON, getStackTrace(e));
        throw new IllegalArgumentException("Not able to parse the event metadata " + metadataJSON, e);
    }
    return updateEventMetadata(id, metadataList, index);
}
Also used : MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) IngestException(org.opencastproject.ingest.api.IngestException) WebApplicationException(javax.ws.rs.WebApplicationException) MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) EventCommentException(org.opencastproject.event.comment.EventCommentException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException)

Example 15 with IndexServiceException

use of org.opencastproject.index.service.exception.IndexServiceException in project opencast by opencast.

the class IndexServiceImpl method getCurrentWorkflowInstance.

@Override
public Opt<WorkflowInstance> getCurrentWorkflowInstance(String mpId) throws IndexServiceException {
    WorkflowQuery query = new WorkflowQuery().withMediaPackage(mpId);
    WorkflowSet workflowInstances;
    try {
        workflowInstances = workflowService.getWorkflowInstances(query);
        if (workflowInstances.size() == 0) {
            logger.info("No workflow instance found for mediapackage {}.", mpId);
            return Opt.none();
        }
    } catch (WorkflowDatabaseException e) {
        logger.error("Unable to get workflows for event {} because {}", mpId, getStackTrace(e));
        throw new IndexServiceException("Unable to get current workflow for event " + mpId);
    }
    // Get the newest workflow instance
    // TODO This presuppose knowledge of the Database implementation and should be fixed sooner or later!
    WorkflowInstance workflowInstance = workflowInstances.getItems()[0];
    for (WorkflowInstance instance : workflowInstances.getItems()) {
        if (instance.getId() > workflowInstance.getId())
            workflowInstance = instance;
    }
    return Opt.some(workflowInstance);
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Aggregations

IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)21 NotFoundException (org.opencastproject.util.NotFoundException)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 IOException (java.io.IOException)11 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)11 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)11 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)11 AssetManagerException (org.opencastproject.assetmanager.api.AssetManagerException)9 IngestException (org.opencastproject.ingest.api.IngestException)9 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)9 WorkflowException (org.opencastproject.workflow.api.WorkflowException)9 ParseException (java.text.ParseException)8 JSONException (org.codehaus.jettison.json.JSONException)8 EventCommentException (org.opencastproject.event.comment.EventCommentException)8 MediaPackage (org.opencastproject.mediapackage.MediaPackage)8 MetadataParsingException (org.opencastproject.metadata.dublincore.MetadataParsingException)7 SeriesException (org.opencastproject.series.api.SeriesException)7 JSONObject (org.json.simple.JSONObject)6 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)6