use of org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao in project BroadleafCommerce by BroadleafCommerce.
the class FieldManager method getField.
public Field getField(Class<?> clazz, String fieldName) throws IllegalStateException {
DynamicEntityDao dynamicEntityDao = getPersistenceManager(clazz).getDynamicEntityDao();
SessionFactory sessionFactory = dynamicEntityDao.getDynamicDaoHelper().getSessionFactory((HibernateEntityManager) dynamicEntityDao.getStandardEntityManager());
BLCFieldUtils fieldUtils = new BLCFieldUtils(sessionFactory, true, dynamicEntityDao.useCache(), dynamicEntityDao.getEjb3ConfigurationDao(), entityConfiguration, dynamicEntityDao.getDynamicDaoHelper());
return fieldUtils.getField(clazz, fieldName);
}
use of org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminTypedEntityRequestFilter method getTypeFieldName.
protected String getTypeFieldName(AdminSection adminSection) {
try {
DynamicEntityDao dynamicEntityDao = getDynamicEntityDao(adminSection.getCeilingEntity());
Class<?> implClass = dynamicEntityDao.getCeilingImplClass(adminSection.getCeilingEntity());
return ((TypedEntity) implClass.newInstance()).getTypeFieldName();
} catch (Exception e) {
return null;
}
}
use of org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldMetadataProvider method buildDataDrivenEnumList.
protected void buildDataDrivenEnumList(BasicFieldMetadata metadata) {
try {
DynamicEntityDao dynamicEntityDao = PersistenceManagerFactory.getDefaultPersistenceManager().getDynamicEntityDao();
FieldManager fieldManager = dynamicEntityDao.getFieldManager();
Criteria criteria = dynamicEntityDao.createCriteria(Class.forName(metadata.getOptionListEntity()));
if (metadata.getOptionListEntity().equals(DataDrivenEnumerationValueImpl.class.getName())) {
criteria.add(Restrictions.eq("hidden", false));
}
if (metadata.getOptionFilterParams() != null) {
for (String[] param : metadata.getOptionFilterParams()) {
Criteria current = criteria;
String key = param[0];
if (!key.equals(".ignore")) {
if (key.contains(".")) {
String[] parts = key.split("\\.");
for (int j = 0; j < parts.length - 1; j++) {
current = current.createCriteria(parts[j], parts[j]);
}
}
current.add(Restrictions.eq(key, convertType(param[1], OptionFilterParamType.valueOf(param[2]))));
}
}
}
List results = criteria.list();
String[][] enumerationValues = new String[results.size()][2];
int j = 0;
for (Object param : results) {
enumerationValues[j][1] = String.valueOf(fieldManager.getFieldValue(param, metadata.getOptionDisplayFieldName()));
enumerationValues[j][0] = String.valueOf(fieldManager.getFieldValue(param, metadata.getOptionValueFieldName()));
j++;
}
if (!CollectionUtils.isEmpty(results) && metadata.getOptionListEntity().equals(DataDrivenEnumerationValueImpl.class.getName())) {
metadata.setOptionCanEditValues((Boolean) fieldManager.getFieldValue(results.get(0), "type.modifiable"));
}
metadata.setEnumerationValues(enumerationValues);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getForeignEntityName.
@Override
public String getForeignEntityName(String owningClass, String id) {
if (owningClass == null || id == null) {
return null;
}
DynamicEntityDao dynamicEntityDao = getDynamicEntityDao(owningClass);
Class<?> clazz = dynamicEntityDao.getImplClass(owningClass);
Object foreignEntity = dynamicEntityDao.find(clazz, toIdFieldType(id, clazz));
if (foreignEntity instanceof AdminMainEntity) {
return ((AdminMainEntity) foreignEntity).getMainEntityName();
}
return null;
}
use of org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao in project BroadleafCommerce by BroadleafCommerce.
the class UniqueValueValidator method validate.
@Override
public PropertyValidationResult validate(Entity entity, Serializable instance, Map<String, FieldMetadata> entityFieldMetadata, Map<String, String> validationConfiguration, BasicFieldMetadata propertyMetadata, String propertyName, String value) {
String instanceClassName = instance.getClass().getName();
DynamicEntityDao dynamicEntityDao = getDynamicEntityDao(instanceClassName);
List<Long> responseIds = dynamicEntityDao.readOtherEntitiesWithPropertyValue(instance, propertyName, value);
String message = validationConfiguration.get(ConfigurationItem.ERROR_MESSAGE);
if (message == null) {
message = entity.getType()[0] + " with this value for attribute " + propertyName + " already exists. This attribute's value must be unique.";
}
if (responseIds.size() == 0) {
return new PropertyValidationResult(true, message);
} else {
return new PropertyValidationResult(false, message);
}
}
Aggregations