use of org.broadleafcommerce.openadmin.dto.AdornedTargetList in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetCollectionFieldMetadataProvider method addMetadataFromFieldType.
@Override
public MetadataProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) {
if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) {
return MetadataProviderResponse.NOT_HANDLED;
}
super.addMetadataFromFieldType(addMetadataFromFieldTypeRequest, metadata);
// add additional adorned target support
AdornedTargetCollectionMetadata fieldMetadata = (AdornedTargetCollectionMetadata) addMetadataFromFieldTypeRequest.getPresentationAttribute();
if (StringUtils.isEmpty(fieldMetadata.getCollectionCeilingEntity())) {
fieldMetadata.setCollectionCeilingEntity(addMetadataFromFieldTypeRequest.getType().getReturnedClass().getName());
AdornedTargetList targetList = ((AdornedTargetList) fieldMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST));
targetList.setAdornedTargetEntityClassname(fieldMetadata.getCollectionCeilingEntity());
}
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.dto.AdornedTargetList in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetCollectionFieldMetadataProvider method buildAdornedTargetCollectionMetadata.
protected void buildAdornedTargetCollectionMetadata(Class<?> parentClass, Class<?> targetClass, Map<String, FieldMetadata> attributes, FieldInfo field, FieldMetadataOverride adornedTargetCollectionMetadata, DynamicEntityDao dynamicEntityDao) {
AdornedTargetCollectionMetadata serverMetadata = (AdornedTargetCollectionMetadata) attributes.get(field.getName());
Class<?> resolvedClass = parentClass == null ? targetClass : parentClass;
AdornedTargetCollectionMetadata metadata;
if (serverMetadata != null) {
metadata = serverMetadata;
} else {
metadata = new AdornedTargetCollectionMetadata();
}
metadata.setTargetClass(targetClass.getName());
metadata.setFieldName(field.getName());
if (adornedTargetCollectionMetadata.getReadOnly() != null) {
metadata.setMutable(!adornedTargetCollectionMetadata.getReadOnly());
}
if (adornedTargetCollectionMetadata.getShowIfProperty() != null) {
metadata.setShowIfProperty(adornedTargetCollectionMetadata.getShowIfProperty());
}
if (adornedTargetCollectionMetadata.getShowIfFieldEquals() != null) {
metadata.setShowIfFieldEquals(adornedTargetCollectionMetadata.getShowIfFieldEquals());
}
org.broadleafcommerce.openadmin.dto.OperationTypes dtoOperationTypes = new org.broadleafcommerce.openadmin.dto.OperationTypes(OperationType.ADORNEDTARGETLIST, OperationType.ADORNEDTARGETLIST, OperationType.ADORNEDTARGETLIST, OperationType.ADORNEDTARGETLIST, OperationType.BASIC);
if (adornedTargetCollectionMetadata.getAddType() != null) {
dtoOperationTypes.setAddType(adornedTargetCollectionMetadata.getAddType());
}
if (adornedTargetCollectionMetadata.getRemoveType() != null) {
dtoOperationTypes.setRemoveType(adornedTargetCollectionMetadata.getRemoveType());
}
if (adornedTargetCollectionMetadata.getFetchType() != null) {
dtoOperationTypes.setFetchType(adornedTargetCollectionMetadata.getFetchType());
}
if (adornedTargetCollectionMetadata.getInspectType() != null) {
dtoOperationTypes.setInspectType(adornedTargetCollectionMetadata.getInspectType());
}
if (adornedTargetCollectionMetadata.getUpdateType() != null) {
dtoOperationTypes.setUpdateType(adornedTargetCollectionMetadata.getUpdateType());
}
// don't allow additional non-persistent properties or additional foreign keys for an advanced collection datasource - they don't make sense in this context
PersistencePerspective persistencePerspective;
if (serverMetadata != null) {
persistencePerspective = metadata.getPersistencePerspective();
persistencePerspective.setOperationTypes(dtoOperationTypes);
} else {
persistencePerspective = new PersistencePerspective(dtoOperationTypes, new String[] {}, new ForeignKey[] {});
metadata.setPersistencePerspective(persistencePerspective);
}
String parentObjectProperty = null;
if (serverMetadata != null) {
parentObjectProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getLinkedObjectPath();
}
if (!StringUtils.isEmpty(adornedTargetCollectionMetadata.getParentObjectProperty())) {
parentObjectProperty = adornedTargetCollectionMetadata.getParentObjectProperty();
}
if (parentObjectProperty == null && !StringUtils.isEmpty(field.getOneToManyMappedBy())) {
parentObjectProperty = field.getOneToManyMappedBy();
}
if (parentObjectProperty == null && !StringUtils.isEmpty(field.getManyToManyMappedBy())) {
parentObjectProperty = field.getManyToManyMappedBy();
}
if (StringUtils.isEmpty(parentObjectProperty)) {
throw new IllegalArgumentException("Unable to infer a parentObjectProperty for the @AdminPresentationAdornedTargetCollection annotated field(" + field.getName() + "). If not using the mappedBy property of @OneToMany or @ManyToMany, please make sure to explicitly define the parentObjectProperty property");
}
String sortProperty = null;
if (serverMetadata != null) {
sortProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getSortField();
}
if (!StringUtils.isEmpty(adornedTargetCollectionMetadata.getSortProperty())) {
sortProperty = adornedTargetCollectionMetadata.getSortProperty();
}
metadata.setParentObjectClass(resolvedClass.getName());
if (adornedTargetCollectionMetadata.getMaintainedAdornedTargetFields() != null) {
metadata.setMaintainedAdornedTargetFields(adornedTargetCollectionMetadata.getMaintainedAdornedTargetFields());
}
if (adornedTargetCollectionMetadata.getGridVisibleFields() != null) {
metadata.setGridVisibleFields(adornedTargetCollectionMetadata.getGridVisibleFields());
}
if (adornedTargetCollectionMetadata.getSelectizeVisibleField() != null) {
metadata.setSelectizeVisibleField(adornedTargetCollectionMetadata.getSelectizeVisibleField());
}
String parentObjectIdProperty = null;
if (serverMetadata != null) {
parentObjectIdProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getLinkedIdProperty();
}
if (adornedTargetCollectionMetadata.getParentObjectIdProperty() != null) {
parentObjectIdProperty = adornedTargetCollectionMetadata.getParentObjectIdProperty();
}
String targetObjectProperty = null;
if (serverMetadata != null) {
targetObjectProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getTargetObjectPath();
}
if (adornedTargetCollectionMetadata.getTargetObjectProperty() != null) {
targetObjectProperty = adornedTargetCollectionMetadata.getTargetObjectProperty();
}
if (StringUtils.isEmpty(parentObjectIdProperty)) {
throw new IllegalArgumentException("targetObjectProperty not defined");
}
String joinEntityClass = null;
if (serverMetadata != null) {
joinEntityClass = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getJoinEntityClass();
}
if (adornedTargetCollectionMetadata.getJoinEntityClass() != null) {
joinEntityClass = adornedTargetCollectionMetadata.getJoinEntityClass();
}
Class<?> collectionTarget = null;
try {
checkCeiling: {
try {
ParameterizedType pt = (ParameterizedType) field.getGenericType();
java.lang.reflect.Type collectionType = pt.getActualTypeArguments()[0];
collectionTarget = (Class<?>) collectionType;
// Hibernate class is from that
if (collectionTarget.isInterface()) {
collectionTarget = entityConfiguration.lookupEntityClass(collectionTarget.getName());
}
break checkCeiling;
} catch (NoSuchBeanDefinitionException e) {
// We weren't successful at looking at entity configuration to find the type of this collection.
// We will continue and attempt to find it via the Hibernate annotations
}
if (!StringUtils.isEmpty(field.getOneToManyTargetEntity()) && !void.class.getName().equals(field.getOneToManyTargetEntity())) {
collectionTarget = Class.forName(field.getOneToManyTargetEntity());
break checkCeiling;
}
if (!StringUtils.isEmpty(field.getManyToManyTargetEntity()) && !void.class.getName().equals(field.getManyToManyTargetEntity())) {
collectionTarget = Class.forName(field.getManyToManyTargetEntity());
break checkCeiling;
}
}
if (StringUtils.isNotBlank(joinEntityClass)) {
collectionTarget = Class.forName(joinEntityClass);
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
if (collectionTarget == null) {
throw new IllegalArgumentException("Unable to infer the type of the collection from the targetEntity property of a OneToMany or ManyToMany collection.");
}
Field collectionTargetField = dynamicEntityDao.getFieldManager().getField(collectionTarget, targetObjectProperty);
ManyToOne manyToOne = collectionTargetField.getAnnotation(ManyToOne.class);
String ceiling = null;
checkCeiling: {
if (manyToOne != null && manyToOne.targetEntity() != void.class) {
ceiling = manyToOne.targetEntity().getName();
break checkCeiling;
}
ceiling = collectionTargetField.getType().getName();
}
if (!StringUtils.isEmpty(ceiling)) {
metadata.setCollectionCeilingEntity(ceiling);
}
String targetObjectIdProperty = null;
if (serverMetadata != null) {
targetObjectIdProperty = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getTargetIdProperty();
}
if (adornedTargetCollectionMetadata.getTargetObjectIdProperty() != null) {
targetObjectIdProperty = adornedTargetCollectionMetadata.getTargetObjectIdProperty();
}
Boolean isAscending = true;
if (serverMetadata != null) {
isAscending = ((AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST)).getSortAscending();
}
if (adornedTargetCollectionMetadata.isSortAscending() != null) {
isAscending = adornedTargetCollectionMetadata.isSortAscending();
}
if (serverMetadata != null) {
AdornedTargetList adornedTargetList = (AdornedTargetList) serverMetadata.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
adornedTargetList.setCollectionFieldName(field.getName());
adornedTargetList.setLinkedObjectPath(parentObjectProperty);
adornedTargetList.setLinkedIdProperty(parentObjectIdProperty);
adornedTargetList.setTargetObjectPath(targetObjectProperty);
adornedTargetList.setTargetIdProperty(targetObjectIdProperty);
adornedTargetList.setJoinEntityClass(joinEntityClass);
adornedTargetList.setIdProperty((String) dynamicEntityDao.getIdMetadata(collectionTarget).get("name"));
adornedTargetList.setAdornedTargetEntityClassname(collectionTarget.getName());
adornedTargetList.setSortField(sortProperty);
adornedTargetList.setSortAscending(isAscending);
adornedTargetList.setMutable(metadata.isMutable());
} else {
AdornedTargetList adornedTargetList = new AdornedTargetList(field.getName(), parentObjectProperty, parentObjectIdProperty, targetObjectProperty, targetObjectIdProperty, collectionTarget.getName(), sortProperty, isAscending);
adornedTargetList.setJoinEntityClass(joinEntityClass);
adornedTargetList.setIdProperty((String) dynamicEntityDao.getIdMetadata(collectionTarget).get("name"));
adornedTargetList.setMutable(metadata.isMutable());
persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.ADORNEDTARGETLIST, adornedTargetList);
}
if (adornedTargetCollectionMetadata.getExcluded() != null) {
if (LOG.isDebugEnabled()) {
if (adornedTargetCollectionMetadata.getExcluded()) {
LOG.debug("buildAdornedTargetCollectionMetadata:Excluding " + field.getName() + " because it was explicitly declared in config");
} else {
LOG.debug("buildAdornedTargetCollectionMetadata:Showing " + field.getName() + " because it was explicitly declared in config");
}
}
metadata.setExcluded(adornedTargetCollectionMetadata.getExcluded());
}
if (adornedTargetCollectionMetadata.getLazyFetch() != null) {
metadata.setLazyFetch(adornedTargetCollectionMetadata.getLazyFetch());
}
if (adornedTargetCollectionMetadata.getManualFetch() != null) {
metadata.setManualFetch(adornedTargetCollectionMetadata.getManualFetch());
}
if (adornedTargetCollectionMetadata.getFriendlyName() != null) {
metadata.setFriendlyName(adornedTargetCollectionMetadata.getFriendlyName());
}
if (adornedTargetCollectionMetadata.getSecurityLevel() != null) {
metadata.setSecurityLevel(adornedTargetCollectionMetadata.getSecurityLevel());
}
if (adornedTargetCollectionMetadata.getOrder() != null) {
metadata.setOrder(adornedTargetCollectionMetadata.getOrder());
}
if (adornedTargetCollectionMetadata.getTab() != null) {
metadata.setTab(adornedTargetCollectionMetadata.getTab());
}
if (adornedTargetCollectionMetadata.getTabOrder() != null) {
metadata.setTabOrder(adornedTargetCollectionMetadata.getTabOrder());
}
if (adornedTargetCollectionMetadata.getGroup() != null) {
metadata.setGroup(adornedTargetCollectionMetadata.getGroup());
}
if (adornedTargetCollectionMetadata.getCustomCriteria() != null) {
metadata.setCustomCriteria(adornedTargetCollectionMetadata.getCustomCriteria());
}
if (adornedTargetCollectionMetadata.getUseServerSideInspectionCache() != null) {
persistencePerspective.setUseServerSideInspectionCache(adornedTargetCollectionMetadata.getUseServerSideInspectionCache());
}
if (adornedTargetCollectionMetadata.isIgnoreAdornedProperties() != null) {
metadata.setIgnoreAdornedProperties(adornedTargetCollectionMetadata.isIgnoreAdornedProperties());
}
if (adornedTargetCollectionMetadata.getAdornedTargetAddMethodType() != null) {
metadata.setAdornedTargetAddMethodType(adornedTargetCollectionMetadata.getAdornedTargetAddMethodType());
}
if (adornedTargetCollectionMetadata.getCurrencyCodeField() != null) {
metadata.setCurrencyCodeField(adornedTargetCollectionMetadata.getCurrencyCodeField());
}
attributes.put(field.getName(), metadata);
}
use of org.broadleafcommerce.openadmin.dto.AdornedTargetList in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetListPersistenceModule method add.
@Override
public Entity add(PersistencePackage persistencePackage) throws ServiceException {
String[] customCriteria = persistencePackage.getCustomCriteria();
if (customCriteria != null && customCriteria.length > 0) {
LOG.warn("custom persistence handlers and custom criteria not supported for add types other than BASIC");
}
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
Entity entity = persistencePackage.getEntity();
AdornedTargetList adornedTargetList = (AdornedTargetList) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
if (!adornedTargetList.getMutable()) {
throw new SecurityServiceException("Field is not mutable");
}
Entity payload;
try {
Class<?>[] entities = persistenceManager.getPolymorphicEntities(ceilingEntityFullyQualifiedClassname);
Map<String, FieldMetadata> mergedPropertiesTarget = persistenceManager.getDynamicEntityDao().getMergedProperties(ceilingEntityFullyQualifiedClassname, entities, null, persistencePerspective.getAdditionalNonPersistentProperties(), persistencePerspective.getAdditionalForeignKeys(), MergedPropertyType.PRIMARY, persistencePerspective.getPopulateToOneFields(), persistencePerspective.getIncludeFields(), persistencePerspective.getExcludeFields(), persistencePerspective.getConfigurationKey(), "");
Class<?>[] entities2 = persistenceManager.getPolymorphicEntities(adornedTargetList.getAdornedTargetEntityClassname());
Map<String, FieldMetadata> mergedProperties = persistenceManager.getDynamicEntityDao().getMergedProperties(adornedTargetList.getAdornedTargetEntityClassname(), entities2, null, new String[] {}, new ForeignKey[] {}, MergedPropertyType.ADORNEDTARGETLIST, false, new String[] {}, new String[] {}, null, "");
CriteriaTransferObject ctoInserted = new CriteriaTransferObject();
FilterAndSortCriteria filterCriteriaInsertedLinked = ctoInserted.get(adornedTargetList.getCollectionFieldName());
String linkedPath;
String targetPath;
if (adornedTargetList.getInverse()) {
linkedPath = adornedTargetList.getTargetObjectPath() + "." + adornedTargetList.getTargetIdProperty();
targetPath = adornedTargetList.getLinkedObjectPath() + "." + adornedTargetList.getLinkedIdProperty();
} else {
targetPath = adornedTargetList.getTargetObjectPath() + "." + adornedTargetList.getTargetIdProperty();
linkedPath = adornedTargetList.getLinkedObjectPath() + "." + adornedTargetList.getLinkedIdProperty();
}
filterCriteriaInsertedLinked.setFilterValue(entity.findProperty(adornedTargetList.getInverse() ? targetPath : linkedPath).getValue());
FilterAndSortCriteria filterCriteriaInsertedTarget = ctoInserted.get(adornedTargetList.getCollectionFieldName() + "Target");
filterCriteriaInsertedTarget.setFilterValue(entity.findProperty(adornedTargetList.getInverse() ? linkedPath : targetPath).getValue());
List<FilterMapping> filterMappingsInserted = getAdornedTargetFilterMappings(persistencePerspective, ctoInserted, mergedProperties, adornedTargetList);
List<Serializable> recordsInserted = getPersistentRecords(adornedTargetList.getAdornedTargetEntityClassname(), filterMappingsInserted, ctoInserted.getFirstResult(), ctoInserted.getMaxResults());
if (recordsInserted.size() > 0) {
payload = getRecords(mergedPropertiesTarget, recordsInserted, mergedProperties, adornedTargetList.getTargetObjectPath(), null)[0];
} else {
Serializable instance = createPopulatedAdornedTargetInstance(adornedTargetList, entity);
instance = createPopulatedInstance(instance, entity, mergedProperties, false, persistencePackage.isValidateUnsubmittedProperties());
instance = createPopulatedInstance(instance, entity, mergedPropertiesTarget, false, persistencePackage.isValidateUnsubmittedProperties());
FieldManager fieldManager = getFieldManager();
if (fieldManager.getField(instance.getClass(), "id") != null) {
fieldManager.setFieldValue(instance, "id", null);
}
if (adornedTargetList.getSortField() != null) {
// Construct a query that gets the last element in the join list ordered by the sort property. This will
// ensure that the new record is always the last element in the list
CriteriaTransferObject cto = new CriteriaTransferObject();
FilterAndSortCriteria filterCriteria = cto.get(adornedTargetList.getCollectionFieldName());
filterCriteria.setFilterValue(entity.findProperty(adornedTargetList.getInverse() ? targetPath : linkedPath).getValue());
FilterAndSortCriteria sortCriteria = cto.get(adornedTargetList.getSortField());
// criteria for which way to sort should be the opposite of how it is normally sorted so that it is
// always inserted at the end
sortCriteria.setSortAscending(!adornedTargetList.getSortAscending());
List<FilterMapping> filterMappings = getAdornedTargetFilterMappings(persistencePerspective, cto, mergedProperties, adornedTargetList);
List<Serializable> joinList = getPersistentRecords(adornedTargetList.getAdornedTargetEntityClassname(), filterMappings, 0, 1);
Object adornedLastOrdering = null;
if (CollectionUtils.isNotEmpty(joinList)) {
adornedLastOrdering = fieldManager.getFieldValue(joinList.get(0), adornedTargetList.getSortField());
}
Field sortFieldDef = fieldManager.getField(instance.getClass(), adornedTargetList.getSortField());
int add = (adornedLastOrdering == null) ? 0 : 1;
if (sortFieldDef.getType().isAssignableFrom(Long.class)) {
adornedLastOrdering = (adornedLastOrdering == null) ? new Long(0) : adornedLastOrdering;
fieldManager.setFieldValue(instance, adornedTargetList.getSortField(), new Long(((Long) adornedLastOrdering).longValue() + add));
} else if (sortFieldDef.getType().isAssignableFrom(Integer.class)) {
adornedLastOrdering = (adornedLastOrdering == null) ? new Integer(0) : adornedLastOrdering;
fieldManager.setFieldValue(instance, adornedTargetList.getSortField(), new Integer(((Integer) adornedLastOrdering).intValue() + add));
} else if (sortFieldDef.getType().isAssignableFrom(BigDecimal.class)) {
adornedLastOrdering = (adornedLastOrdering == null) ? BigDecimal.ZERO : adornedLastOrdering;
fieldManager.setFieldValue(instance, adornedTargetList.getSortField(), ((BigDecimal) adornedLastOrdering).add(new BigDecimal(add)));
}
}
instance = persistenceManager.getDynamicEntityDao().merge(instance);
persistenceManager.getDynamicEntityDao().clear();
List<Serializable> recordsInserted2 = getPersistentRecords(adornedTargetList.getAdornedTargetEntityClassname(), filterMappingsInserted, ctoInserted.getFirstResult(), ctoInserted.getMaxResults());
payload = getRecords(mergedPropertiesTarget, recordsInserted2, mergedProperties, adornedTargetList.getTargetObjectPath(), null)[0];
}
} catch (Exception e) {
throw new ServiceException("Problem adding new entity : " + e.getMessage(), e);
}
return payload;
}
use of org.broadleafcommerce.openadmin.dto.AdornedTargetList 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.dto.AdornedTargetList in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetListPersistenceModule method updateMergedProperties.
@Override
public void updateMergedProperties(PersistencePackage persistencePackage, Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
AdornedTargetList adornedTargetList = (AdornedTargetList) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
if (adornedTargetList != null) {
Class<?>[] entities = persistenceManager.getPolymorphicEntities(adornedTargetList.getAdornedTargetEntityClassname());
Map<String, FieldMetadata> joinMergedProperties = persistenceManager.getDynamicEntityDao().getMergedProperties(adornedTargetList.getAdornedTargetEntityClassname(), entities, null, new String[] {}, new ForeignKey[] {}, MergedPropertyType.ADORNEDTARGETLIST, persistencePerspective.getPopulateToOneFields(), persistencePerspective.getIncludeFields(), persistencePerspective.getExcludeFields(), persistencePerspective.getConfigurationKey(), "");
String idProp = null;
for (String key : joinMergedProperties.keySet()) {
if (joinMergedProperties.get(key) instanceof BasicFieldMetadata && ((BasicFieldMetadata) joinMergedProperties.get(key)).getFieldType() == SupportedFieldType.ID) {
idProp = key;
break;
}
}
if (idProp != null) {
joinMergedProperties.remove(idProp);
}
allMergedProperties.put(MergedPropertyType.ADORNEDTARGETLIST, joinMergedProperties);
}
} catch (Exception e) {
throw new ServiceException("Unable to fetch results for " + ceilingEntityFullyQualifiedClassname, e);
}
}
Aggregations