Search in sources :

Example 41 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class CommentMessageReceiverImpl method execute.

@Override
protected void execute(CommentItem commentItem) {
    String organization = getSecurityService().getOrganization().getId();
    User user = getSecurityService().getUser();
    switch(commentItem.getType()) {
        case Update:
            logger.debug("Received Comment update for {} search index", getSearchIndex().getIndexName());
            try {
                EventIndexUtils.updateComments(commentItem.getEventId(), commentItem.hasComments(), commentItem.hasOpenComments(), commentItem.needsCutting(), organization, user, getSearchIndex());
                logger.debug("Event {} comment status updated from search index", commentItem.getEventId());
            } catch (SearchIndexException e) {
                logger.error("Error updating comment status of event {} from the search index: {}", commentItem.getEventId(), ExceptionUtils.getStackTrace(e));
            } catch (NotFoundException e) {
                // This is expected if the event's comments have been removed as part of the event's removal
                logger.debug("Event {} not found for comment status updating", commentItem.getEventId());
            }
            return;
        default:
            throw new IllegalArgumentException("Unhandled type of CommentItem");
    }
}
Also used : User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) NotFoundException(org.opencastproject.util.NotFoundException)

Example 42 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class GroupMessageReceiverImpl method execute.

@Override
protected void execute(GroupItem groupItem) {
    String organization = getSecurityService().getOrganization().getId();
    User user = getSecurityService().getUser();
    switch(groupItem.getType()) {
        case Update:
            org.opencastproject.security.api.Group jaxbGroup = groupItem.getGroup();
            logger.debug("Update the group with id '{}', name '{}', description '{}', organization '{}', roles '{}', members '{}'", jaxbGroup.getGroupId(), jaxbGroup.getName(), jaxbGroup.getDescription(), jaxbGroup.getOrganization(), jaxbGroup.getRoles(), jaxbGroup.getMembers());
            try {
                Group group = GroupIndexUtils.getOrCreate(jaxbGroup.getGroupId(), organization, user, getSearchIndex());
                group.setName(jaxbGroup.getName());
                group.setDescription(jaxbGroup.getDescription());
                group.setMembers(jaxbGroup.getMembers());
                Set<String> roles = new HashSet<>();
                for (Role role : jaxbGroup.getRoles()) {
                    roles.add(role.getName());
                }
                group.setRoles(roles);
                getSearchIndex().addOrUpdate(group);
            } catch (SearchIndexException e) {
                logger.error("Error storing the group {} to the search index: {}", jaxbGroup.getGroupId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            break;
        case Delete:
            logger.debug("Received Delete Group Event {}", groupItem.getGroupId());
            // Remove the group from the search index
            try {
                getSearchIndex().delete(Group.DOCUMENT_TYPE, groupItem.getGroupId().concat(organization));
                logger.debug("Group {} removed from external search index", groupItem.getGroupId());
            } catch (SearchIndexException e) {
                logger.error("Error deleting the group {} from the search index: {}", groupItem.getGroupId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            return;
        default:
            throw new IllegalArgumentException("Unhandled type of GroupItem");
    }
}
Also used : Role(org.opencastproject.security.api.Role) Group(org.opencastproject.index.service.impl.index.group.Group) User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) HashSet(java.util.HashSet)

Example 43 with SearchIndexException

use of org.opencastproject.matterhorn.search.SearchIndexException in project opencast by opencast.

the class AbstractElasticsearchIndex method delete.

/**
 * Removes the given document from the specified index.
 *
 * @param type
 *          the document type
 * @param uid
 *          the identifier
 * @return <code>true</code> if the element was found and deleted
 * @throws SearchIndexException
 *           if deletion fails
 */
protected boolean delete(String type, String uid) throws SearchIndexException {
    if (!preparedIndices.contains(index)) {
        try {
            createIndex(index);
        } catch (IOException e) {
            throw new SearchIndexException(e);
        }
    }
    logger.debug("Removing element with id '{}' from searching index", uid);
    DeleteRequestBuilder deleteRequest = nodeClient.prepareDelete(index, type, uid);
    deleteRequest.setRefresh(true);
    DeleteResponse delete = deleteRequest.execute().actionGet();
    if (!delete.isFound()) {
        logger.trace("Document {} to delete was not found", uid);
        return false;
    }
    return true;
}
Also used : DeleteRequestBuilder(org.elasticsearch.action.delete.DeleteRequestBuilder) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) IOException(java.io.IOException)

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