use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class AbstractSearchIndex method executeQuery.
/**
* Execute a query on the index.
*
* @param query
* The query to use to find the results
* @param requestBuilder
* The builder to use to create the query.
* @param toSearchResult
* The function to convert the results to a {@link SearchResult}
* @return A {@link SearchResult} containing the relevant objects.
* @throws SearchIndexException
*/
protected <T> SearchResult<T> executeQuery(SearchQuery query, SearchRequestBuilder requestBuilder, Fn<SearchMetadataCollection, T> toSearchResult) throws SearchIndexException {
// Execute the query and try to get hold of a query response
SearchResponse response = null;
try {
response = getSearchClient().search(requestBuilder.request()).actionGet();
} catch (Throwable t) {
throw new SearchIndexException(t);
}
// Create and configure the query result
long hits = response.getHits().getTotalHits();
long size = response.getHits().getHits().length;
SearchResultImpl<T> result = new SearchResultImpl<>(query, hits, size);
result.setSearchTime(response.getTookInMillis());
// Walk through response and create new items with title, creator, etc:
for (SearchHit doc : response.getHits()) {
// Wrap the search resulting metadata
SearchMetadataCollection metadata = new SearchMetadataCollection(doc.getType());
metadata.setIdentifier(doc.getId());
for (SearchHitField field : doc.getFields().values()) {
String name = field.getName();
SearchMetadata<Object> m = new SearchMetadataImpl<>(name);
// Add the field values
if (field.getValues().size() > 1) {
for (Object v : field.getValues()) {
m.addValue(v);
}
} else {
m.addValue(field.getValue());
}
// Add the metadata
metadata.add(m);
}
// Get the score for this item
float score = doc.getScore();
// item
try {
T document = toSearchResult.apply(metadata);
SearchResultItem<T> item = new SearchResultItemImpl<>(score, document);
result.addResultItem(item);
} catch (Throwable t) {
logger.warn("Error during search result serialization: '{}'. Skipping this search result.", t.getMessage());
size--;
continue;
}
}
// Set the number of resulting documents
result.setDocumentCount(size);
return result;
}
use of org.opencastproject.matterhorn.search.SearchIndexException 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.matterhorn.search.SearchIndexException in project opencast by opencast.
the class SeriesMessageReceiverImpl method execute.
@Override
protected void execute(SeriesItem seriesItem) {
Series series = null;
String organization = getSecurityService().getOrganization().getId();
User user = getSecurityService().getUser();
switch(seriesItem.getType()) {
case UpdateCatalog:
logger.debug("Received Update Series for index {}", getSearchIndex().getIndexName());
DublinCoreCatalog dc = seriesItem.getMetadata();
String seriesId = dc.getFirst(DublinCoreCatalog.PROPERTY_IDENTIFIER);
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesId, organization, user, getSearchIndex());
series.setCreator(getSecurityService().getUser().getName());
SeriesIndexUtils.updateSeries(series, dc);
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesId, ExceptionUtils.getStackTrace(e));
return;
}
// Update the event series titles if they changed
try {
SeriesIndexUtils.updateEventSeriesTitles(series, organization, getSecurityService().getUser(), getSearchIndex());
} catch (SearchIndexException e) {
logger.error("Error updating the series name of series {} from the associated events: {}", series.getIdentifier(), ExceptionUtils.getStackTrace(e));
}
// Persist the series
update(seriesItem.getSeriesId(), series);
break;
case UpdateAcl:
logger.debug("Received Update Series ACL for index {}", getSearchIndex().getIndexName());
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesItem.getSeriesId(), organization, user, getSearchIndex());
List<ManagedAcl> acls = aclServiceFactory.serviceFor(getSecurityService().getOrganization()).getAcls();
Option<ManagedAcl> managedAcl = AccessInformationUtil.matchAcls(acls, seriesItem.getAcl());
if (managedAcl.isSome())
series.setManagedAcl(managedAcl.get().getName());
series.setAccessPolicy(AccessControlParser.toJsonSilent(seriesItem.getAcl()));
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
// Persist the updated series
update(seriesItem.getSeriesId(), series);
break;
case UpdateOptOut:
logger.debug("Received update opt out status of series {} for index {}", seriesItem.getSeriesId(), getSearchIndex().getIndexName());
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesItem.getSeriesId(), organization, user, getSearchIndex());
series.setOptOut(seriesItem.getOptOut());
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
// Persist the updated series
update(seriesItem.getSeriesId(), series);
break;
case UpdateProperty:
logger.debug("Received update property of series {} for index {}", seriesItem.getSeriesId(), getSearchIndex().getIndexName());
if (!THEME_PROPERTY_NAME.equals(seriesItem.getPropertyName()))
break;
// Load or create the corresponding series
try {
series = SeriesIndexUtils.getOrCreate(seriesItem.getSeriesId(), organization, user, getSearchIndex());
series.setTheme(Opt.nul(seriesItem.getPropertyValue()).bind(Strings.toLong).orNull());
} catch (SearchIndexException e) {
logger.error("Error retrieving series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
// Persist the updated series
update(seriesItem.getSeriesId(), series);
break;
case Delete:
logger.debug("Received Delete Series Event {} for index {}", seriesItem.getSeriesId(), getSearchIndex().getIndexName());
// Remove the series from the search index
try {
getSearchIndex().delete(Series.DOCUMENT_TYPE, seriesItem.getSeriesId().concat(organization));
logger.debug("Series {} removed from search index", seriesItem.getSeriesId());
} catch (SearchIndexException e) {
logger.error("Error deleting the series {} from the search index: {}", seriesItem.getSeriesId(), ExceptionUtils.getStackTrace(e));
return;
}
return;
case UpdateElement:
// nothing to do
break;
default:
throw new IllegalArgumentException("Unhandled type of SeriesItem");
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class WorkflowMessageReceiverImpl method execute.
@Override
protected void execute(WorkflowItem workflowItem) {
String organization = getSecurityService().getOrganization().getId();
User user = getSecurityService().getUser();
String eventId = null;
switch(workflowItem.getType()) {
case UpdateInstance:
logger.debug("Received Update Workflow instance Entry for index {}", getSearchIndex().getIndexName());
WorkflowInstance wf = workflowItem.getWorkflowInstance();
MediaPackage mp = wf.getMediaPackage();
eventId = mp.getIdentifier().toString();
// Load or create the corresponding recording event
Event event = null;
try {
event = getOrCreateEvent(eventId, organization, user, getSearchIndex());
event.setCreator(getSecurityService().getUser().getName());
event.setWorkflowId(wf.getId());
event.setWorkflowDefinitionId(wf.getTemplate());
event.setWorkflowState(wf.getState());
WorkflowInstance.WorkflowState state = wf.getState();
if (!(WorkflowInstance.WorkflowState.SUCCEEDED.equals(state) || WorkflowInstance.WorkflowState.FAILED.equals(state) || WorkflowInstance.WorkflowState.STOPPED.equals(state))) {
Tuple<AccessControlList, AclScope> activeAcl = authorizationService.getActiveAcl(mp);
List<ManagedAcl> acls = aclServiceFactory.serviceFor(getSecurityService().getOrganization()).getAcls();
Option<ManagedAcl> managedAcl = AccessInformationUtil.matchAcls(acls, activeAcl.getA());
if (managedAcl.isSome()) {
event.setManagedAcl(managedAcl.get().getName());
}
event.setAccessPolicy(AccessControlParser.toJsonSilent(activeAcl.getA()));
try {
Opt<DublinCoreCatalog> loadedDC = DublinCoreUtil.loadEpisodeDublinCore(workspace, mp);
if (loadedDC.isSome())
updateEvent(event, loadedDC.get());
} catch (Throwable t) {
logger.warn("Unable to load dublincore catalog for the workflow {}", wf.getId(), t);
}
}
updateEvent(event, mp);
} 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("Workflow instance {} updated in the search index", event.getIdentifier());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
return;
}
return;
case DeleteInstance:
logger.debug("Received Delete Workflow instance Entry {}", eventId);
eventId = workflowItem.getWorkflowInstance().getMediaPackage().getIdentifier().toString();
// Remove the Workflow instance entry from the search index
try {
getSearchIndex().deleteWorkflow(organization, user, eventId, workflowItem.getWorkflowInstanceId());
logger.debug("Workflow instance mediapackage {} removed from search index", eventId);
} catch (NotFoundException e) {
logger.warn("Workflow instance mediapackage {} not found for deletion", eventId);
} catch (SearchIndexException e) {
logger.error("Error deleting the Workflow instance entry {} from the search index: {}", eventId, ExceptionUtils.getStackTrace(e));
}
return;
case AddDefinition:
// TODO: Update the index with it as soon as the definition are part of it
return;
case DeleteDefinition:
// TODO: Update the index with it as soon as the definition are part of it
return;
default:
throw new IllegalArgumentException("Unhandled type of WorkflowItem");
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class ThemesListProvider method getList.
@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
Map<String, String> list = new HashMap<String, String>();
if (NAME.equals(listName)) {
ThemeSearchQuery themeQuery = new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
themeQuery.withOffset(query.getOffset().getOrElse(0));
int limit = query.getLimit().getOrElse(Integer.MAX_VALUE - themeQuery.getOffset());
themeQuery.withLimit(limit);
themeQuery.sortByName(SearchQuery.Order.Ascending);
SearchResult<Theme> results = null;
try {
results = searchIndex.getByQuery(themeQuery);
} catch (SearchIndexException e) {
logger.error("The admin UI Search Index was not able to get the themes: {}", ExceptionUtils.getStackTrace(e));
throw new ListProviderException("No themes list for list name " + listName + " found!");
}
for (SearchResultItem<Theme> item : results.getItems()) {
Theme theme = item.getSource();
list.put(Long.toString(theme.getIdentifier()), theme.getName());
}
} else if (DESCRIPTION.equals(listName)) {
ThemeSearchQuery themeQuery = new ThemeSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
themeQuery.withOffset(query.getOffset().getOrElse(0));
int limit = query.getLimit().getOrElse(Integer.MAX_VALUE - themeQuery.getOffset());
themeQuery.withLimit(limit);
themeQuery.sortByName(SearchQuery.Order.Ascending);
SearchResult<Theme> results = null;
try {
results = searchIndex.getByQuery(themeQuery);
} catch (SearchIndexException e) {
logger.error("The admin UI Search Index was not able to get the themes: {}", ExceptionUtils.getStackTrace(e));
throw new ListProviderException("No themes list for list name " + listName + " found!");
}
for (SearchResultItem<Theme> item : results.getItems()) {
Theme theme = item.getSource();
if (theme.getDescription() == null) {
theme.setDescription("");
} else {
theme.getDescription();
}
list.put(Long.toString(theme.getIdentifier()), theme.getDescription());
}
}
return list;
}
Aggregations