Search in sources :

Example 31 with SearchIndexException

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));
    }
}
Also used : Group(org.opencastproject.index.service.impl.index.group.Group) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) NotFoundException(org.opencastproject.util.NotFoundException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 32 with SearchIndexException

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);
    }
}
Also used : SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) EventQueryBuilder(org.opencastproject.index.service.impl.index.event.EventQueryBuilder) Event(org.opencastproject.index.service.impl.index.event.Event) IOException(java.io.IOException)

Example 33 with SearchIndexException

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);
    }
}
Also used : Series(org.opencastproject.index.service.impl.index.series.Series) SeriesQueryBuilder(org.opencastproject.index.service.impl.index.series.SeriesQueryBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) IOException(java.io.IOException)

Example 34 with SearchIndexException

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);
    }
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SearchMetadata(org.opencastproject.matterhorn.search.SearchMetadata) ElasticsearchDocument(org.opencastproject.matterhorn.search.impl.ElasticsearchDocument)

Example 35 with SearchIndexException

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);
    }
}
Also used : SearchMetadataCollection(org.opencastproject.matterhorn.search.impl.SearchMetadataCollection) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SearchMetadata(org.opencastproject.matterhorn.search.SearchMetadata) ElasticsearchDocument(org.opencastproject.matterhorn.search.impl.ElasticsearchDocument)

Aggregations

SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)43 NotFoundException (org.opencastproject.util.NotFoundException)18 WebApplicationException (javax.ws.rs.WebApplicationException)15 Path (javax.ws.rs.Path)14 RestQuery (org.opencastproject.util.doc.rest.RestQuery)14 Event (org.opencastproject.index.service.impl.index.event.Event)11 IOException (java.io.IOException)10 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)10 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)10 SearchMetadataCollection (org.opencastproject.matterhorn.search.impl.SearchMetadataCollection)9 Produces (javax.ws.rs.Produces)8 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)8 User (org.opencastproject.security.api.User)8 GET (javax.ws.rs.GET)7 ParseException (java.text.ParseException)6 ArrayList (java.util.ArrayList)6 JSONException (org.codehaus.jettison.json.JSONException)6 EventCommentException (org.opencastproject.event.comment.EventCommentException)6 Series (org.opencastproject.index.service.impl.index.series.Series)6 Theme (org.opencastproject.index.service.impl.index.theme.Theme)6