private List<Predicate> getValuePredicate(StoredQueryParam param, StringPath valuePath) { List<Predicate> predicates = new ArrayList<Predicate>(); List<String> values; for (int i = 0, len = param.getNumberOfANDElements(); i < len; i++) { values = param.isMultiValue() ? param.getMultiValues(i) : Arrays.asList(param.getStringValue()); BooleanBuilder predicate = new BooleanBuilder(); List<String> eqValues = new ArrayList<String>(); for (String v : values) { if (v.indexOf('%') != -1 || v.indexOf('_') != -1) { predicate.or(valuePath.like(v)); } else { eqValues.add(v); } } if (eqValues.size() > 0) { if (eqValues.size() > 1) { predicate.or(valuePath.in(eqValues)); } else { predicate.or(valuePath.eq(eqValues.get(0))); } } predicates.add(predicate); } return predicates; }
/** * Add code matches in XDS form using XDSCode entity * * @param builder BooleanBuilder to add matches for given code parameter * @param codeParam Stored Query Parameter with code values * @param codeType The classification of the codes (Classification.classificationScheme) * @param xdsCodes The CollectionPath for XDSCodes of parent select (to bind subselect) * @throws XDSException */ protected void addXdsCodeMatch( BooleanBuilder builder, StoredQueryParam codeParam, String codeClassification, CollectionPath<XDSCode, QXDSCode> xdsCodes) throws XDSException { if (codeParam != null) { List<String> codeValues; String[] codeAndScheme; for (int i = 0, len = codeParam.getNumberOfANDElements(); i < len; i++) { codeValues = codeParam.getMultiValues(i); BooleanBuilder codesBuilder = new BooleanBuilder(); for (int j = 0, jLen = codeValues.size(); j < jLen; j++) { codeAndScheme = toCodeValueAndScheme(codeValues.get(j)); codesBuilder.or( ExpressionUtils.allOf( QXDSCode.xDSCode.codeClassification.eq(codeClassification), QXDSCode.xDSCode.codeValue.eq(codeAndScheme[0]), QXDSCode.xDSCode.codingSchemeDesignator.eq(codeAndScheme[1]))); } builder.and( new JPASubQuery() .from(QXDSCode.xDSCode) .where(QXDSCode.xDSCode.in(xdsCodes), codesBuilder) .exists()); } } }
/** * Adds a match against RegistryObjectIndex, i.e. the indexed fields from the blob xml. </br> Uses * OR for multi values and LIKE to match. */ protected void addIndexMatch( BooleanBuilder builder, NumberPath<Long> registryObjectPk, StoredQueryParam param, XDSSearchIndexKey key) { // No match needed if param not specified if (param == null) return; QRegistryObjectIndex index = QRegistryObjectIndex.registryObjectIndex; // perform an OR for the list of values in QueryParam BooleanExpression orExpr; BooleanBuilder andBuilder = new BooleanBuilder(); List<String> values; for (int i = 0, len = param.getNumberOfANDElements(); i < len; i++) { orExpr = null; if (param.isMultiValue()) { values = param.getMultiValues(i); for (String val : values) orExpr = orExpr == null ? index.value.like(val) : orExpr.or(index.value.like(val)); } else { orExpr = index.value.like(param.getStringValue()); } andBuilder.and(orExpr); } // add this expression as subquery JPASubQuery subq = new JPASubQuery() .from(index) .where(index.subject.pk.eq(registryObjectPk).and(index.key.eq(key)).and(andBuilder)); builder.and(subq.exists()); }
protected void addStatusMatch( BooleanBuilder builder, StringPath status, StoredQueryParam statusParam) { List<String> stati = statusParam.getMultiValues(0); if (stati == null) { builder.and(status.eq(statusParam.getStringValue())); } else if (stati.size() == 1) { builder.and(status.eq(stati.get(0))); } else if (stati.size() > 1) { builder.and(status.in(stati)); } }