@Test public void testExecuteWithGroupList() { final LinkedHashSet<Long> groupIds = new LinkedHashSet<Long>(2); groupIds.add(5L); groupIds.add(6L); final String searchString = "+(name:(foo\\-foo* foo\\-foo) lastName:(foo\\-foo* foo\\-foo) " + "preferredName:(foo\\-foo* foo\\-foo)^0.5) +isStreamPostable:true " + "+(isPublic:true ( +id:(5 6 ) -isPublic:true))"; context.checking(new Expectations() { { oneOf(request).getPrefix(); will(returnValue("foo-foo")); oneOf(request).getUserKey(); will(returnValue(userKey)); oneOf(getPersonIdByAccountIdMapper).execute(userKey); will(returnValue(userId)); oneOf(getGroupIdsMapper).execute(userId); will(returnValue(groupIds)); oneOf(searchRequestBuilder).buildQueryFromNativeSearchString(searchString); will(returnValue(query)); oneOf(searchRequestBuilder).setPaging(query, 0, 9); oneOf(query).getResultList(); will(returnValue(searchResults)); allowing(personView).getAccountId(); oneOf(personView).getDisplayName(); oneOf(personView).getStreamId(); allowing(groupView).getShortName(); oneOf(groupView).getName(); oneOf(groupView).getStreamId(); allowing(personView).isAccountLocked(); } }); assertEquals(2, sut.execute(request).size()); context.assertIsSatisfied(); }
@Override public List<DisplayEntityModelView> execute(final GetEntitiesByPrefixRequest inRequest) { String term = escapeSearchTerm(inRequest.getPrefix()); String excludeReadOnlyClause = excludeReadOnlyStreams ? "+isStreamPostable:true" : ""; String searchText = String.format("+(name:(%1$s* %1$s) lastName:(%1$s* %1$s) preferredName:(%1$s* %1$s)^0.5) " + "%2$s %3$s", term, excludeReadOnlyClause, getGroupVisibilityClause(inRequest)); if (log.isTraceEnabled()) { log.trace("Searching for " + maxResults + " people and groups with Lucene query: " + searchText); } FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(searchText); searchRequestBuilder.setPaging(query, 0, maxResults); List<ModelView> searchResults = query.getResultList(); if (log.isTraceEnabled()) { log.trace("Found " + searchResults.size() + " search results"); } List<DisplayEntityModelView> displayModelViews = new ArrayList<DisplayEntityModelView>(); for (ModelView modelView : searchResults) { DisplayEntityModelView displayModelView = new DisplayEntityModelView(); if (modelView instanceof PersonModelView) { PersonModelView person = (PersonModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found person '" + person.getAccountId() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(person.getDisplayName()); displayModelView.setStreamScopeId(person.getStreamId()); displayModelView.setType(EntityType.PERSON); displayModelView.setUniqueKey(person.getAccountId()); displayModelView.setAccountLocked(person.isAccountLocked()); displayModelViews.add(displayModelView); } else if (modelView instanceof DomainGroupModelView) { DomainGroupModelView group = (DomainGroupModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found domain group '" + group.getShortName() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(group.getName()); displayModelView.setStreamScopeId(group.getStreamId()); displayModelView.setType(EntityType.GROUP); displayModelView.setUniqueKey(group.getShortName()); displayModelViews.add(displayModelView); } } return displayModelViews; }
SearchPeopleAndGroupsByPrefix extends ReadMapper<GetEntitiesByPrefixRequest, List<DisplayEntityModelView>> { @Override public List<DisplayEntityModelView> execute(final GetEntitiesByPrefixRequest inRequest) { String term = escapeSearchTerm(inRequest.getPrefix()); String excludeReadOnlyClause = excludeReadOnlyStreams ? "+isStreamPostable:true" : ""; String searchText = String.format("+(name:(%1$s* %1$s) lastName:(%1$s* %1$s) preferredName:(%1$s* %1$s)^0.5) " + "%2$s %3$s", term, excludeReadOnlyClause, getGroupVisibilityClause(inRequest)); if (log.isTraceEnabled()) { log.trace("Searching for " + maxResults + " people and groups with Lucene query: " + searchText); } FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(searchText); searchRequestBuilder.setPaging(query, 0, maxResults); List<ModelView> searchResults = query.getResultList(); if (log.isTraceEnabled()) { log.trace("Found " + searchResults.size() + " search results"); } List<DisplayEntityModelView> displayModelViews = new ArrayList<DisplayEntityModelView>(); for (ModelView modelView : searchResults) { DisplayEntityModelView displayModelView = new DisplayEntityModelView(); if (modelView instanceof PersonModelView) { PersonModelView person = (PersonModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found person '" + person.getAccountId() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(person.getDisplayName()); displayModelView.setStreamScopeId(person.getStreamId()); displayModelView.setType(EntityType.PERSON); displayModelView.setUniqueKey(person.getAccountId()); displayModelView.setAccountLocked(person.isAccountLocked()); displayModelViews.add(displayModelView); } else if (modelView instanceof DomainGroupModelView) { DomainGroupModelView group = (DomainGroupModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found domain group '" + group.getShortName() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(group.getName()); displayModelView.setStreamScopeId(group.getStreamId()); displayModelView.setType(EntityType.GROUP); displayModelView.setUniqueKey(group.getShortName()); displayModelViews.add(displayModelView); } } return displayModelViews; } }
SearchPeopleAndGroupsByPrefix extends ReadMapper<GetEntitiesByPrefixRequest, List<DisplayEntityModelView>> { @Override public List<DisplayEntityModelView> execute(final GetEntitiesByPrefixRequest inRequest) { String term = escapeSearchTerm(inRequest.getPrefix()); String excludeReadOnlyClause = excludeReadOnlyStreams ? "+isStreamPostable:true" : ""; String searchText = String.format("+(name:(%1$s* %1$s) lastName:(%1$s* %1$s) preferredName:(%1$s* %1$s)^0.5) " + "%2$s %3$s", term, excludeReadOnlyClause, getGroupVisibilityClause(inRequest)); if (log.isTraceEnabled()) { log.trace("Searching for " + maxResults + " people and groups with Lucene query: " + searchText); } FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(searchText); searchRequestBuilder.setPaging(query, 0, maxResults); List<ModelView> searchResults = query.getResultList(); if (log.isTraceEnabled()) { log.trace("Found " + searchResults.size() + " search results"); } List<DisplayEntityModelView> displayModelViews = new ArrayList<DisplayEntityModelView>(); for (ModelView modelView : searchResults) { DisplayEntityModelView displayModelView = new DisplayEntityModelView(); if (modelView instanceof PersonModelView) { PersonModelView person = (PersonModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found person '" + person.getAccountId() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(person.getDisplayName()); displayModelView.setStreamScopeId(person.getStreamId()); displayModelView.setType(EntityType.PERSON); displayModelView.setUniqueKey(person.getAccountId()); displayModelView.setAccountLocked(person.isAccountLocked()); displayModelViews.add(displayModelView); } else if (modelView instanceof DomainGroupModelView) { DomainGroupModelView group = (DomainGroupModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found domain group '" + group.getShortName() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(group.getName()); displayModelView.setStreamScopeId(group.getStreamId()); displayModelView.setType(EntityType.GROUP); displayModelView.setUniqueKey(group.getShortName()); displayModelViews.add(displayModelView); } } return displayModelViews; } SearchPeopleAndGroupsByPrefix(final Integer inMaxResults,
            final ProjectionSearchRequestBuilder inSearchRequestBuilder,
            final GetPrivateCoordinatedAndFollowedGroupIdsForUser inGetGroupIdsMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper, final boolean inExcludeReadOnlyStreams); }
SearchPeopleAndGroupsByPrefix extends ReadMapper<GetEntitiesByPrefixRequest, List<DisplayEntityModelView>> { @Override public List<DisplayEntityModelView> execute(final GetEntitiesByPrefixRequest inRequest) { String term = escapeSearchTerm(inRequest.getPrefix()); String excludeReadOnlyClause = excludeReadOnlyStreams ? "+isStreamPostable:true" : ""; String searchText = String.format("+(name:(%1$s* %1$s) lastName:(%1$s* %1$s) preferredName:(%1$s* %1$s)^0.5) " + "%2$s %3$s", term, excludeReadOnlyClause, getGroupVisibilityClause(inRequest)); if (log.isTraceEnabled()) { log.trace("Searching for " + maxResults + " people and groups with Lucene query: " + searchText); } FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(searchText); searchRequestBuilder.setPaging(query, 0, maxResults); List<ModelView> searchResults = query.getResultList(); if (log.isTraceEnabled()) { log.trace("Found " + searchResults.size() + " search results"); } List<DisplayEntityModelView> displayModelViews = new ArrayList<DisplayEntityModelView>(); for (ModelView modelView : searchResults) { DisplayEntityModelView displayModelView = new DisplayEntityModelView(); if (modelView instanceof PersonModelView) { PersonModelView person = (PersonModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found person '" + person.getAccountId() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(person.getDisplayName()); displayModelView.setStreamScopeId(person.getStreamId()); displayModelView.setType(EntityType.PERSON); displayModelView.setUniqueKey(person.getAccountId()); displayModelView.setAccountLocked(person.isAccountLocked()); displayModelViews.add(displayModelView); } else if (modelView instanceof DomainGroupModelView) { DomainGroupModelView group = (DomainGroupModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found domain group '" + group.getShortName() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(group.getName()); displayModelView.setStreamScopeId(group.getStreamId()); displayModelView.setType(EntityType.GROUP); displayModelView.setUniqueKey(group.getShortName()); displayModelViews.add(displayModelView); } } return displayModelViews; } SearchPeopleAndGroupsByPrefix(final Integer inMaxResults,
            final ProjectionSearchRequestBuilder inSearchRequestBuilder,
            final GetPrivateCoordinatedAndFollowedGroupIdsForUser inGetGroupIdsMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper, final boolean inExcludeReadOnlyStreams); @Override List<DisplayEntityModelView> execute(final GetEntitiesByPrefixRequest inRequest); }
SearchPeopleAndGroupsByPrefix extends ReadMapper<GetEntitiesByPrefixRequest, List<DisplayEntityModelView>> { @Override public List<DisplayEntityModelView> execute(final GetEntitiesByPrefixRequest inRequest) { String term = escapeSearchTerm(inRequest.getPrefix()); String excludeReadOnlyClause = excludeReadOnlyStreams ? "+isStreamPostable:true" : ""; String searchText = String.format("+(name:(%1$s* %1$s) lastName:(%1$s* %1$s) preferredName:(%1$s* %1$s)^0.5) " + "%2$s %3$s", term, excludeReadOnlyClause, getGroupVisibilityClause(inRequest)); if (log.isTraceEnabled()) { log.trace("Searching for " + maxResults + " people and groups with Lucene query: " + searchText); } FullTextQuery query = searchRequestBuilder.buildQueryFromNativeSearchString(searchText); searchRequestBuilder.setPaging(query, 0, maxResults); List<ModelView> searchResults = query.getResultList(); if (log.isTraceEnabled()) { log.trace("Found " + searchResults.size() + " search results"); } List<DisplayEntityModelView> displayModelViews = new ArrayList<DisplayEntityModelView>(); for (ModelView modelView : searchResults) { DisplayEntityModelView displayModelView = new DisplayEntityModelView(); if (modelView instanceof PersonModelView) { PersonModelView person = (PersonModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found person '" + person.getAccountId() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(person.getDisplayName()); displayModelView.setStreamScopeId(person.getStreamId()); displayModelView.setType(EntityType.PERSON); displayModelView.setUniqueKey(person.getAccountId()); displayModelView.setAccountLocked(person.isAccountLocked()); displayModelViews.add(displayModelView); } else if (modelView instanceof DomainGroupModelView) { DomainGroupModelView group = (DomainGroupModelView) modelView; if (log.isTraceEnabled()) { log.trace("Found domain group '" + group.getShortName() + " with search prefix '" + searchText + "'"); } displayModelView.setDisplayName(group.getName()); displayModelView.setStreamScopeId(group.getStreamId()); displayModelView.setType(EntityType.GROUP); displayModelView.setUniqueKey(group.getShortName()); displayModelViews.add(displayModelView); } } return displayModelViews; } SearchPeopleAndGroupsByPrefix(final Integer inMaxResults,
            final ProjectionSearchRequestBuilder inSearchRequestBuilder,
            final GetPrivateCoordinatedAndFollowedGroupIdsForUser inGetGroupIdsMapper,
            final DomainMapper<String, Long> inGetPersonIdByAccountIdMapper, final boolean inExcludeReadOnlyStreams); @Override List<DisplayEntityModelView> execute(final GetEntitiesByPrefixRequest inRequest);  }