@Test public void testQueryField() throws Exception { try (OperationContext ctx = new OperationContext(session)) { Map<String, Object> params = new HashMap<>(); params.put("firstName", FIRSTNAME); Blob blob = (Blob) automationService.run(ctx, QueryUsers.ID, params); assertJsonUserList(Arrays.asList( map( "username", "testuser", "firstName", "syd", "lastName", "barrett"), map( "username", "testuser2", "firstName", "syd", "lastName", "vycyous", "tenantId", "alternatey" )), blob); params = new HashMap<>(); params.put("firstName", FIRSTNAME); params.put("lastName", LASTNAME); blob = (Blob) automationService.run(ctx, QueryUsers.ID, params); assertJsonUserList(Arrays.asList( map( "username", "testuser", "firstName", "syd", "lastName", "barrett" )), blob); params = new HashMap<>(); params.put("firstName", FIRSTNAME); params.put("tenantId", TENANTID); blob = (Blob) automationService.run(ctx, QueryUsers.ID, params); assertJsonUserList(Arrays.asList( map( "username", "testuser2", "firstName", "syd", "lastName", "vycyous", "tenantId", "alternatey" )), blob); } }
@OperationMethod public Blob run() throws IOException { List<DocumentModel> users; if (StringUtils.isBlank(pattern)) { Map<String, Serializable> filter = new HashMap<>(); if (StringUtils.isNotBlank(username)) { filter.put(USERNAME_COLUMN, username); } if (StringUtils.isNotBlank(firstName)) { filter.put(FIRSTNAME_COLUMN, firstName); } if (StringUtils.isNotBlank(lastName)) { filter.put(LASTNAME_COLUMN, lastName); } if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } users = userManager.searchUsers(filter, FULLTEXT_FIELDS); } else { users = new ArrayList<>(); Set<String> userIds = new HashSet<>(); for (String field : FULLTEXT_FIELDS) { Map<String, Serializable> filter = new HashMap<>(); filter.put(field, pattern); if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } DocumentModelList userDocs = userManager.searchUsers(filter, Collections.singleton(field)); for (DocumentModel userDoc : userDocs) { if (userIds.add(userDoc.getId())) { users.add(userDoc); } } } } return buildResponse(users); }
QueryUsers { @OperationMethod public Blob run() throws IOException { List<DocumentModel> users; if (StringUtils.isBlank(pattern)) { Map<String, Serializable> filter = new HashMap<>(); if (StringUtils.isNotBlank(username)) { filter.put(USERNAME_COLUMN, username); } if (StringUtils.isNotBlank(firstName)) { filter.put(FIRSTNAME_COLUMN, firstName); } if (StringUtils.isNotBlank(lastName)) { filter.put(LASTNAME_COLUMN, lastName); } if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } users = userManager.searchUsers(filter, FULLTEXT_FIELDS); } else { users = new ArrayList<>(); Set<String> userIds = new HashSet<>(); for (String field : FULLTEXT_FIELDS) { Map<String, Serializable> filter = new HashMap<>(); filter.put(field, pattern); if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } DocumentModelList userDocs = userManager.searchUsers(filter, Collections.singleton(field)); for (DocumentModel userDoc : userDocs) { if (userIds.add(userDoc.getId())) { users.add(userDoc); } } } } return buildResponse(users); } }
QueryUsers { @OperationMethod public Blob run() throws IOException { List<DocumentModel> users; if (StringUtils.isBlank(pattern)) { Map<String, Serializable> filter = new HashMap<>(); if (StringUtils.isNotBlank(username)) { filter.put(USERNAME_COLUMN, username); } if (StringUtils.isNotBlank(firstName)) { filter.put(FIRSTNAME_COLUMN, firstName); } if (StringUtils.isNotBlank(lastName)) { filter.put(LASTNAME_COLUMN, lastName); } if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } users = userManager.searchUsers(filter, FULLTEXT_FIELDS); } else { users = new ArrayList<>(); Set<String> userIds = new HashSet<>(); for (String field : FULLTEXT_FIELDS) { Map<String, Serializable> filter = new HashMap<>(); filter.put(field, pattern); if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } DocumentModelList userDocs = userManager.searchUsers(filter, Collections.singleton(field)); for (DocumentModel userDoc : userDocs) { if (userIds.add(userDoc.getId())) { users.add(userDoc); } } } } return buildResponse(users); }  }
QueryUsers { @OperationMethod public Blob run() throws IOException { List<DocumentModel> users; if (StringUtils.isBlank(pattern)) { Map<String, Serializable> filter = new HashMap<>(); if (StringUtils.isNotBlank(username)) { filter.put(USERNAME_COLUMN, username); } if (StringUtils.isNotBlank(firstName)) { filter.put(FIRSTNAME_COLUMN, firstName); } if (StringUtils.isNotBlank(lastName)) { filter.put(LASTNAME_COLUMN, lastName); } if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } users = userManager.searchUsers(filter, FULLTEXT_FIELDS); } else { users = new ArrayList<>(); Set<String> userIds = new HashSet<>(); for (String field : FULLTEXT_FIELDS) { Map<String, Serializable> filter = new HashMap<>(); filter.put(field, pattern); if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } DocumentModelList userDocs = userManager.searchUsers(filter, Collections.singleton(field)); for (DocumentModel userDoc : userDocs) { if (userIds.add(userDoc.getId())) { users.add(userDoc); } } } } return buildResponse(users); }  @OperationMethod Blob run(); }
QueryUsers { @OperationMethod public Blob run() throws IOException { List<DocumentModel> users; if (StringUtils.isBlank(pattern)) { Map<String, Serializable> filter = new HashMap<>(); if (StringUtils.isNotBlank(username)) { filter.put(USERNAME_COLUMN, username); } if (StringUtils.isNotBlank(firstName)) { filter.put(FIRSTNAME_COLUMN, firstName); } if (StringUtils.isNotBlank(lastName)) { filter.put(LASTNAME_COLUMN, lastName); } if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } users = userManager.searchUsers(filter, FULLTEXT_FIELDS); } else { users = new ArrayList<>(); Set<String> userIds = new HashSet<>(); for (String field : FULLTEXT_FIELDS) { Map<String, Serializable> filter = new HashMap<>(); filter.put(field, pattern); if (StringUtils.isNotBlank(tenantId)) { filter.put(TENANT_ID_COLUMN, tenantId); } DocumentModelList userDocs = userManager.searchUsers(filter, Collections.singleton(field)); for (DocumentModel userDoc : userDocs) { if (userIds.add(userDoc.getId())) { users.add(userDoc); } } } } return buildResponse(users); }  @OperationMethod Blob run(); static final String ID; static final Set<String> FULLTEXT_FIELDS; static final String JSON_USERNAME; static final String JSON_FIRSTNAME; static final String JSON_LASTNAME; static final String JSON_EMAIL; static final String JSON_COMPANY; static final String JSON_TENANT_ID; }