use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class SkuBundleItemCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
// retrieve the default properties for Inventory
Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(SkuBundleItem.class.getName(), persistencePerspective);
// add in the consolidated product options field
FieldMetadata options = skuPersistenceHandler.createConsolidatedOptionField(SkuBundleItemImpl.class);
options.setOrder(3);
properties.put(SkuCustomPersistenceHandler.CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME, options);
allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(SkuBundleItem.class);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
return new DynamicResultSet(mergedMetadata, null, null);
} catch (Exception e) {
String className = persistencePackage.getCeilingEntityFullyQualifiedClassname();
ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + className, e);
LOG.error("Unable to retrieve inspection results for " + className, ex);
throw ex;
}
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPaymentCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(CustomerPayment.class.getName(), persistencePerspective);
// Hide "Payment Gateway Type" column & create "Saved Payment Info" ListGrid column
FieldMetadata paymentGatewayType = properties.get("paymentGatewayType");
if (paymentGatewayType != null) {
((BasicFieldMetadata) paymentGatewayType).setProminent(false);
}
BasicFieldMetadata savedPaymentInfo = new BasicFieldMetadata();
savedPaymentInfo.setName(SAVED_PAYMENT_INFO);
savedPaymentInfo.setFriendlyName("CustomerPaymentImpl_Saved_Payment_Info");
savedPaymentInfo.setFieldType(SupportedFieldType.STRING);
savedPaymentInfo.setInheritedFromType(CustomerPaymentImpl.class.getName());
savedPaymentInfo.setAvailableToTypes(new String[] { CustomerPaymentImpl.class.getName() });
savedPaymentInfo.setProminent(true);
savedPaymentInfo.setGridOrder(2000);
savedPaymentInfo.setReadOnly(true);
savedPaymentInfo.setVisibility(VisibilityEnum.FORM_HIDDEN);
properties.put(SAVED_PAYMENT_INFO, savedPaymentInfo);
allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(CustomerPayment.class);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
return new DynamicResultSet(mergedMetadata, null, null);
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityDaoImpl method buildProperties.
protected void buildProperties(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> presentationAttributes, List<Property> componentProperties, Map<String, FieldMetadata> fields, List<String> propertyNames, List<Type> propertyTypes, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, Boolean isComponentPrefix, String parentPrefix) {
int j = 0;
Comparator<String> propertyComparator = new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
// check for property name equality and for map field properties
if (o1.equals(o2) || o1.startsWith(o2 + FieldManager.MAPFIELDSEPARATOR) || o2.startsWith(o1 + FieldManager.MAPFIELDSEPARATOR)) {
return 0;
}
return o1.compareTo(o2);
}
};
List<String> presentationKeyList = new ArrayList<>(presentationAttributes.keySet());
Collections.sort(presentationKeyList);
for (String propertyName : propertyNames) {
final Type type = propertyTypes.get(j);
boolean isPropertyForeignKey = testForeignProperty(foreignField, prefix, propertyName);
int additionalForeignKeyIndexPosition = findAdditionalForeignKeyIndex(additionalForeignFields, prefix, propertyName);
j++;
Field myField = getFieldManager().getField(targetClass, propertyName);
if (myField == null) {
// try to get the field with the prefix - needed for advanced collections that appear in @Embedded classes
myField = getFieldManager().getField(targetClass, prefix + propertyName);
}
if (!type.isAnyType() && !type.isCollectionType() || isPropertyForeignKey || additionalForeignKeyIndexPosition >= 0 || Collections.binarySearch(presentationKeyList, propertyName, propertyComparator) >= 0) {
if (myField != null) {
boolean handled = false;
for (FieldMetadataProvider provider : fieldMetadataProviders) {
FieldMetadata presentationAttribute = presentationAttributes.get(propertyName);
if (presentationAttribute != null) {
setExcludedBasedOnShowIfProperty(presentationAttribute);
}
MetadataProviderResponse response = provider.addMetadataFromFieldType(new AddMetadataFromFieldTypeRequest(myField, targetClass, foreignField, additionalForeignFields, mergedPropertyType, componentProperties, idProperty, prefix, propertyName, type, isPropertyForeignKey, additionalForeignKeyIndexPosition, presentationAttributes, presentationAttribute, null, type.getReturnedClass(), this), fields);
if (MetadataProviderResponse.NOT_HANDLED != response) {
handled = true;
}
if (MetadataProviderResponse.HANDLED_BREAK == response) {
break;
}
}
if (!handled) {
buildBasicProperty(myField, targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties, mergedPropertyType, presentationAttributes, componentProperties, fields, idProperty, populateManyToOneFields, includeFields, excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, parentClasses, prefix, isParentExcluded, propertyName, type, isPropertyForeignKey, additionalForeignKeyIndexPosition, isComponentPrefix, parentPrefix);
}
}
}
}
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityDaoImpl method buildComponentProperties.
protected void buildComponentProperties(Class<?> targetClass, ForeignKey foreignField, ForeignKey[] additionalForeignFields, String[] additionalNonPersistentProperties, MergedPropertyType mergedPropertyType, Map<String, FieldMetadata> fields, String idProperty, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, String propertyName, Type type, Class<?> returnedClass, List<Class<?>> parentClasses, Boolean isParentExcluded, String prefix, String parentPrefix) {
String[] componentProperties = ((ComponentType) type).getPropertyNames();
List<String> componentPropertyNames = Arrays.asList(componentProperties);
Type[] componentTypes = ((ComponentType) type).getSubtypes();
List<Type> componentPropertyTypes = Arrays.asList(componentTypes);
String tempPrefix = "";
int pos = prefix.indexOf(".");
final int prefixLength = prefix.length();
if (pos > 0 && pos < prefixLength - 1) {
// only use part of the prefix if it's more than one layer deep
tempPrefix = prefix.substring(pos + 1, prefixLength);
}
Map<String, FieldMetadata> componentPresentationAttributes = metadata.getFieldMetadataForTargetClass(targetClass, returnedClass, this, tempPrefix + propertyName + ".");
if (isParentExcluded) {
for (String key : componentPresentationAttributes.keySet()) {
LOG.debug("buildComponentProperties:Excluding " + key + " because the parent was excluded");
componentPresentationAttributes.get(key).setExcluded(true);
}
}
PersistentClass persistentClass = getPersistentClass(targetClass.getName());
Property property;
try {
property = persistentClass.getProperty(propertyName);
} catch (MappingException e) {
property = persistentClass.getProperty(prefix + propertyName);
}
Iterator componentPropertyIterator = ((org.hibernate.mapping.Component) property.getValue()).getPropertyIterator();
List<Property> componentPropertyList = new ArrayList<>();
while (componentPropertyIterator.hasNext()) {
componentPropertyList.add((Property) componentPropertyIterator.next());
}
Map<String, FieldMetadata> newFields = new HashMap<>();
buildProperties(targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties, mergedPropertyType, componentPresentationAttributes, componentPropertyList, newFields, componentPropertyNames, componentPropertyTypes, idProperty, populateManyToOneFields, includeFields, excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, parentClasses, propertyName + ".", isParentExcluded, true, parentPrefix + prefix);
Map<String, FieldMetadata> convertedFields = new HashMap<>();
for (String key : newFields.keySet()) {
final FieldMetadata fieldMetadata = newFields.get(key);
convertedFields.put(propertyName + "." + key, fieldMetadata);
if (isForeignKey(fieldMetadata)) {
setOriginatingFieldForForeignKey(propertyName, key, fieldMetadata);
}
}
fields.putAll(convertedFields);
}
use of org.broadleafcommerce.openadmin.dto.MergedPropertyType in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityDaoImpl method getPropertiesForEntityClass.
protected Map<String, FieldMetadata> getPropertiesForEntityClass(Class<?> targetClass, ForeignKey foreignField, String[] additionalNonPersistentProperties, ForeignKey[] additionalForeignFields, MergedPropertyType mergedPropertyType, Boolean populateManyToOneFields, String[] includeFields, String[] excludeFields, String configurationKey, String ceilingEntityFullyQualifiedClassname, List<Class<?>> parentClasses, String prefix, Boolean isParentExcluded, String parentPrefix) {
Map<String, FieldMetadata> presentationAttributes = metadata.getFieldMetadataForTargetClass(null, targetClass, this, "");
if (isParentExcluded) {
for (String key : presentationAttributes.keySet()) {
LOG.debug("getPropertiesForEntityClass:Excluding " + key + " because parent is excluded.");
presentationAttributes.get(key).setExcluded(true);
}
}
Map idMetadata = getIdMetadata(targetClass);
Map<String, FieldMetadata> fields = new HashMap<>();
String idProperty = (String) idMetadata.get("name");
List<String> propertyNames = getPropertyNames(targetClass);
propertyNames.add(idProperty);
Type idType = (Type) idMetadata.get("type");
List<Type> propertyTypes = getPropertyTypes(targetClass);
propertyTypes.add(idType);
PersistentClass persistentClass = getPersistentClass(targetClass.getName());
Iterator testIter = persistentClass.getPropertyIterator();
List<Property> propertyList = new ArrayList<>();
// check the properties for problems
while (testIter.hasNext()) {
Property property = (Property) testIter.next();
if (property.getName().contains(".")) {
throw new IllegalArgumentException("Properties from entities that utilize a period character ('.') in their name are incompatible with this system. The property name in question is: (" + property.getName() + ") from the class: (" + targetClass.getName() + ")");
}
propertyList.add(property);
}
buildProperties(targetClass, foreignField, additionalForeignFields, additionalNonPersistentProperties, mergedPropertyType, presentationAttributes, propertyList, fields, propertyNames, propertyTypes, idProperty, populateManyToOneFields, includeFields, excludeFields, configurationKey, ceilingEntityFullyQualifiedClassname, parentClasses, prefix, isParentExcluded, false, parentPrefix);
BasicFieldMetadata presentationAttribute = new BasicFieldMetadata();
presentationAttribute.setExplicitFieldType(SupportedFieldType.STRING);
presentationAttribute.setVisibility(VisibilityEnum.HIDDEN_ALL);
if (!ArrayUtils.isEmpty(additionalNonPersistentProperties)) {
Class<?>[] entities = getAllPolymorphicEntitiesFromCeiling(targetClass);
for (String additionalNonPersistentProperty : additionalNonPersistentProperties) {
if (StringUtils.isEmpty(prefix) || (!StringUtils.isEmpty(prefix) && additionalNonPersistentProperty.startsWith(prefix))) {
String myAdditionalNonPersistentProperty = additionalNonPersistentProperty;
// get final property if this is a dot delimited property
int finalDotPos = additionalNonPersistentProperty.lastIndexOf('.');
if (finalDotPos >= 0) {
myAdditionalNonPersistentProperty = myAdditionalNonPersistentProperty.substring(finalDotPos + 1, myAdditionalNonPersistentProperty.length());
}
// check all the polymorphic types on this target class to see if the end property exists
Field testField = null;
Method testMethod = null;
for (Class<?> clazz : entities) {
try {
testMethod = clazz.getMethod(myAdditionalNonPersistentProperty);
if (testMethod != null) {
break;
}
} catch (NoSuchMethodException e) {
// do nothing - method does not exist
}
testField = getFieldManager().getField(clazz, myAdditionalNonPersistentProperty);
if (testField != null) {
break;
}
}
// if the property exists, add it to the metadata for this class
if (testField != null || testMethod != null) {
fields.put(additionalNonPersistentProperty, metadata.getFieldMetadata(prefix, additionalNonPersistentProperty, propertyList, SupportedFieldType.STRING, null, targetClass, presentationAttribute, mergedPropertyType, this));
}
}
}
}
return fields;
}
Aggregations