@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.loadFlatXmlDataStream(getClass(), "wf_material.xml") ); support.cleanInsert(support.getConnection(tx), db); tx.commit(); MaterialFilter filter = new MaterialFilter(); filter.setTaskId(BigDecimal.ONE); filter.setId(new BigDecimal(2)); List<MaterialView> ms = dao.view(filter); assertEquals(1, ms.size()); assertEquals(filter.getId(), ms.get(0).getId()); assertNull(ms.get(0).getJobId()); assertEquals("Dig Obj", ms.get(0).getLabel()); assertEquals("material.digital", ms.get(0).getName()); assertEquals("note d1", ms.get(0).getNote()); assertEquals("uuid:ebfd7bf2-169d-476e-a230-0cc39f01764c", ms.get(0).getPid()); assertNull(ms.get(0).getPath()); assertEquals(filter.getTaskId(), ms.get(0).getTaskId()); assertEquals(MaterialType.DIGITAL_OBJECT, ms.get(0).getType()); assertEquals(Way.INPUT, ms.get(0).getWay()); filter = new MaterialFilter(); filter.setTaskId(BigDecimal.ONE); filter.setId(new BigDecimal(3)); ms = dao.view(filter); assertEquals(1, ms.size()); assertEquals(filter.getId(), ms.get(0).getId()); assertNull(ms.get(0).getJobId()); assertEquals("Phys Doc", ms.get(0).getLabel()); assertEquals("material.physical", ms.get(0).getName()); assertEquals("note p1", ms.get(0).getNote()); assertEquals("1234", ms.get(0).getBarcode()); assertEquals("001", ms.get(0).getField001()); assertEquals("Metadata", ms.get(0).getMetadata()); assertEquals(BigDecimal.valueOf(3), ms.get(0).getRdczId()); assertEquals("sig123", ms.get(0).getSignature()); assertEquals("http: assertEquals("detail", ms.get(0).getDetail()); assertEquals("11", ms.get(0).getIssue()); assertEquals("ABA123", ms.get(0).getSigla()); assertEquals("13", ms.get(0).getVolume()); assertEquals("1998-1999", ms.get(0).getYear()); assertNull(ms.get(0).getPid()); assertNull(ms.get(0).getPath()); assertEquals(filter.getTaskId(), ms.get(0).getTaskId()); assertEquals(MaterialType.PHYSICAL_DOCUMENT, ms.get(0).getType()); assertEquals(Way.INPUT, ms.get(0).getWay()); filter = new MaterialFilter(); filter.setJobId(BigDecimal.ONE); filter.setSortBy(schema.tableWorkflowMaterial.id.getBeanPropertyName()); ms = dao.view(filter); assertEquals(3, ms.size()); assertEquals(BigDecimal.ONE, ms.get(0).getId()); assertEquals(BigDecimal.ONE, ms.get(0).getJobId()); assertEquals("/folder1", ms.get(0).getLabel()); assertEquals("material.folder", ms.get(0).getName()); assertEquals("note m1", ms.get(0).getNote()); assertEquals("file: assertNull(ms.get(0).getTaskId()); assertEquals(MaterialType.FOLDER, ms.get(0).getType()); assertNull(ms.get(0).getWay()); filter = new MaterialFilter(); filter.setJobId(BigDecimal.ONE); filter.setId(BigDecimal.ONE); filter.setSortBy(schema.tableWorkflowMaterial.id.getBeanPropertyName()); ms = dao.view(filter); assertEquals(1, ms.size()); assertEquals(BigDecimal.ONE, ms.get(0).getId()); assertEquals(BigDecimal.ONE, ms.get(0).getJobId()); assertEquals("/folder1", ms.get(0).getLabel()); assertEquals("material.folder", ms.get(0).getName()); assertEquals("note m1", ms.get(0).getNote()); assertEquals("file: assertNull(ms.get(0).getTaskId()); assertEquals(MaterialType.FOLDER, ms.get(0).getType()); assertNull(ms.get(0).getWay()); for (MaterialType type : MaterialType.values()) { filter = new MaterialFilter(); filter.setJobId(BigDecimal.ONE); filter.setType(type); assertTrue("returned objects should be " + type.name(), dao.view(filter).stream().allMatch(material-> type.equals(material.getType()))); } }
@Override public List<MaterialView> view(MaterialFilter filter) { DBCommand cmd = db.createCommand(); cmd.select(db.tableWorkflowMaterial.getColumns()); cmd.select(db.tableWorkflowFolder.path); cmd.select(db.tableWorkflowDigObj.pid); List<DBColumn> physicalSelections = new ArrayList<DBColumn>(db.tableWorkflowPhysicalDoc.getColumns()); physicalSelections.remove(db.tableWorkflowPhysicalDoc.materialId); cmd.select(physicalSelections); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowFolder.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowDigObj.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowPhysicalDoc.materialId, DBJoinType.LEFT); if (filter.getId() != null) { cmd.where(db.tableWorkflowMaterial.id.is(filter.getId())); } if (filter.getType() != null) { cmd.addWhereConstraints(Collections.singletonList(db.tableWorkflowMaterial.type.is(filter.getType()))); } if (filter.getTaskId() != null) { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterialInTask.taskId.is(filter.getTaskId()) )); } else if (filter.getJobId() != null) { DBCommand subcmd = db.createCommand(); subcmd.select(db.tableWorkflowMaterialInTask.materialId); subcmd.selectDistinct(); subcmd.join(db.tableWorkflowMaterialInTask.taskId, db.tableWorkflowTask.id); subcmd.where(db.tableWorkflowTask.jobId.is(filter.getJobId())); DBQuery materialIds = new DBQuery(subcmd); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterial.id.in(materialIds.findQueryColumn(db.tableWorkflowMaterialInTask.materialId)) )); cmd.select(db.getValueExpr(filter.getJobId(), DataType.DECIMAL).as(db.tableWorkflowTask.jobId)); } else { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); } EmpireUtils.addOrderBy(cmd, filter.getSortBy(), db.tableWorkflowMaterial.id, false); DBReader reader = new DBReader(); try { reader.open(cmd, getConnection()); if (!reader.skipRows(filter.getOffset())) { return Collections.emptyList(); } ArrayList<MaterialView> viewItems = new ArrayList<MaterialView>(filter.getMaxCount()); for (Iterator<DBRecordData> it = reader.iterator(filter.getMaxCount()); it.hasNext();) { DBRecordData rec = it.next(); MaterialView view = new MaterialView(); rec.getBeanProperties(view); viewItems.add(view); } return viewItems; } finally { reader.close(); } }
EmpireWorkflowMaterialDao extends EmpireDao implements WorkflowMaterialDao { @Override public List<MaterialView> view(MaterialFilter filter) { DBCommand cmd = db.createCommand(); cmd.select(db.tableWorkflowMaterial.getColumns()); cmd.select(db.tableWorkflowFolder.path); cmd.select(db.tableWorkflowDigObj.pid); List<DBColumn> physicalSelections = new ArrayList<DBColumn>(db.tableWorkflowPhysicalDoc.getColumns()); physicalSelections.remove(db.tableWorkflowPhysicalDoc.materialId); cmd.select(physicalSelections); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowFolder.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowDigObj.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowPhysicalDoc.materialId, DBJoinType.LEFT); if (filter.getId() != null) { cmd.where(db.tableWorkflowMaterial.id.is(filter.getId())); } if (filter.getType() != null) { cmd.addWhereConstraints(Collections.singletonList(db.tableWorkflowMaterial.type.is(filter.getType()))); } if (filter.getTaskId() != null) { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterialInTask.taskId.is(filter.getTaskId()) )); } else if (filter.getJobId() != null) { DBCommand subcmd = db.createCommand(); subcmd.select(db.tableWorkflowMaterialInTask.materialId); subcmd.selectDistinct(); subcmd.join(db.tableWorkflowMaterialInTask.taskId, db.tableWorkflowTask.id); subcmd.where(db.tableWorkflowTask.jobId.is(filter.getJobId())); DBQuery materialIds = new DBQuery(subcmd); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterial.id.in(materialIds.findQueryColumn(db.tableWorkflowMaterialInTask.materialId)) )); cmd.select(db.getValueExpr(filter.getJobId(), DataType.DECIMAL).as(db.tableWorkflowTask.jobId)); } else { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); } EmpireUtils.addOrderBy(cmd, filter.getSortBy(), db.tableWorkflowMaterial.id, false); DBReader reader = new DBReader(); try { reader.open(cmd, getConnection()); if (!reader.skipRows(filter.getOffset())) { return Collections.emptyList(); } ArrayList<MaterialView> viewItems = new ArrayList<MaterialView>(filter.getMaxCount()); for (Iterator<DBRecordData> it = reader.iterator(filter.getMaxCount()); it.hasNext();) { DBRecordData rec = it.next(); MaterialView view = new MaterialView(); rec.getBeanProperties(view); viewItems.add(view); } return viewItems; } finally { reader.close(); } } }
EmpireWorkflowMaterialDao extends EmpireDao implements WorkflowMaterialDao { @Override public List<MaterialView> view(MaterialFilter filter) { DBCommand cmd = db.createCommand(); cmd.select(db.tableWorkflowMaterial.getColumns()); cmd.select(db.tableWorkflowFolder.path); cmd.select(db.tableWorkflowDigObj.pid); List<DBColumn> physicalSelections = new ArrayList<DBColumn>(db.tableWorkflowPhysicalDoc.getColumns()); physicalSelections.remove(db.tableWorkflowPhysicalDoc.materialId); cmd.select(physicalSelections); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowFolder.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowDigObj.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowPhysicalDoc.materialId, DBJoinType.LEFT); if (filter.getId() != null) { cmd.where(db.tableWorkflowMaterial.id.is(filter.getId())); } if (filter.getType() != null) { cmd.addWhereConstraints(Collections.singletonList(db.tableWorkflowMaterial.type.is(filter.getType()))); } if (filter.getTaskId() != null) { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterialInTask.taskId.is(filter.getTaskId()) )); } else if (filter.getJobId() != null) { DBCommand subcmd = db.createCommand(); subcmd.select(db.tableWorkflowMaterialInTask.materialId); subcmd.selectDistinct(); subcmd.join(db.tableWorkflowMaterialInTask.taskId, db.tableWorkflowTask.id); subcmd.where(db.tableWorkflowTask.jobId.is(filter.getJobId())); DBQuery materialIds = new DBQuery(subcmd); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterial.id.in(materialIds.findQueryColumn(db.tableWorkflowMaterialInTask.materialId)) )); cmd.select(db.getValueExpr(filter.getJobId(), DataType.DECIMAL).as(db.tableWorkflowTask.jobId)); } else { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); } EmpireUtils.addOrderBy(cmd, filter.getSortBy(), db.tableWorkflowMaterial.id, false); DBReader reader = new DBReader(); try { reader.open(cmd, getConnection()); if (!reader.skipRows(filter.getOffset())) { return Collections.emptyList(); } ArrayList<MaterialView> viewItems = new ArrayList<MaterialView>(filter.getMaxCount()); for (Iterator<DBRecordData> it = reader.iterator(filter.getMaxCount()); it.hasNext();) { DBRecordData rec = it.next(); MaterialView view = new MaterialView(); rec.getBeanProperties(view); viewItems.add(view); } return viewItems; } finally { reader.close(); } } EmpireWorkflowMaterialDao(ProarcDatabase db); }
EmpireWorkflowMaterialDao extends EmpireDao implements WorkflowMaterialDao { @Override public List<MaterialView> view(MaterialFilter filter) { DBCommand cmd = db.createCommand(); cmd.select(db.tableWorkflowMaterial.getColumns()); cmd.select(db.tableWorkflowFolder.path); cmd.select(db.tableWorkflowDigObj.pid); List<DBColumn> physicalSelections = new ArrayList<DBColumn>(db.tableWorkflowPhysicalDoc.getColumns()); physicalSelections.remove(db.tableWorkflowPhysicalDoc.materialId); cmd.select(physicalSelections); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowFolder.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowDigObj.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowPhysicalDoc.materialId, DBJoinType.LEFT); if (filter.getId() != null) { cmd.where(db.tableWorkflowMaterial.id.is(filter.getId())); } if (filter.getType() != null) { cmd.addWhereConstraints(Collections.singletonList(db.tableWorkflowMaterial.type.is(filter.getType()))); } if (filter.getTaskId() != null) { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterialInTask.taskId.is(filter.getTaskId()) )); } else if (filter.getJobId() != null) { DBCommand subcmd = db.createCommand(); subcmd.select(db.tableWorkflowMaterialInTask.materialId); subcmd.selectDistinct(); subcmd.join(db.tableWorkflowMaterialInTask.taskId, db.tableWorkflowTask.id); subcmd.where(db.tableWorkflowTask.jobId.is(filter.getJobId())); DBQuery materialIds = new DBQuery(subcmd); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterial.id.in(materialIds.findQueryColumn(db.tableWorkflowMaterialInTask.materialId)) )); cmd.select(db.getValueExpr(filter.getJobId(), DataType.DECIMAL).as(db.tableWorkflowTask.jobId)); } else { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); } EmpireUtils.addOrderBy(cmd, filter.getSortBy(), db.tableWorkflowMaterial.id, false); DBReader reader = new DBReader(); try { reader.open(cmd, getConnection()); if (!reader.skipRows(filter.getOffset())) { return Collections.emptyList(); } ArrayList<MaterialView> viewItems = new ArrayList<MaterialView>(filter.getMaxCount()); for (Iterator<DBRecordData> it = reader.iterator(filter.getMaxCount()); it.hasNext();) { DBRecordData rec = it.next(); MaterialView view = new MaterialView(); rec.getBeanProperties(view); viewItems.add(view); } return viewItems; } finally { reader.close(); } } EmpireWorkflowMaterialDao(ProarcDatabase db); @Override T create(MaterialType type); @Override T find(BigDecimal id); @Override Job findJob(Material m); @Override List<MaterialView> view(MaterialFilter filter); @Override void update(Material m); @Override void addTaskReference(Material m, Task t, Way way); }
EmpireWorkflowMaterialDao extends EmpireDao implements WorkflowMaterialDao { @Override public List<MaterialView> view(MaterialFilter filter) { DBCommand cmd = db.createCommand(); cmd.select(db.tableWorkflowMaterial.getColumns()); cmd.select(db.tableWorkflowFolder.path); cmd.select(db.tableWorkflowDigObj.pid); List<DBColumn> physicalSelections = new ArrayList<DBColumn>(db.tableWorkflowPhysicalDoc.getColumns()); physicalSelections.remove(db.tableWorkflowPhysicalDoc.materialId); cmd.select(physicalSelections); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowFolder.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowDigObj.materialId, DBJoinType.LEFT); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowPhysicalDoc.materialId, DBJoinType.LEFT); if (filter.getId() != null) { cmd.where(db.tableWorkflowMaterial.id.is(filter.getId())); } if (filter.getType() != null) { cmd.addWhereConstraints(Collections.singletonList(db.tableWorkflowMaterial.type.is(filter.getType()))); } if (filter.getTaskId() != null) { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterialInTask.taskId.is(filter.getTaskId()) )); } else if (filter.getJobId() != null) { DBCommand subcmd = db.createCommand(); subcmd.select(db.tableWorkflowMaterialInTask.materialId); subcmd.selectDistinct(); subcmd.join(db.tableWorkflowMaterialInTask.taskId, db.tableWorkflowTask.id); subcmd.where(db.tableWorkflowTask.jobId.is(filter.getJobId())); DBQuery materialIds = new DBQuery(subcmd); cmd.addWhereConstraints(Collections.<DBCompareExpr>singletonList( db.tableWorkflowMaterial.id.in(materialIds.findQueryColumn(db.tableWorkflowMaterialInTask.materialId)) )); cmd.select(db.getValueExpr(filter.getJobId(), DataType.DECIMAL).as(db.tableWorkflowTask.jobId)); } else { cmd.select(db.tableWorkflowMaterialInTask.taskId); cmd.select(db.tableWorkflowMaterialInTask.way); cmd.join(db.tableWorkflowMaterial.id, db.tableWorkflowMaterialInTask.materialId); } EmpireUtils.addOrderBy(cmd, filter.getSortBy(), db.tableWorkflowMaterial.id, false); DBReader reader = new DBReader(); try { reader.open(cmd, getConnection()); if (!reader.skipRows(filter.getOffset())) { return Collections.emptyList(); } ArrayList<MaterialView> viewItems = new ArrayList<MaterialView>(filter.getMaxCount()); for (Iterator<DBRecordData> it = reader.iterator(filter.getMaxCount()); it.hasNext();) { DBRecordData rec = it.next(); MaterialView view = new MaterialView(); rec.getBeanProperties(view); viewItems.add(view); } return viewItems; } finally { reader.close(); } } EmpireWorkflowMaterialDao(ProarcDatabase db); @Override T create(MaterialType type); @Override T find(BigDecimal id); @Override Job findJob(Material m); @Override List<MaterialView> view(MaterialFilter filter); @Override void update(Material m); @Override void addTaskReference(Material m, Task t, Way way);  }