Search in sources :

Example 1 with DynamicEntityDao

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);
}
Also used : SessionFactory(org.hibernate.SessionFactory) BLCFieldUtils(org.broadleafcommerce.common.util.BLCFieldUtils) DynamicEntityDao(org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao)

Example 2 with DynamicEntityDao

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;
    }
}
Also used : TypedEntity(org.broadleafcommerce.common.admin.domain.TypedEntity) DynamicEntityDao(org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with DynamicEntityDao

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);
    }
}
Also used : FieldManager(org.broadleafcommerce.openadmin.server.service.persistence.module.FieldManager) List(java.util.List) ArrayList(java.util.ArrayList) DynamicEntityDao(org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao) Criteria(org.hibernate.Criteria) DataDrivenEnumerationValueImpl(org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumerationValueImpl)

Example 4 with DynamicEntityDao

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;
}
Also used : CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) DynamicEntityDao(org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity)

Example 5 with DynamicEntityDao

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);
    }
}
Also used : DynamicEntityDao(org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao)

Aggregations

DynamicEntityDao (org.broadleafcommerce.openadmin.server.dao.DynamicEntityDao)5 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ServletException (javax.servlet.ServletException)1 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)1 TypedEntity (org.broadleafcommerce.common.admin.domain.TypedEntity)1 DataDrivenEnumerationValueImpl (org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumerationValueImpl)1 BLCFieldUtils (org.broadleafcommerce.common.util.BLCFieldUtils)1 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)1 FieldManager (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldManager)1 Criteria (org.hibernate.Criteria)1 SessionFactory (org.hibernate.SessionFactory)1