@Test public void getGroupsForUserWithWrongProfile() throws ComponentLookupException, QueryException { Assert.assertTrue(this.mocker.getComponentUnderTest().getGroupsForUser(null).isEmpty()); User u = mock(User.class); Assert.assertTrue(this.mocker.getComponentUnderTest().getGroupsForUser(u).isEmpty()); }
@Override public Set<Group> getGroupsForUser(User user) { if (user == null || user.getProfileDocument() == null) { return Collections.emptySet(); } DocumentReference profile = user.getProfileDocument(); Set<Group> result = new LinkedHashSet<>(); try { Query q = this.qm.createQuery("from doc.object(XWiki.XWikiGroups) grp where grp.member in (:u, :su)", Query.XWQL); q.bindValue("u", profile.toString()); q.bindValue("su", this.compactSerializer.serialize(profile)); List<Object> groups = q.execute(); List<Object> nestedGroups = new ArrayList<>(groups); while (!nestedGroups.isEmpty()) { StringBuilder qs = new StringBuilder("from doc.object(XWiki.XWikiGroups) grp where grp.member in ("); for (int i = 0; i < nestedGroups.size(); ++i) { if (i > 0) { qs.append(','); } qs.append('?').append(i * 2 + 1).append(",?").append(i * 2 + 2); } qs.append(')'); q = this.qm.createQuery(qs.toString(), Query.XWQL); for (int i = 0; i < nestedGroups.size(); ++i) { String formalGroupName = this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE).toString(); String shortGroupName = this.compactSerializer .serialize(this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE)); q.bindValue(i * 2 + 1, formalGroupName); q.bindValue(i * 2 + 2, shortGroupName); } nestedGroups = q.execute(); nestedGroups.removeAll(groups); groups.addAll(nestedGroups); } q = this.qm.createQuery( "from doc.object(XWiki.XWikiGroups) grp, doc.object(PhenoTips.PhenoTipsGroupClass) phgrp", Query.XWQL); groups.retainAll(q.execute()); for (Object groupName : groups) { result.add(getGroup(String.valueOf(groupName))); } } catch (QueryException ex) { this.logger.warn("Failed to search for user's groups: {}", ex.getMessage()); } return Collections.unmodifiableSet(result); }
DefaultGroupManager implements GroupManager { @Override public Set<Group> getGroupsForUser(User user) { if (user == null || user.getProfileDocument() == null) { return Collections.emptySet(); } DocumentReference profile = user.getProfileDocument(); Set<Group> result = new LinkedHashSet<>(); try { Query q = this.qm.createQuery("from doc.object(XWiki.XWikiGroups) grp where grp.member in (:u, :su)", Query.XWQL); q.bindValue("u", profile.toString()); q.bindValue("su", this.compactSerializer.serialize(profile)); List<Object> groups = q.execute(); List<Object> nestedGroups = new ArrayList<>(groups); while (!nestedGroups.isEmpty()) { StringBuilder qs = new StringBuilder("from doc.object(XWiki.XWikiGroups) grp where grp.member in ("); for (int i = 0; i < nestedGroups.size(); ++i) { if (i > 0) { qs.append(','); } qs.append('?').append(i * 2 + 1).append(",?").append(i * 2 + 2); } qs.append(')'); q = this.qm.createQuery(qs.toString(), Query.XWQL); for (int i = 0; i < nestedGroups.size(); ++i) { String formalGroupName = this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE).toString(); String shortGroupName = this.compactSerializer .serialize(this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE)); q.bindValue(i * 2 + 1, formalGroupName); q.bindValue(i * 2 + 2, shortGroupName); } nestedGroups = q.execute(); nestedGroups.removeAll(groups); groups.addAll(nestedGroups); } q = this.qm.createQuery( "from doc.object(XWiki.XWikiGroups) grp, doc.object(PhenoTips.PhenoTipsGroupClass) phgrp", Query.XWQL); groups.retainAll(q.execute()); for (Object groupName : groups) { result.add(getGroup(String.valueOf(groupName))); } } catch (QueryException ex) { this.logger.warn("Failed to search for user's groups: {}", ex.getMessage()); } return Collections.unmodifiableSet(result); } }
DefaultGroupManager implements GroupManager { @Override public Set<Group> getGroupsForUser(User user) { if (user == null || user.getProfileDocument() == null) { return Collections.emptySet(); } DocumentReference profile = user.getProfileDocument(); Set<Group> result = new LinkedHashSet<>(); try { Query q = this.qm.createQuery("from doc.object(XWiki.XWikiGroups) grp where grp.member in (:u, :su)", Query.XWQL); q.bindValue("u", profile.toString()); q.bindValue("su", this.compactSerializer.serialize(profile)); List<Object> groups = q.execute(); List<Object> nestedGroups = new ArrayList<>(groups); while (!nestedGroups.isEmpty()) { StringBuilder qs = new StringBuilder("from doc.object(XWiki.XWikiGroups) grp where grp.member in ("); for (int i = 0; i < nestedGroups.size(); ++i) { if (i > 0) { qs.append(','); } qs.append('?').append(i * 2 + 1).append(",?").append(i * 2 + 2); } qs.append(')'); q = this.qm.createQuery(qs.toString(), Query.XWQL); for (int i = 0; i < nestedGroups.size(); ++i) { String formalGroupName = this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE).toString(); String shortGroupName = this.compactSerializer .serialize(this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE)); q.bindValue(i * 2 + 1, formalGroupName); q.bindValue(i * 2 + 2, shortGroupName); } nestedGroups = q.execute(); nestedGroups.removeAll(groups); groups.addAll(nestedGroups); } q = this.qm.createQuery( "from doc.object(XWiki.XWikiGroups) grp, doc.object(PhenoTips.PhenoTipsGroupClass) phgrp", Query.XWQL); groups.retainAll(q.execute()); for (Object groupName : groups) { result.add(getGroup(String.valueOf(groupName))); } } catch (QueryException ex) { this.logger.warn("Failed to search for user's groups: {}", ex.getMessage()); } return Collections.unmodifiableSet(result); }  }
DefaultGroupManager implements GroupManager { @Override public Set<Group> getGroupsForUser(User user) { if (user == null || user.getProfileDocument() == null) { return Collections.emptySet(); } DocumentReference profile = user.getProfileDocument(); Set<Group> result = new LinkedHashSet<>(); try { Query q = this.qm.createQuery("from doc.object(XWiki.XWikiGroups) grp where grp.member in (:u, :su)", Query.XWQL); q.bindValue("u", profile.toString()); q.bindValue("su", this.compactSerializer.serialize(profile)); List<Object> groups = q.execute(); List<Object> nestedGroups = new ArrayList<>(groups); while (!nestedGroups.isEmpty()) { StringBuilder qs = new StringBuilder("from doc.object(XWiki.XWikiGroups) grp where grp.member in ("); for (int i = 0; i < nestedGroups.size(); ++i) { if (i > 0) { qs.append(','); } qs.append('?').append(i * 2 + 1).append(",?").append(i * 2 + 2); } qs.append(')'); q = this.qm.createQuery(qs.toString(), Query.XWQL); for (int i = 0; i < nestedGroups.size(); ++i) { String formalGroupName = this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE).toString(); String shortGroupName = this.compactSerializer .serialize(this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE)); q.bindValue(i * 2 + 1, formalGroupName); q.bindValue(i * 2 + 2, shortGroupName); } nestedGroups = q.execute(); nestedGroups.removeAll(groups); groups.addAll(nestedGroups); } q = this.qm.createQuery( "from doc.object(XWiki.XWikiGroups) grp, doc.object(PhenoTips.PhenoTipsGroupClass) phgrp", Query.XWQL); groups.retainAll(q.execute()); for (Object groupName : groups) { result.add(getGroup(String.valueOf(groupName))); } } catch (QueryException ex) { this.logger.warn("Failed to search for user's groups: {}", ex.getMessage()); } return Collections.unmodifiableSet(result); }  @Override Set<Group> getGroupsForUser(User user); @Override Group getGroup(String name); @Override Group getGroup(DocumentReference groupReference); @Override Set<Document> getAllMembersForGroup(String name); }
DefaultGroupManager implements GroupManager { @Override public Set<Group> getGroupsForUser(User user) { if (user == null || user.getProfileDocument() == null) { return Collections.emptySet(); } DocumentReference profile = user.getProfileDocument(); Set<Group> result = new LinkedHashSet<>(); try { Query q = this.qm.createQuery("from doc.object(XWiki.XWikiGroups) grp where grp.member in (:u, :su)", Query.XWQL); q.bindValue("u", profile.toString()); q.bindValue("su", this.compactSerializer.serialize(profile)); List<Object> groups = q.execute(); List<Object> nestedGroups = new ArrayList<>(groups); while (!nestedGroups.isEmpty()) { StringBuilder qs = new StringBuilder("from doc.object(XWiki.XWikiGroups) grp where grp.member in ("); for (int i = 0; i < nestedGroups.size(); ++i) { if (i > 0) { qs.append(','); } qs.append('?').append(i * 2 + 1).append(",?").append(i * 2 + 2); } qs.append(')'); q = this.qm.createQuery(qs.toString(), Query.XWQL); for (int i = 0; i < nestedGroups.size(); ++i) { String formalGroupName = this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE).toString(); String shortGroupName = this.compactSerializer .serialize(this.resolver.resolve(String.valueOf(nestedGroups.get(i)), GROUP_SPACE)); q.bindValue(i * 2 + 1, formalGroupName); q.bindValue(i * 2 + 2, shortGroupName); } nestedGroups = q.execute(); nestedGroups.removeAll(groups); groups.addAll(nestedGroups); } q = this.qm.createQuery( "from doc.object(XWiki.XWikiGroups) grp, doc.object(PhenoTips.PhenoTipsGroupClass) phgrp", Query.XWQL); groups.retainAll(q.execute()); for (Object groupName : groups) { result.add(getGroup(String.valueOf(groupName))); } } catch (QueryException ex) { this.logger.warn("Failed to search for user's groups: {}", ex.getMessage()); } return Collections.unmodifiableSet(result); }  @Override Set<Group> getGroupsForUser(User user); @Override Group getGroup(String name); @Override Group getGroup(DocumentReference groupReference); @Override Set<Document> getAllMembersForGroup(String name);  }