use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class GroupsEndpoint method removeGroupMember.
@DELETE
@Path("{groupId}/members/{memberId}")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "removegroupmember", description = "Removes a member from a group", returnDescription = "", pathParameters = { @RestParameter(name = "groupId", description = "The group id", isRequired = true, type = STRING), @RestParameter(name = "memberId", description = "The member id", isRequired = true, type = STRING) }, reponses = { @RestResponse(description = "The member has been removed.", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "The specified group or member does not exist.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response removeGroupMember(@HeaderParam("Accept") String acceptHeader, @PathParam("groupId") String id, @PathParam("memberId") String memberId) {
try {
Opt<Group> groupOpt = indexService.getGroup(id, externalIndex);
if (groupOpt.isSome()) {
Group group = groupOpt.get();
Set<String> members = group.getMembers();
if (members.contains(memberId)) {
members.remove(memberId);
group.setMembers(members);
return indexService.updateGroup(group.getIdentifier(), group.getName(), group.getDescription(), StringUtils.join(group.getRoles(), ","), StringUtils.join(group.getMembers(), ","));
} else {
return ApiResponses.notFound("Cannot find member '%s' in group '%s'.", memberId, id);
}
} else {
return ApiResponses.notFound("Cannot find group with id '%s'.", id);
}
} catch (SearchIndexException e) {
logger.warn("The external search index was not able to retrieve the group with id {}, ", getStackTrace(e));
return ApiResponses.serverError("Could not retrieve groups, reason: '%s'", getMessage(e));
} catch (NotFoundException e) {
logger.warn("The external search index was not able to update the group with id {}, ", getStackTrace(e));
return ApiResponses.serverError("Could not update group with id '%s', reason: '%s'", id, getMessage(e));
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class AbstractSearchIndex method getByQuery.
/**
* @param query
* The query to use to retrieve the events that match the query
* @return {@link SearchResult} collection of {@link Event} from a query.
* @throws SearchIndexException
* Thrown if there is an error getting the results.
*/
public SearchResult<Event> getByQuery(EventSearchQuery query) throws SearchIndexException {
logger.debug("Searching index using event query '{}'", query);
// Create the request builder
SearchRequestBuilder requestBuilder = getSearchRequestBuilder(query, new EventQueryBuilder(query));
try {
return executeQuery(query, requestBuilder, new Fn<SearchMetadataCollection, Event>() {
@Override
public Event apply(SearchMetadataCollection metadata) {
try {
return EventIndexUtils.toRecordingEvent(metadata);
} catch (IOException e) {
return chuck(e);
}
}
});
} catch (Throwable t) {
throw new SearchIndexException("Error querying event index", t);
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class AbstractSearchIndex method getByQuery.
/**
* @param query
* The query to use to retrieve the series that match the query
* @return {@link SearchResult} collection of {@link Series} from a query.
* @throws SearchIndexException
* Thrown if there is an error getting the results.
*/
public SearchResult<Series> getByQuery(SeriesSearchQuery query) throws SearchIndexException {
logger.debug("Searching index using series query '{}'", query);
// Create the request builder
SearchRequestBuilder requestBuilder = getSearchRequestBuilder(query, new SeriesQueryBuilder(query));
try {
return executeQuery(query, requestBuilder, new Fn<SearchMetadataCollection, Series>() {
@Override
public Series apply(SearchMetadataCollection metadata) {
try {
return SeriesIndexUtils.toSeries(metadata);
} catch (IOException e) {
return chuck(e);
}
}
});
} catch (Throwable t) {
throw new SearchIndexException("Error querying series index", t);
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class AbstractSearchIndex method addOrUpdate.
/**
* Adds the recording event to the search index or updates it accordingly if it is there.
*
* @param event
* the recording event
* @throws SearchIndexException
* if the event cannot be added or updated
*/
public void addOrUpdate(Event event) throws SearchIndexException {
logger.debug("Adding resource {} to search index", event);
// if (!preparedIndices.contains(resource.getURI().getSite().getIdentifier())) {
// try {
// createIndex(resource.getURI().getSite());
// } catch (IOException e) {
// throw new SearchIndexException(e);
// }
// }
// Add the resource to the index
SearchMetadataCollection inputDocument = EventIndexUtils.toSearchMetadata(event);
List<SearchMetadata<?>> resourceMetadata = inputDocument.getMetadata();
ElasticsearchDocument doc = new ElasticsearchDocument(inputDocument.getIdentifier(), inputDocument.getDocumentType(), resourceMetadata);
try {
update(doc);
} catch (Throwable t) {
throw new SearchIndexException("Cannot write resource " + event + " to index", t);
}
}
use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.
the class AbstractSearchIndex method addOrUpdate.
/**
* Adds or updates the group in the search index.
*
* @param group
* The group to add
* @throws SearchIndexException
* Thrown if unable to add or update the group.
*/
public void addOrUpdate(Group group) throws SearchIndexException {
logger.debug("Adding resource {} to search index", group);
// if (!preparedIndices.contains(resource.getURI().getSite().getIdentifier())) {
// try {
// createIndex(resource.getURI().getSite());
// } catch (IOException e) {
// throw new SearchIndexException(e);
// }
// }
// Add the resource to the index
SearchMetadataCollection inputDocument = GroupIndexUtils.toSearchMetadata(group);
List<SearchMetadata<?>> resourceMetadata = inputDocument.getMetadata();
ElasticsearchDocument doc = new ElasticsearchDocument(inputDocument.getIdentifier(), inputDocument.getDocumentType(), resourceMetadata);
try {
update(doc);
} catch (Throwable t) {
throw new SearchIndexException("Cannot write resource " + group + " to index", t);
}
}
Aggregations