LookupCriteriaGeneratorImpl implements LookupCriteriaGenerator { @Override @Deprecated public QueryByCriteria.Builder generateCriteria(Class<?> type, Map<String, String> formProps, boolean usePrimaryKeysOnly) { if (usePrimaryKeysOnly) { return getCollectionCriteriaFromMapUsingPrimaryKeysOnly(type, instantiateLookupDataObject(type), formProps).toQueryBuilder(); } else { return getCollectionCriteriaFromMap(type, instantiateLookupDataObject(type), formProps).toQueryBuilder(); } }  DateTimeService getDateTimeService(); void setDateTimeService(DateTimeService dateTimeService); DataDictionaryService getDataDictionaryService(); void setDataDictionaryService(DataDictionaryService dataDictionaryService); DatabasePlatform getDbPlatform(); void setDbPlatform(DatabasePlatform dbPlatform); DataObjectService getDataObjectService(); void setDataObjectService(DataObjectService dataObjectService); @Override @Deprecated QueryByCriteria.Builder generateCriteria(Class<?> type, Map<String, String> formProps, boolean usePrimaryKeysOnly); @Override QueryByCriteria.Builder generateCriteria(Class<?> type, Map<String, String> formProps,
            List<String> wildcardAsLiteralPropertyNames, boolean usePrimaryKeysOnly); @Override QueryByCriteria.Builder createObjectCriteriaFromMap(Object example, Map<String, String> formProps); boolean createCriteria(Object example, String searchValue, String propertyName, boolean caseInsensitive, boolean treatWildcardsAndOperatorsAsLiteral, Predicates criteria);  }
@Test public void testGenerateCriteria_MultipleOr() throws Exception { Map<String, String> mapCriteria = new HashMap<String, String>(); mapCriteria.put("prop1", "a|b"); mapCriteria.put("prop2", "c"); mapCriteria.put("prop3", "d"); QueryByCriteria.Builder qbcBuilder = generator.generateCriteria(TestClass.class, mapCriteria, false); assertNotNull("build should not have been null", qbcBuilder); QueryByCriteria qbc = qbcBuilder.build(); Predicate and = qbc.getPredicate(); assertTrue("top level predicate type incorrect. Was: " + and, and instanceof AndPredicate); Set<Predicate> predicates = ((AndPredicate) and).getPredicates(); assertEquals("Wrong number of top-level predicates", 3, predicates.size()); boolean foundProp1 = false; boolean foundProp2 = false; boolean foundProp3 = false; for (Predicate predicate : predicates) { if (predicate instanceof LikePredicate) { LikePredicate like = (LikePredicate)predicate; if (like.getPropertyPath().equals("prop2")) { assertEquals("prop2 had wrong value", "c", like.getValue().getValue()); foundProp2 = true; } else { fail("Invalid like predicate encountered: " + predicate); } } else if (predicate instanceof LikeIgnoreCasePredicate) { LikeIgnoreCasePredicate like = (LikeIgnoreCasePredicate)predicate; if (like.getPropertyPath().equals("prop3")) { assertEquals("prop3 had wrong value", "d", like.getValue().getValue()); foundProp3 = true; } else { fail("Invalid likeIgnoreCase predicate encountered: " + predicate); } } else if (predicate instanceof OrPredicate) { foundProp1 = true; OrPredicate orPredicate = (OrPredicate)predicate; assertEquals("wrong number of predicates in the internal OR predicate",2, orPredicate.getPredicates().size()); for (Predicate orSubPredicate : orPredicate.getPredicates()) { if (orSubPredicate instanceof LikeIgnoreCasePredicate) { LikeIgnoreCasePredicate likeInternal = (LikeIgnoreCasePredicate)orSubPredicate; if (likeInternal.getPropertyPath().equals("prop1")) { assertTrue("prop1 had wrong value", "a".equals(likeInternal.getValue().getValue()) || "b".equals(likeInternal.getValue().getValue())); } else { fail("Invalid predicate, does not have a propertypath of prop1:" + predicate); } } else { fail("Unexpected predicate: " + orSubPredicate); } } } else { fail("Unexpected predicate: " + predicate); } } assertTrue("prop1 predicate missing", foundProp1); assertTrue("prop2 predicate missing", foundProp2); assertTrue("prop3 predicate missing", foundProp3); }
@Test public void testGenerateCriteria_BetweenDate() { String lowerDateString = "1/1/2010"; DateTime lowerDate = DateTime.parse(lowerDateString, formatter).withTimeAtStartOfDay(); String upperDateString = "1/2/2010"; DateTime upperDate = DateTime.parse(upperDateString, formatter).withTimeAtStartOfDay(); Map<String, String> mapCriteria = new HashMap<String, String>(); mapCriteria.put("prop4", lowerDateString + SearchOperator.BETWEEN.op() + upperDateString); QueryByCriteria.Builder qbcBuilder = generator.generateCriteria(TestClass.class, mapCriteria, false); assertNotNull(qbcBuilder); QueryByCriteria qbc = qbcBuilder.build(); Predicate and = qbc.getPredicate(); assertTrue(and instanceof AndPredicate); Set<Predicate> predicates = ((AndPredicate) and).getPredicates(); assertEquals(2, predicates.size()); boolean foundProp4Lower = false; boolean foundProp4Upper = false; for (Predicate predicate : predicates) { if (predicate instanceof GreaterThanOrEqualPredicate) { foundProp4Lower = true; GreaterThanOrEqualPredicate greaterThanOrEqual = (GreaterThanOrEqualPredicate) predicate; assertEquals(greaterThanOrEqual.getValue().getValue(), lowerDate); } else if (predicate instanceof LessThanOrEqualPredicate) { foundProp4Upper = true; LessThanOrEqualPredicate lessThanOrEqual = (LessThanOrEqualPredicate) predicate; assertEquals(lessThanOrEqual.getValue().getValue(), upperDate.plusDays(1)); } } assertTrue(foundProp4Lower); assertTrue(foundProp4Upper); }
@Test public void testGenerateCriteria_GreaterThanEqualDate() { String dateString = "1/1/2010"; DateTime date = DateTime.parse(dateString, formatter).withTimeAtStartOfDay(); Map<String, String> mapCriteria = new HashMap<String, String>(); mapCriteria.put("prop4", SearchOperator.GREATER_THAN_EQUAL.op() + dateString); QueryByCriteria.Builder qbcBuilder = generator.generateCriteria(TestClass.class, mapCriteria, false); assertNotNull(qbcBuilder); QueryByCriteria qbc = qbcBuilder.build(); Predicate greaterThanEqual = qbc.getPredicate(); assertTrue(greaterThanEqual instanceof GreaterThanOrEqualPredicate); assertEquals(((GreaterThanOrEqualPredicate) greaterThanEqual).getValue().getValue(), date); }
@Test public void testGenerateCriteria_LessThanEqualDate() { String dateString = "1/2/2010"; DateTime date = DateTime.parse(dateString, formatter).withTimeAtStartOfDay(); Map<String, String> mapCriteria = new HashMap<String, String>(); mapCriteria.put("prop4", SearchOperator.LESS_THAN_EQUAL.op() + dateString); QueryByCriteria.Builder qbcBuilder = generator.generateCriteria(TestClass.class, mapCriteria, false); assertNotNull(qbcBuilder); QueryByCriteria qbc = qbcBuilder.build(); Predicate lessThanEqual = qbc.getPredicate(); assertTrue(lessThanEqual instanceof LessThanOrEqualPredicate); assertEquals(((LessThanOrEqualPredicate) lessThanEqual).getValue().getValue(), date.plusDays(1)); }
@Test public void testGenerateCriteria_GreaterThanDate() { String dateString = "1/1/2010"; DateTime date = DateTime.parse(dateString, formatter).withTimeAtStartOfDay(); Map<String, String> mapCriteria = new HashMap<String, String>(); mapCriteria.put("prop4", SearchOperator.GREATER_THAN.op() + dateString); QueryByCriteria.Builder qbcBuilder = generator.generateCriteria(TestClass.class, mapCriteria, false); assertNotNull(qbcBuilder); QueryByCriteria qbc = qbcBuilder.build(); Predicate greaterThan = qbc.getPredicate(); assertTrue(greaterThan instanceof GreaterThanPredicate); assertEquals(((GreaterThanPredicate) greaterThan).getValue().getValue(), date); }
@Test public void testGenerateCriteria_LessThanDate() { String dateString = "1/2/2010"; DateTime date = DateTime.parse(dateString, formatter).withTimeAtStartOfDay(); Map<String, String> mapCriteria = new HashMap<String, String>(); mapCriteria.put("prop4", SearchOperator.LESS_THAN.op() + dateString); QueryByCriteria.Builder qbcBuilder = generator.generateCriteria(TestClass.class, mapCriteria, false); assertNotNull(qbcBuilder); QueryByCriteria qbc = qbcBuilder.build(); Predicate lessThan = qbc.getPredicate(); assertTrue(lessThan instanceof LessThanPredicate); assertEquals(((LessThanPredicate) lessThan).getValue().getValue(), date); }