@Override @SuppressWarnings("unchecked") public List<PositionBaseBo> getPositions( String positionNum, String description, LocalDate fromEffdt, LocalDate toEffdt, String active, String showHistory) { List<PositionBaseBo> results = new ArrayList<PositionBaseBo>(); Criteria root = new Criteria(); if (StringUtils.isNotBlank(positionNum)) { root.addLike("positionNumber", positionNum); } if (StringUtils.isNotBlank(description)) { root.addLike("UPPER(description)", description.toUpperCase()); // KPME-2695 } Criteria effectiveDateFilter = new Criteria(); if (fromEffdt != null) { effectiveDateFilter.addGreaterOrEqualThan("effectiveDate", fromEffdt.toDate()); } if (toEffdt != null) { effectiveDateFilter.addLessOrEqualThan("effectiveDate", toEffdt.toDate()); } if (fromEffdt == null && toEffdt == null) { effectiveDateFilter.addLessOrEqualThan("effectiveDate", LocalDate.now().toDate()); } root.addAndCriteria(effectiveDateFilter); if (StringUtils.isNotBlank(active)) { Criteria activeFilter = new Criteria(); if (StringUtils.equals(active, "Y")) { activeFilter.addEqualTo("active", true); } else if (StringUtils.equals(active, "N")) { activeFilter.addEqualTo("active", false); } root.addAndCriteria(activeFilter); } if (StringUtils.equals(showHistory, "N")) { root.addEqualTo( "effectiveDate", OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter( PositionBaseBo.class, effectiveDateFilter, PositionBaseBo.BUSINESS_KEYS, false)); root.addEqualTo( "timestamp", OjbSubQueryUtil.getTimestampSubQuery( PositionBaseBo.class, PositionBaseBo.BUSINESS_KEYS, false)); } Query query = QueryFactory.newQuery(PositionBaseBo.class, root); results.addAll(getPersistenceBrokerTemplate().getCollectionByQuery(query)); return results; }
@SuppressWarnings({"rawtypes", "unchecked"}) private void injectSubQueries( Criteria root, Class<? extends HrBusinessObjectContract> hrBOClass, Map formProps) { // create the effective date filter criteria Criteria effectiveDateFilter = new Criteria(); LocalDate fromEffdt = TKUtils.formatDateString(TKUtils.getFromDateString((String) formProps.get(EFFECTIVE_DATE))); LocalDate toEffdt = TKUtils.formatDateString(TKUtils.getToDateString((String) formProps.get(EFFECTIVE_DATE))); if (fromEffdt != null) { effectiveDateFilter.addGreaterOrEqualThan(EFFECTIVE_DATE, fromEffdt.toDate()); } if (toEffdt != null) { effectiveDateFilter.addLessOrEqualThan(EFFECTIVE_DATE, toEffdt.toDate()); } if (fromEffdt == null && toEffdt == null) { effectiveDateFilter.addLessOrEqualThan(EFFECTIVE_DATE, LocalDate.now().toDate()); } List<String> businessKeys = new ArrayList<String>(); try { businessKeys = (List<String>) hrBOClass.getDeclaredField(BUSINESS_KEYS_VAR_NAME).get(hrBOClass); } catch (NoSuchFieldException e) { LOG.warn(hrBOClass.getName() + DOES_NOT_CONTAIN_BUSINESS_KEYS_MESSAGE); } catch (IllegalAccessException e) { LOG.warn(hrBOClass.getName() + DOES_NOT_CONTAIN_BUSINESS_KEYS_MESSAGE); } // inject the subqueries root.addEqualTo( EFFECTIVE_DATE, OjbSubQueryUtil.getEffectiveDateSubQueryWithFilter( hrBOClass, effectiveDateFilter, businessKeys, false)); root.addEqualTo( TIMESTAMP, OjbSubQueryUtil.getTimestampSubQuery(hrBOClass, businessKeys, false)); }