Search in sources :

Example 6 with Group

use of org.opencastproject.index.service.impl.index.group.Group 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)

Aggregations

Group (org.opencastproject.index.service.impl.index.group.Group)6 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)5 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 NotFoundException (org.opencastproject.util.NotFoundException)3 GET (javax.ws.rs.GET)2 Field (com.entwinemedia.fn.data.json.Field)1 JValue (com.entwinemedia.fn.data.json.JValue)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 GroupQueryBuilder (org.opencastproject.index.service.impl.index.group.GroupQueryBuilder)1 GroupSearchQuery (org.opencastproject.index.service.impl.index.group.GroupSearchQuery)1 SortCriterion (org.opencastproject.matterhorn.search.SortCriterion)1 SearchMetadataCollection (org.opencastproject.matterhorn.search.impl.SearchMetadataCollection)1