use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method fetch.
@SuppressWarnings("unchecked")
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
// get the default properties from Sku and its subclasses
Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
// Pull back the Skus based on the criteria from the client
List<FilterMapping> filterMappings = helper.getFilterMappings(persistencePerspective, cto, ceilingEntityFullyQualifiedClassname, originalProps);
// allow subclasses to provide additional criteria before executing the query
applyProductOptionValueCriteria(filterMappings, cto, persistencePackage, null);
applySkuBundleItemValueCriteria(filterMappings, cto, persistencePackage);
applyAdditionalFetchCriteria(filterMappings, cto, persistencePackage);
List<Serializable> records = helper.getPersistentRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings, cto.getFirstResult(), cto.getMaxResults());
// Convert Skus into the client-side Entity representation
Entity[] payload = helper.getRecords(originalProps, records);
int totalRecords = helper.getTotalRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings);
// Now fill out the relevant properties for the product options for the Skus that were returned
updateProductOptionFieldsForFetch(records, payload);
return new DynamicResultSet(payload, totalRecords);
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping in project BroadleafCommerce by BroadleafCommerce.
the class ISOCountryPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty("name")).withDirectFilterValues(new EmptyFilterValues()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider<Character, Character>() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path<Character> explicitPath, List<Character> directValues) {
return builder.isNotNull(explicitPath);
}
}));
cto.getAdditionalFilterMappings().add(filterMapping);
FilterMapping countryRestrictionMapping = new FilterMapping().withDirectFilterValues(new EmptyFilterValues()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider<Character, Character>() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path<Character> explicitPath, List<Character> directValues) {
CriteriaQuery<Serializable> criteria = fieldPathBuilder.getCriteria();
Root<CountryImpl> blcCountry = criteria.from(CountryImpl.class);
Predicate join = builder.equal(root.get("alpha2").as(String.class), blcCountry.get("abbreviation").as(String.class));
return join;
}
}));
cto.getAdditionalFilterMappings().add(countryRestrictionMapping);
PersistenceModule myModule = helper.getCompatibleModule(persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType());
return myModule.fetch(persistencePackage, cto);
}
Aggregations