@Test public void getUsers() throws QueryException { mockUsers(false, USERS_STRING_ALL); mockUsers(true, USERS_STRING_ACTIVE); assertGetCache(USERS_REF_ACTIVE, true); assertGetCache(USERS_REF_ALL, false); }
public List<DocumentReference> getUsers(WikiReference wiki, boolean activeOnly) { String cacheKey = activeOnly + wiki.getName(); List<DocumentReference> cached = this.cache.get(cacheKey); if (cached != null) { return cached; } List<String> result; try { StringBuilder statement = new StringBuilder( "select distinct doc.fullName from Document doc, doc.object(XWiki.XWikiUsers) as user"); if (activeOnly) { statement.append(" where user.active = 1"); } Query query = this.queries.createQuery(statement.toString(), Query.XWQL); query.setWiki(wiki.getName()); result = query.execute(); } catch (QueryException e) { this.logger.error("Failed to get users from the wiki [{}]", wiki, e); return Collections.emptyList(); } List<DocumentReference> users; if (result.isEmpty()) { users = Collections.emptyList(); } else { List<DocumentReference> list = new ArrayList<>(result.size()); result.forEach(e -> list.add(this.referenceFactory.getReference(this.resolver.resolve(e, wiki)))); users = Collections.unmodifiableList(list); } this.cache.set(cacheKey, users); return users; }
UsersCache implements Initializable, Disposable { public List<DocumentReference> getUsers(WikiReference wiki, boolean activeOnly) { String cacheKey = activeOnly + wiki.getName(); List<DocumentReference> cached = this.cache.get(cacheKey); if (cached != null) { return cached; } List<String> result; try { StringBuilder statement = new StringBuilder( "select distinct doc.fullName from Document doc, doc.object(XWiki.XWikiUsers) as user"); if (activeOnly) { statement.append(" where user.active = 1"); } Query query = this.queries.createQuery(statement.toString(), Query.XWQL); query.setWiki(wiki.getName()); result = query.execute(); } catch (QueryException e) { this.logger.error("Failed to get users from the wiki [{}]", wiki, e); return Collections.emptyList(); } List<DocumentReference> users; if (result.isEmpty()) { users = Collections.emptyList(); } else { List<DocumentReference> list = new ArrayList<>(result.size()); result.forEach(e -> list.add(this.referenceFactory.getReference(this.resolver.resolve(e, wiki)))); users = Collections.unmodifiableList(list); } this.cache.set(cacheKey, users); return users; } }
UsersCache implements Initializable, Disposable { public List<DocumentReference> getUsers(WikiReference wiki, boolean activeOnly) { String cacheKey = activeOnly + wiki.getName(); List<DocumentReference> cached = this.cache.get(cacheKey); if (cached != null) { return cached; } List<String> result; try { StringBuilder statement = new StringBuilder( "select distinct doc.fullName from Document doc, doc.object(XWiki.XWikiUsers) as user"); if (activeOnly) { statement.append(" where user.active = 1"); } Query query = this.queries.createQuery(statement.toString(), Query.XWQL); query.setWiki(wiki.getName()); result = query.execute(); } catch (QueryException e) { this.logger.error("Failed to get users from the wiki [{}]", wiki, e); return Collections.emptyList(); } List<DocumentReference> users; if (result.isEmpty()) { users = Collections.emptyList(); } else { List<DocumentReference> list = new ArrayList<>(result.size()); result.forEach(e -> list.add(this.referenceFactory.getReference(this.resolver.resolve(e, wiki)))); users = Collections.unmodifiableList(list); } this.cache.set(cacheKey, users); return users; }  }
UsersCache implements Initializable, Disposable { public List<DocumentReference> getUsers(WikiReference wiki, boolean activeOnly) { String cacheKey = activeOnly + wiki.getName(); List<DocumentReference> cached = this.cache.get(cacheKey); if (cached != null) { return cached; } List<String> result; try { StringBuilder statement = new StringBuilder( "select distinct doc.fullName from Document doc, doc.object(XWiki.XWikiUsers) as user"); if (activeOnly) { statement.append(" where user.active = 1"); } Query query = this.queries.createQuery(statement.toString(), Query.XWQL); query.setWiki(wiki.getName()); result = query.execute(); } catch (QueryException e) { this.logger.error("Failed to get users from the wiki [{}]", wiki, e); return Collections.emptyList(); } List<DocumentReference> users; if (result.isEmpty()) { users = Collections.emptyList(); } else { List<DocumentReference> list = new ArrayList<>(result.size()); result.forEach(e -> list.add(this.referenceFactory.getReference(this.resolver.resolve(e, wiki)))); users = Collections.unmodifiableList(list); } this.cache.set(cacheKey, users); return users; }  @Override void initialize(); @Override void dispose(); List<DocumentReference> getUsers(WikiReference wiki, boolean activeOnly); void cleanCache(String wiki); }
UsersCache implements Initializable, Disposable { public List<DocumentReference> getUsers(WikiReference wiki, boolean activeOnly) { String cacheKey = activeOnly + wiki.getName(); List<DocumentReference> cached = this.cache.get(cacheKey); if (cached != null) { return cached; } List<String> result; try { StringBuilder statement = new StringBuilder( "select distinct doc.fullName from Document doc, doc.object(XWiki.XWikiUsers) as user"); if (activeOnly) { statement.append(" where user.active = 1"); } Query query = this.queries.createQuery(statement.toString(), Query.XWQL); query.setWiki(wiki.getName()); result = query.execute(); } catch (QueryException e) { this.logger.error("Failed to get users from the wiki [{}]", wiki, e); return Collections.emptyList(); } List<DocumentReference> users; if (result.isEmpty()) { users = Collections.emptyList(); } else { List<DocumentReference> list = new ArrayList<>(result.size()); result.forEach(e -> list.add(this.referenceFactory.getReference(this.resolver.resolve(e, wiki)))); users = Collections.unmodifiableList(list); } this.cache.set(cacheKey, users); return users; }  @Override void initialize(); @Override void dispose(); List<DocumentReference> getUsers(WikiReference wiki, boolean activeOnly); void cleanCache(String wiki);  }