OrderQueryBuilder extends AbstractQueryBuilder<Order> { @Override protected BaseQueryBuilder build(final Order context, final BaseQueryBuilder builder) { return builder .where() .openBracket() .addAndCondition(ORDERTYPE_CONDITION, context.getOrderType()) .addAndCondition(EMPLOYEE_CONDITION, context.getEmployee()) .addAndCondition(ASSET_CONDITION, context.getAsset()) .addAndCondition(PARTNER_CONDITION, context.getPartner()) .addAndCondition(OPTYPE_CONDITION, context.getOpType()) .addAndCondition(DEPARTMENT_CONDITION, context.getDepartment()) .addAndCondition(REASON_CONDITION, context.getReason()) .addAndCondition(PARENT_CONDITION, context.getParent()) .addAndCondition(REASONTEXT_CONDITION, context.getReasonText()) .addAndCondition(DOCSERIES_CONDITION, context.getDocSeries()) .addAndCondition(DOCNUM_CONDITION, context.getDocNum()) .addAndCondition(DOCDATE_CONDITION, context.getDocDate()) .addAndCondition(DOCISSUED_CONDITION, context.getDocIssued()) .addAndCondition(EVDATE_CONDITION, context.getEvDate()) .addAndCondition(TITLE_CONDITION, context.getTitle()) .addAndCondition(DESCRIPTION_CONDITION, context.getDescription()) .addAndCondition(TIMEPERIOD_CONDITION, context.getTimePeriod()) .closeBracket(); }    }
@Test public void testBuild() throws Exception { Order context = new Order(); String expected = "SELECT e FROM Order e WHERE e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Order> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledSecurityCOnstraint() throws Exception { unit.setSecurity(false); Order context = new Order(); String expected = "SELECT e FROM Order e WHERE e.status=:status "; MultiplePagedSearch<Order> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledStatusConstraint() throws Exception { unit.setActive(false); Order context = new Order(); String expected = "SELECT e FROM Order e WHERE e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Order> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithDisabledDefaultConstraint() throws Exception { unit.setActive(false); unit.setSecurity(false); Order context = new Order(); String expected = "SELECT e FROM Order e "; MultiplePagedSearch<Order> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParameters() throws Exception { OrderType orderType = new OrderType(); Employee employee = new Employee(); Asset asset = new Asset(); Partner partner = new Partner(); OperationType opType = new OperationType(); Department department = new Department(); Reason reason = new Reason(); Order parent = new Order(); String reasonText = "fsdfsd"; String docSeries = "fdsfds"; String docNum = "fsdfds"; Date docDate = new Date(); String docIssued = "fdfds"; Date evDate = new Date(); Order context = new Order(); context.setOrderType(orderType); context.setEmployee(employee); context.setAsset(asset); context.setPartner(partner); context.setOpType(opType); context.setDepartment(department); context.setReason(reason); context.setParent(parent); context.setReasonText(reasonText); context.setDocSeries(docSeries); context.setDocNum(docNum); context.setDocDate(docDate); context.setDocIssued(docIssued); context.setEvDate(evDate); String expected = "SELECT e FROM Order e WHERE ( e.orderType = :orderType AND e.employee = :employee AND e.asset = :asset AND e.partner = :partner AND e.opType = :opType AND e.department = :department AND e.reason = :reason AND e.parent = :parent AND e.reasonText LIKE CONCAT('%',:reasonText,'%') AND e.docSeries LIKE CONCAT('%',:docSeries,'%') AND e.docNum LIKE CONCAT('%',:docNum,'%') AND e.docDate = :docDate AND e.docIssued LIKE CONCAT('%',:docIssued,'%') AND e.evDate = :evDate ) AND e.status=:status AND e.crtUserGroup IN (:userGroups) "; MultiplePagedSearch<Order> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }
@Test public void testBuildWithParametersAndDisabledDefaultConstraints() throws Exception { unit.setActive(false); unit.setSecurity(false); OrderType orderType = new OrderType(); Employee employee = new Employee(); Asset asset = new Asset(); Partner partner = new Partner(); OperationType opType = new OperationType(); Department department = new Department(); Reason reason = new Reason(); Order parent = new Order(); String reasonText = "fsdfsd"; String docSeries = "fdsfds"; String docNum = "fsdfds"; Date docDate = new Date(); String docIssued = "fdfds"; Date evDate = new Date(); Order context = new Order(); context.setOrderType(orderType); context.setEmployee(employee); context.setAsset(asset); context.setPartner(partner); context.setOpType(opType); context.setDepartment(department); context.setReason(reason); context.setParent(parent); context.setReasonText(reasonText); context.setDocSeries(docSeries); context.setDocNum(docNum); context.setDocDate(docDate); context.setDocIssued(docIssued); context.setEvDate(evDate); String expected = "SELECT e FROM Order e WHERE ( e.orderType = :orderType AND e.employee = :employee AND e.asset = :asset AND e.partner = :partner AND e.opType = :opType AND e.department = :department AND e.reason = :reason AND e.parent = :parent AND e.reasonText LIKE CONCAT('%',:reasonText,'%') AND e.docSeries LIKE CONCAT('%',:docSeries,'%') AND e.docNum LIKE CONCAT('%',:docNum,'%') AND e.docDate = :docDate AND e.docIssued LIKE CONCAT('%',:docIssued,'%') AND e.evDate = :evDate ) "; MultiplePagedSearch<Order> pagedSearch = new MultiplePagedSearch<>(); pagedSearch.setEntity(context); String actualQuery = unit.build(pagedSearch); assertEquals(expected, actualQuery); }