use of org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method getValueClassNames.
protected List<String> getValueClassNames(String valueClassName) {
PersistenceManager pm = PersistenceManagerFactory.getPersistenceManager(valueClassName);
List<String> classNames = new ArrayList<>();
try {
Class<?>[] mapEntities = pm.getPolymorphicEntities(valueClassName);
for (Class clazz : mapEntities) {
classNames.add(clazz.getName());
}
} catch (ClassNotFoundException e) {
classNames.add(valueClassName);
}
return classNames;
}
use of org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager in project BroadleafCommerce by BroadleafCommerce.
the class DefaultFetchWrapper method getBasicPersistenceModule.
protected BasicPersistenceModule getBasicPersistenceModule() {
PersistenceManager persistenceManager = PersistenceManagerFactory.getPersistenceManager();
BasicPersistenceModule basicPersistenceModule = (BasicPersistenceModule) ((InspectHelper) persistenceManager).getCompatibleModule(OperationType.BASIC);
return basicPersistenceModule;
}
use of org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager in project BroadleafCommerce by BroadleafCommerce.
the class FieldManager method setFieldValue.
public Object setFieldValue(Object bean, String fieldName, Object newValue) throws IllegalAccessException, InstantiationException {
StringTokenizer tokens = new StringTokenizer(fieldName, ".");
Class<?> componentClass = bean.getClass();
Field field;
bean = HibernateUtils.deproxy(bean);
Object value = bean;
int count = tokens.countTokens();
int j = 0;
StringBuilder sb = new StringBuilder();
while (tokens.hasMoreTokens()) {
String fieldNamePart = tokens.nextToken();
sb.append(fieldNamePart);
String mapKey = null;
if (fieldNamePart.contains(FieldManager.MAPFIELDSEPARATOR)) {
mapKey = fieldNamePart.substring(fieldNamePart.indexOf(FieldManager.MAPFIELDSEPARATOR) + FieldManager.MAPFIELDSEPARATOR.length(), fieldNamePart.length());
fieldNamePart = fieldNamePart.substring(0, fieldNamePart.indexOf(FieldManager.MAPFIELDSEPARATOR));
}
field = getSingleField(componentClass, fieldNamePart);
field.setAccessible(true);
if (j == count - 1) {
if (mapKey != null) {
handleMapFieldPopulation(bean, fieldName, newValue, componentClass, field, value, fieldNamePart, mapKey);
} else {
FieldModifierManager modifierManager = FieldModifierManager.getFieldModifierManager();
if (modifierManager != null) {
newValue = modifierManager.getModifiedWriteValue(field, value, newValue, entityManager);
}
field.set(value, newValue);
}
} else {
Object myValue = field.get(value);
if (myValue != null) {
componentClass = myValue.getClass();
value = myValue;
} else {
// configured entity for this class
try {
Object newEntity = entityConfiguration.createEntityInstance(field.getType().getName());
SortableValue val = new SortableValue(bean, (Serializable) newEntity, j, sb.toString());
middleFields.add(val);
field.set(value, newEntity);
componentClass = newEntity.getClass();
value = newEntity;
} catch (Exception e) {
// Use the most extended type based on the field type
PersistenceManager persistenceManager = getPersistenceManager(field.getType());
Class<?>[] entities = persistenceManager.getUpDownInheritance(field.getType());
if (!ArrayUtils.isEmpty(entities)) {
Object newEntity = entities[entities.length - 1].newInstance();
SortableValue val = new SortableValue(bean, (Serializable) newEntity, j, sb.toString());
middleFields.add(val);
field.set(value, newEntity);
componentClass = newEntity.getClass();
value = newEntity;
LOG.info("Unable to find a reference to (" + field.getType().getName() + ") in the EntityConfigurationManager. " + "Using the most extended form of this class identified as (" + entities[0].getName() + ")");
} else {
// Just use the field type
Object newEntity = field.getType().newInstance();
field.set(value, newEntity);
componentClass = newEntity.getClass();
value = newEntity;
LOG.info("Unable to find a reference to (" + field.getType().getName() + ") in the EntityConfigurationManager. " + "Using the type of this class.");
}
}
}
}
sb.append(".");
j++;
}
return value;
}
use of org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager in project BroadleafCommerce by BroadleafCommerce.
the class CustomPersistenceHandlerAdapter method getResultSet.
/**
* This is a helper method that can be invoked as the last step in a custom inspect phase. It will assemble the
* appropriate DynamicResultSet from the given parameters.
*/
protected DynamicResultSet getResultSet(PersistencePackage persistencePackage, InspectHelper helper, Map<String, FieldMetadata> metadata) throws ServiceException {
String entityName = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
if (helper instanceof PersistenceManager) {
Class<?>[] entities = ((PersistenceManager) helper).getPolymorphicEntities(entityName);
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
allMergedProperties.put(MergedPropertyType.PRIMARY, metadata);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entities, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata);
return results;
}
} catch (ClassNotFoundException e) {
throw new ServiceException(e);
}
return new DynamicResultSet();
}
use of org.broadleafcommerce.openadmin.server.service.persistence.PersistenceManager 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;
}
Aggregations