JobService extends SearchableService { public StringHandle getJobs(JobQuery jobQuery) { queryMgr.setPageLength(jobQuery.count); StructuredQueryBuilder sb = queryMgr.newStructuredQueryBuilder(SEARCH_OPTIONS_NAME); ArrayList<StructuredQueryDefinition> queries = new ArrayList<>(); queries.add(sb.collection("job")); if (jobQuery.query != null && !jobQuery.query.equals("")) { queries.add(sb.term(jobQuery.query)); } StructuredQueryDefinition def = addRangeConstraint(sb, "status", jobQuery.status); if (def != null) { queries.add(def); } def = addRangeConstraint(sb, "entityName", jobQuery.entityName); if (def != null) { queries.add(def); } def = addRangeConstraint(sb, "flowName", jobQuery.flowName); if (def != null) { queries.add(def); } def = addRangeConstraint(sb, "flowType", jobQuery.flowType); if (def != null) { queries.add(def); } StructuredQueryDefinition sqd = sb.and(queries.toArray(new StructuredQueryDefinition[0])); String searchXml = sqd.serialize(); RawCombinedQueryDefinition querydef = queryMgr.newRawCombinedQueryDefinition(new StringHandle(searchXml), SEARCH_OPTIONS_NAME); querydef.setResponseTransform(new ServerTransform("mlJobSearchResults")); StringHandle sh = new StringHandle(); sh.setFormat(Format.JSON); return queryMgr.search(querydef, sh, jobQuery.start); } JobService(DatabaseClient jobClient); StringHandle getJobs(JobQuery jobQuery); JobDeleteResponse deleteJobs(String jobIds); File exportJobs(String[] jobIds); void cancelJob(long jobId);  }
@Test public void getJobs() { DatabaseClient jobClient = getDataHubAdminConfig().newJobDbClient(); JobService jobService = new JobService(jobClient); JobQuery jobQuery = new JobQuery(); jobQuery.start = Long.valueOf(1); jobQuery.count = Long.valueOf(10); jobService.getJobs(jobQuery); }