JobsListProvider implements ResourceListProvider { @Override public Map<String, String> getList(String listName, ResourceListQuery query) { String listNameTrimmed = StringUtils.trimToEmpty(listName); Map<String, String> jobList = new HashMap<String, String>(); if (StringUtils.equalsIgnoreCase(LIST_STATUS, listName)) { jobList.put(Job.Status.PAUSED.toString(), JOB_STATUS_FILTER_PREFIX + Job.Status.PAUSED.toString()); jobList.put(Job.Status.QUEUED.toString(), JOB_STATUS_FILTER_PREFIX + Job.Status.QUEUED.toString()); jobList.put(Job.Status.RUNNING.toString(), JOB_STATUS_FILTER_PREFIX + Job.Status.RUNNING.toString()); jobList.put(Job.Status.WAITING.toString(), JOB_STATUS_FILTER_PREFIX + Job.Status.WAITING.toString()); } else if (StringUtils.equalsIgnoreCase(LIST_WORKFLOW, listNameTrimmed)) { try { for (WorkflowDefinition workflowDef : workflowService.listAvailableWorkflowDefinitions()) { if (StringUtils.isNotBlank(workflowDef.getTitle()) && !jobList.containsKey(workflowDef.getId()) && !jobList.containsValue(workflowDef.getTitle())) { jobList.put(workflowDef.getId(), workflowDef.getTitle()); } } } catch (WorkflowDatabaseException ex) { logger.error("Failed to get available workflow definitions from workflow service: {}", ex.getMessage()); } } return jobList; }  @Override String[] getListNames(); @Override Map<String, String> getList(String listName, ResourceListQuery query); void setWorkflowService(WorkflowService workflowService); @Override boolean isTranslatable(String listName); @Override String getDefault(); static final String LIST_STATUS; static final String LIST_WORKFLOW; static final String JOB_STATUS_FILTER_PREFIX; }
@Test public void testStatusListName() throws ListProviderException, WorkflowDatabaseException { ResourceListQuery query = new JobsListQuery(); assertEquals(4, jobsListProvider.getList(JobsListProvider.LIST_STATUS, query).size()); for (Entry<String, String> entry : jobsListProvider.getList(JobsListProvider.LIST_STATUS, query).entrySet()) { try { Job.Status.valueOf(entry.getKey()); } catch (IllegalArgumentException ex) { fail("Can not parse job state"); } assertTrue(StringUtils.startsWith(entry.getValue(), JobsListProvider.JOB_STATUS_FILTER_PREFIX)); } }
@Test public void testWorkflowListName() throws ListProviderException, WorkflowDatabaseException { ResourceListQuery query = new JobsListQuery(); assertEquals(workflowDefinitions.size(), jobsListProvider.getList(JobsListProvider.LIST_WORKFLOW, query).size()); for (Entry<String, String> entry : jobsListProvider.getList( JobsListProvider.LIST_WORKFLOW, query).entrySet()) { boolean match = false; for (WorkflowDefinition wfD : workflowDefinitions) { if (StringUtils.equals(wfD.getId(), entry.getKey()) && StringUtils.equals(wfD.getTitle(), entry.getValue())) { match = true; break; } } assertTrue(match); } }