Search in sources :

Example 11 with PersistenceModule

use of org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule 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

PersistenceModule (org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule)11 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)5 CustomPersistenceHandler (org.broadleafcommerce.openadmin.server.service.handler.CustomPersistenceHandler)5 Entity (org.broadleafcommerce.openadmin.dto.Entity)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 PersistencePackage (org.broadleafcommerce.openadmin.dto.PersistencePackage)2 Property (org.broadleafcommerce.openadmin.dto.Property)2 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)2 RecordHelper (org.broadleafcommerce.openadmin.server.service.persistence.module.RecordHelper)2 Serializable (java.io.Serializable)1 PostConstruct (javax.annotation.PostConstruct)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 From (javax.persistence.criteria.From)1 Path (javax.persistence.criteria.Path)1 Predicate (javax.persistence.criteria.Predicate)1