EmpireWorkflowTaskDao extends EmpireDao implements WorkflowTaskDao { @Override public List<TaskView> view(TaskFilter filter) { DBCommand cmd = db.createCommand(); cmd.select(tableTask.getColumns()); cmd.select(db.tableWorkflowJob.label.as("JOB_LABEL")); cmd.select(db.tableUser.username); cmd.join(tableTask.jobId, db.tableWorkflowJob.id); cmd.join(tableTask.ownerId, db.tableUser.id, DBJoinType.LEFT); if (filter.getId() != null) { cmd.where(tableTask.id.is(filter.getId())); } if (filter.getJobId() != null) { cmd.where(tableTask.jobId.is(filter.getJobId())); } if (filter.getJobLabel() != null) { String pattern = filter.getJobLabel().trim().replace("%", "\\%"); if (!pattern.isEmpty()) { cmd.where(db.tableWorkflowJob.label.likeUpper('%' + pattern + '%')); } } if (!filter.getPriority().isEmpty()) { cmd.where(tableTask.priority.in(filter.getPriority())); } if (!filter.getProfileName().isEmpty()) { cmd.where(tableTask.typeRef.in(filter.getProfileName())); } if (!filter.getState().isEmpty()) { cmd.where(tableTask.state.in(filter.getStateAsString())); } if (!filter.getUserId().isEmpty()) { cmd.where(tableTask.ownerId.in(filter.getUserId())); } EmpireUtils.addWhereDate(cmd, tableTask.created, filter.getCreated()); EmpireUtils.addWhereDate(cmd, tableTask.timestamp, filter.getModified()); EmpireUtils.addOrderBy(cmd, filter.getSortBy(), tableTask.timestamp, false); DBReader reader = new DBReader(); try { reader.open(cmd, getConnection()); if (!reader.skipRows(filter.getOffset())) { return Collections.emptyList(); } ArrayList<TaskView> viewItems = new ArrayList<TaskView>(filter.getMaxCount()); for (Iterator<DBRecordData> it = reader.iterator(filter.getMaxCount()); it.hasNext();) { DBRecordData rec = it.next(); TaskView view = new TaskView(); rec.getBeanProperties(view); viewItems.add(view); } return viewItems; } finally { reader.close(); } } EmpireWorkflowTaskDao(ProarcDatabase db); @Override Task create(); @Override void update(Task task); @Override Task find(BigDecimal id); @Override List<TaskView> view(TaskFilter filter);  }
@Test public void testView() throws Exception { IDataSet db = database( support.loadFlatXmlDataStream(getClass(), "user.xml"), support.loadFlatXmlDataStream(getClass(), "wf_job.xml"), support.loadFlatXmlDataStream(getClass(), "wf_task.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); TaskFilter filter = new TaskFilter(); filter.setJobId(BigDecimal.ONE); filter.setJobLabel("Monograph1"); List<TaskView> tasks = dao.view(filter); assertEquals(1, tasks.size()); TaskView t = tasks.get(0); assertEquals(BigDecimal.ONE, t.getId()); assertEquals(State.STARTED, t.getState()); assertEquals("Monograph1", t.getJobLabel()); assertEquals("test", t.getUserName()); filter = new TaskFilter(); filter.setProfileName(Arrays.asList("task.id1", "task.id2")); tasks = dao.view(filter); assertEquals(2, tasks.size()); }