use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method addIsActiveFiltering.
protected void addIsActiveFiltering(CriteriaTransferObject cto) {
if (isActiveFilter && cto.getCriteriaMap().containsKey(IS_ACTIVE)) {
FilterAndSortCriteria filter = cto.get(IS_ACTIVE);
final Boolean isActive = Boolean.parseBoolean(filter.getFilterValues().get(0));
FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty("id")).withDirectFilterValues(new EmptyFilterValues()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
Date currentTime = SystemTime.asDate(true);
if (isActive) {
return builder.and(builder.isNotNull(root.get("startDate")), builder.lessThan(root.get("startDate"), currentTime), builder.or(builder.isNull(root.get("endDate")), builder.greaterThan(root.get("endDate"), currentTime)));
} else {
return builder.or(builder.isNull(root.get("startDate")), builder.greaterThan(root.get("startDate"), currentTime), builder.and(builder.isNotNull(root.get("endDate")), builder.lessThan(root.get("endDate"), currentTime)));
}
}
}));
cto.getAdditionalFilterMappings().add(filterMapping);
}
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method applyProductOptionValueCriteria.
public void applyProductOptionValueCriteria(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage, String skuPropertyPrefix) {
// if the front
final List<Long> productOptionValueFilterIDs = new ArrayList<>();
for (String filterProperty : cto.getCriteriaMap().keySet()) {
if (filterProperty.startsWith(PRODUCT_OPTION_FIELD_PREFIX)) {
FilterAndSortCriteria criteria = cto.get(filterProperty);
productOptionValueFilterIDs.add(Long.parseLong(criteria.getFilterValues().get(0)));
}
}
// also determine if there is a consolidated POV query
final List<String> productOptionValueFilterValues = new ArrayList<>();
FilterAndSortCriteria consolidatedCriteria = cto.get(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);
if (!consolidatedCriteria.getFilterValues().isEmpty()) {
// the criteria in this case would be a semi-colon delimeter value list
productOptionValueFilterValues.addAll(Arrays.asList(StringUtils.split(consolidatedCriteria.getFilterValues().get(0), CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER)));
}
if (productOptionValueFilterIDs.size() > 0) {
FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty(StringUtils.isEmpty(skuPropertyPrefix) ? "" : skuPropertyPrefix + ".productOptionValueXrefs.productOptionValue.id")).withDirectFilterValues(productOptionValueFilterIDs).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
return explicitPath.as(Long.class).in(directValues);
}
}));
filterMappings.add(filterMapping);
}
if (productOptionValueFilterValues.size() > 0) {
FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty(StringUtils.isEmpty(skuPropertyPrefix) ? "" : skuPropertyPrefix + ".productOptionValueXrefs.productOptionValue.attributeValue")).withDirectFilterValues(productOptionValueFilterValues).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
return explicitPath.as(String.class).in(directValues);
}
}));
filterMappings.add(filterMapping);
}
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method createToOneIndividualOptionField.
/**
* Using a ToOne lookup performs much better for large product option value lists, speeds up initial page load,
* and is generally more accurate in relation to option value updates and how they impact available selections and cache.
*
* @param option
* @param order
* @return
*/
protected FieldMetadata createToOneIndividualOptionField(ProductOption option, int order) {
PersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
FilterMapping filterMapping = new FilterMapping().withDirectFilterValues(sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, option.getId())).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
return root.get("productOption").get("id").in(directValues);
}
}));
List<FilterMapping> mappings = new ArrayList<>();
mappings.add(filterMapping);
TypedQuery<Serializable> countQuery = criteriaTranslator.translateCountQuery(persistenceManager.getDynamicEntityDao(), ProductOptionValueImpl.class.getName(), mappings);
Long count = (Long) countQuery.getSingleResult();
BasicFieldMetadata metadata = null;
if (count > 0) {
metadata = new BasicFieldMetadata();
metadata.setFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
metadata.setSecondaryType(SupportedFieldType.INTEGER);
metadata.setForeignKeyProperty("id");
metadata.setForeignKeyClass(ProductOptionValueImpl.class.getName());
metadata.setForeignKeyDisplayValueProperty("attributeValue");
metadata.setLookupDisplayProperty("attributeValue");
metadata.setForeignKeyCollection(false);
metadata.setCustomCriteria(new String[] { "option=" + String.valueOf(option.getId()) });
metadata.setName(PRODUCT_OPTION_FIELD_PREFIX + option.getId());
metadata.setFriendlyName(option.getLabel());
metadata.setGroup("productOption_group");
metadata.setGroupOrder(-1);
metadata.setOrder(order);
metadata.setExplicitFieldType(SupportedFieldType.ADDITIONAL_FOREIGN_KEY);
metadata.setProminent(false);
metadata.setVisibility(VisibilityEnum.FORM_EXPLICITLY_SHOWN);
metadata.setReadOnly(false);
// these may not be actually required, but the CPH has this as a requirement for parsing the data, so we'll stick with it here
metadata.setRequiredOverride(true);
metadata.setLookupType(LookupType.STANDARD);
metadata.setMutable(true);
metadata.setInheritedFromType(SkuImpl.class.getName());
metadata.setAvailableToTypes(getPolymorphicClasses(SkuImpl.class, em, skuMetadataCacheService.useCache()));
metadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
metadata.setTargetClass(SkuImpl.class.getName());
metadata.setFieldName(PRODUCT_OPTION_FIELD_PREFIX + option.getId());
}
return metadata;
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method applySkuBundleItemValueCriteria.
/**
* Add filter restriction such that a ProductBundle cannot add its own default sku as a Sku Bundle Item
*/
private void applySkuBundleItemValueCriteria(List<FilterMapping> filterMappings, CriteriaTransferObject cto, PersistencePackage persistencePackage) {
SectionCrumb[] sectionCrumbs = persistencePackage.getSectionCrumbs();
if (isSkuBundleItemLookup(persistencePackage, sectionCrumbs)) {
final Long defaultSkuId = getOwningProductBundlesDefaultSkuId(sectionCrumbs[0]);
filterMappings.add(new FilterMapping().withDirectFilterValues(Collections.singletonList(defaultSkuId)).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
return builder.notEqual(root, directValues.get(0));
}
})));
}
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder 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