use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetListPersistenceModule method getAdornedTargetFilterMappings.
public List<FilterMapping> getAdornedTargetFilterMappings(PersistencePerspective persistencePerspective, CriteriaTransferObject cto, Map<String, FieldMetadata> mergedProperties, AdornedTargetList adornedTargetList) throws ClassNotFoundException {
List<FilterMapping> filterMappings = getFilterMappings(persistencePerspective, cto, adornedTargetList.getAdornedTargetEntityClassname(), mergedProperties);
FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty(adornedTargetList.getLinkedObjectPath() + "." + adornedTargetList.getLinkedIdProperty())).withFilterValues(cto.get(adornedTargetList.getCollectionFieldName()).getFilterValues()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider<Serializable, String>() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path<Serializable> explicitPath, List<String> directValues) {
if (String.class.isAssignableFrom(explicitPath.getJavaType())) {
return builder.equal(explicitPath, directValues.get(0));
} else {
return builder.equal(explicitPath, Long.parseLong(directValues.get(0)));
}
}
}));
filterMappings.add(filterMapping);
FilterMapping filterMapping2 = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty(adornedTargetList.getTargetObjectPath() + "." + adornedTargetList.getTargetIdProperty())).withFilterValues(cto.get(adornedTargetList.getCollectionFieldName() + "Target").getFilterValues()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider<Serializable, String>() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path<Serializable> explicitPath, List<String> directValues) {
if (String.class.isAssignableFrom(explicitPath.getJavaType())) {
return builder.equal(explicitPath, directValues.get(0));
} else {
return builder.equal(explicitPath, Long.parseLong(directValues.get(0)));
}
}
}));
filterMappings.add(filterMapping2);
return filterMappings;
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class ProductCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
boolean legacy = parentCategoryLegacyModeService.isLegacyMode();
// which seeks matching values in allParentCategoryXRefs instead
if (!legacy) {
FilterAndSortCriteria fsc = cto.getCriteriaMap().get("defaultCategory");
if (fsc != null) {
List<String> filterValues = fsc.getFilterValues();
cto.getCriteriaMap().remove("defaultCategory");
List<Long> transformedValues = BLCCollectionUtils.collectList(filterValues, new TypedTransformer<Long>() {
@Override
public Long transform(Object input) {
return Long.parseLong(((String) input));
}
});
CriteriaBuilder builder = dynamicEntityDao.getStandardEntityManager().getCriteriaBuilder();
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<CategoryProductXrefImpl> root = criteria.from(CategoryProductXrefImpl.class);
criteria.select(root.get("product").get("id").as(Long.class));
List<Predicate> restrictions = new ArrayList<Predicate>();
restrictions.add(builder.equal(root.get("defaultReference"), Boolean.TRUE));
if (CollectionUtils.isNotEmpty(transformedValues)) {
restrictions.add(root.get("category").get("id").in(transformedValues));
}
criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
TypedQuery<Long> query = dynamicEntityDao.getStandardEntityManager().createQuery(criteria);
List<Long> productIds = query.getResultList();
productIds = sandBoxHelper.mergeCloneIds(ProductImpl.class, productIds.toArray(new Long[productIds.size()]));
if (productIds.size() == 0) {
return new DynamicResultSet(null, new Entity[0], 0);
}
if (productIds.size() <= queryLimit) {
FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty("id")).withDirectFilterValues(productIds).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.in(directValues);
}
}));
cto.getAdditionalFilterMappings().add(filterMapping);
} else {
String joined = StringUtils.join(transformedValues, ',');
LOG.warn(String.format("Skipping default category filtering for product fetch query since there are " + "more than " + queryLimit + " products found to belong to the selected default categories(%s). This is a " + "filter query limitation.", joined));
}
}
}
if (eagerFetchAssociations) {
cto.getNonCountAdditionalFilterMappings().add(new FilterMapping().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) {
root.fetch("defaultSku", JoinType.LEFT);
root.fetch("defaultCategory", JoinType.LEFT);
return null;
}
})));
}
return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class ProductOptionValuesCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Long optionId = getOptionKey(persistencePackage);
if (optionId != null) {
FilterMapping filterMapping = new FilterMapping().withDirectFilterValues(sandBoxHelper.mergeCloneIds(ProductOptionImpl.class, optionId)).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
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);
}
}));
cto.getAdditionalFilterMappings().add(filterMapping);
}
return helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class ArchiveStatusPersistenceEventHandler method preFetch.
@Override
public PersistenceManagerEventHandlerResponse preFetch(PersistenceManager persistenceManager, PersistencePackage persistencePackage, CriteriaTransferObject cto) throws ServiceException {
try {
Class<?>[] entityClasses = persistenceManager.getDynamicEntityDao().getAllPolymorphicEntitiesFromCeiling(Class.forName(persistencePackage.getCeilingEntityFullyQualifiedClassname()));
AtomicBoolean isArchivable = new AtomicBoolean(false);
for (Class<?> entity : entityClasses) {
AtomicBoolean test = new AtomicBoolean(true);
extensionManager.getProxy().isArchivable(entity, test);
if (!test.get()) {
isArchivable.set(false);
break;
}
if (Status.class.isAssignableFrom(entity)) {
isArchivable.set(true);
}
}
if (isArchivable.get() && !persistencePackage.getPersistencePerspective().getShowArchivedFields()) {
String targetPropertyName = "archiveStatus.archived";
if (persistencePackage.getPersistencePerspectiveItems().containsKey(PersistencePerspectiveItemType.ADORNEDTARGETLIST)) {
AdornedTargetList atl = (AdornedTargetList) persistencePackage.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
targetPropertyName = atl.getTargetObjectPath() + "." + targetPropertyName;
}
FilterMapping filterMapping = new FilterMapping().withFieldPath(new FieldPath().withTargetProperty(targetPropertyName)).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.or(builder.equal(explicitPath, 'N'), builder.isNull(explicitPath));
}
}));
cto.getAdditionalFilterMappings().add(filterMapping);
}
return new PersistenceManagerEventHandlerResponse().withStatus(PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.HANDLED);
} catch (ClassNotFoundException e) {
LOG.error("Could not find the class " + persistencePackage.getCeilingEntityFullyQualifiedClassname() + " to " + "compute polymorphic entity types for. Assuming that the entity is not archivable");
return new PersistenceManagerEventHandlerResponse().withStatus(PersistenceManagerEventHandlerResponse.PersistenceManagerEventHandlerResponseStatus.NOT_HANDLED);
}
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FieldPathBuilder in project BroadleafCommerce by BroadleafCommerce.
the class IndexFieldCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
FilterAndSortCriteria fieldFsc = cto.getCriteriaMap().get("field");
if (fieldFsc != null) {
List<String> filterValues = fieldFsc.getFilterValues();
cto.getCriteriaMap().remove("field");
cto.getAdditionalFilterMappings().add(new FilterMapping().withFieldPath(new FieldPath().withTargetProperty("field.friendlyName")).withFilterValues(filterValues).withSortDirection(fieldFsc.getSortDirection()).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.like(explicitPath.as(String.class), "%" + directValues.get(0) + "%");
}
})));
}
DynamicResultSet resultSet = helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
return resultSet;
}
Aggregations