use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.converter.FilterValueConverter in project BroadleafCommerce by BroadleafCommerce.
the class BasicPersistenceModule method buildStandardRestrictions.
/**
* Generate LIKE or EQUALS restrictions for any filter property specified on the root entity (not the collection field in the @Embeddable object)
*
* @see #getSpecialCaseQueryBuilder(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath, java.util.List, String)
* @param embeddedCollectionPath the path for the collection field in the @Embeddable object - this is what caused the whole thing
* @param filterMappings all the fetch restrictions for this request
* @return the list of restrictions on the root entity
*/
protected List<TQRestriction> buildStandardRestrictions(FieldPath embeddedCollectionPath, List<FilterMapping> filterMappings) {
String expression = embeddedCollectionPath.getTargetProperty().substring(0, embeddedCollectionPath.getTargetProperty().lastIndexOf("."));
List<TQRestriction> restrictions = new ArrayList<TQRestriction>();
for (FilterMapping mapping : filterMappings) {
checkProperty: {
String mappingProperty = mapping.getFieldPath() == null ? null : mapping.getFieldPath().getTargetProperty();
if (StringUtils.isEmpty(mappingProperty)) {
mappingProperty = mapping.getFullPropertyName();
}
if (!embeddedCollectionPath.getTargetProperty().equals(mappingProperty) && !StringUtils.isEmpty(mappingProperty)) {
PredicateProvider predicateProvider = mapping.getRestriction().getPredicateProvider();
if (predicateProvider != null) {
FilterValueConverter converter = mapping.getRestriction().getFilterValueConverter();
if (converter != null && CollectionUtils.isNotEmpty(mapping.getFilterValues())) {
Object val = converter.convert(mapping.getFilterValues().get(0));
if (predicateProvider instanceof LikePredicateProvider) {
restrictions.add(new TQRestriction("specialEntity." + mappingProperty, "LIKE", val + "%"));
break checkProperty;
} else if (predicateProvider instanceof EqPredicateProvider) {
restrictions.add(new TQRestriction("specialEntity." + mappingProperty, "=", val));
break checkProperty;
}
}
}
LOG.warn(String.format("Unable to filter the embedded collection (%s) on an additional property (%s)", StringUtil.sanitize(expression), StringUtil.sanitize(mappingProperty)));
}
}
}
return restrictions;
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.converter.FilterValueConverter in project BroadleafCommerce by BroadleafCommerce.
the class BasicPersistenceModule method buildSpecialRestrictions.
/**
* Generate EQUALS restrictions for any filter property specified on the entity member of the collection field in the @Embeddable object
*
* @see #getSpecialCaseQueryBuilder(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath, java.util.List, String)
* @param specialExpression the String representation of the path for the collection field in the @Embeddable object
* @param filterMappings all the fetch restrictions for this request
* @return the list of restrictions on the collection in the @Embeddable object
*/
protected List<TQRestriction> buildSpecialRestrictions(String specialExpression, List<FilterMapping> filterMappings) {
List<TQRestriction> restrictions = new ArrayList<TQRestriction>();
for (FilterMapping mapping : filterMappings) {
if (mapping.getFieldPath() != null && mapping.getFieldPath().getTargetProperty() != null && mapping.getFieldPath().getTargetProperty().startsWith(specialExpression)) {
FilterValueConverter converter = mapping.getRestriction().getFilterValueConverter();
if (converter != null && CollectionUtils.isNotEmpty(mapping.getFilterValues())) {
Object val = converter.convert(mapping.getFilterValues().get(0));
String property = mapping.getFieldPath().getTargetProperty().substring(mapping.getFieldPath().getTargetProperty().lastIndexOf(".") + 1, mapping.getFieldPath().getTargetProperty().length());
restrictions.add(new TQRestriction("embeddedCollection." + property, "=", val));
}
}
}
return restrictions;
}
Aggregations