Search in sources :

Example 6 with EmptyFilterValues

use of org.broadleafcommerce.openadmin.server.service.persistence.module.EmptyFilterValues 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);
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Path(javax.persistence.criteria.Path) FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) Serializable(java.io.Serializable) FieldPath(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) From(javax.persistence.criteria.From) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) FieldPathBuilder(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder) Predicate(javax.persistence.criteria.Predicate) EmptyFilterValues(org.broadleafcommerce.openadmin.server.service.persistence.module.EmptyFilterValues) Restriction(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.Restriction) PredicateProvider(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.predicate.PredicateProvider) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) List(java.util.List)

Aggregations

EmptyFilterValues (org.broadleafcommerce.openadmin.server.service.persistence.module.EmptyFilterValues)6 List (java.util.List)5 Path (javax.persistence.criteria.Path)5 FieldPath (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPath)5 FilterMapping (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping)5 Restriction (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.Restriction)5 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 From (javax.persistence.criteria.From)4 FieldPathBuilder (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder)4 PredicateProvider (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.predicate.PredicateProvider)4 Predicate (javax.persistence.criteria.Predicate)3 FilterAndSortCriteria (org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria)3 ArrayList (java.util.ArrayList)2 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 Date (java.util.Date)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)1 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)1 AdornedTargetList (org.broadleafcommerce.openadmin.dto.AdornedTargetList)1