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);
}
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);
}
}
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()));
}
}
}
}
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);
}
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);
}
Aggregations