Search in sources :

Example 1 with SystemProperty

use of org.broadleafcommerce.common.config.domain.SystemProperty in project BroadleafCommerce by BroadleafCommerce.

the class SystemPropertiesTest method testOverridesPropertyFiles.

@Test
@Transactional
public void testOverridesPropertyFiles() {
    String propertyFileResolved = env.getProperty("property.file.override.test", String.class);
    Assert.assertEquals(propertyFileResolved, "propertyfile");
    clearSystemPropertiesCache();
    SystemProperty prop = new SystemPropertyImpl();
    prop.setName("property.file.override.test");
    prop.setValue("testngtest");
    prop = propsDao.saveSystemProperty(prop);
    String resolvedProperty = env.getProperty(prop.getName(), String.class);
    Assert.assertEquals(resolvedProperty, prop.getValue());
    propsDao.deleteSystemProperty(prop);
    clearSystemPropertiesCache();
    String fromPropertiesFile = propsSvc.resolveSystemProperty("property.file.override.test");
    Assert.assertEquals(fromPropertiesFile, "propertyfile");
}
Also used : SystemPropertyImpl(org.broadleafcommerce.common.config.domain.SystemPropertyImpl) SystemProperty(org.broadleafcommerce.common.config.domain.SystemProperty) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SystemProperty

use of org.broadleafcommerce.common.config.domain.SystemProperty in project BroadleafCommerce by BroadleafCommerce.

the class SystemPropertyCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        // Get an instance of SystemProperty with the updated values from the form
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        SystemProperty adminInstance = (SystemProperty) Class.forName(entity.getType()[0]).newInstance();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(SystemProperty.class.getName(), persistencePerspective);
        adminInstance = (SystemProperty) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        // Verify that the value entered matches up with the type of this property
        Entity errorEntity = validateTypeAndValueCombo(adminInstance);
        if (errorEntity != null) {
            entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
            return entity;
        }
        adminInstance = (SystemProperty) dynamicEntityDao.merge(adminInstance);
        // Fill out the DTO and add in the product option value properties to it
        return helper.getRecord(adminProperties, adminInstance, null, null);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform fetch for entity: " + SystemProperty.class.getName(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SystemProperty(org.broadleafcommerce.common.config.domain.SystemProperty) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 3 with SystemProperty

use of org.broadleafcommerce.common.config.domain.SystemProperty in project BroadleafCommerce by BroadleafCommerce.

the class SystemPropertyCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        // Get an instance of SystemProperty with the updated values from the form
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(SystemProperty.class.getName(), persistencePerspective);
        Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
        SystemProperty adminInstance = (SystemProperty) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
        adminInstance = (SystemProperty) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        // Verify that the value entered matches up with the type of this property
        Entity errorEntity = validateTypeAndValueCombo(adminInstance);
        if (errorEntity != null) {
            entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
            return entity;
        }
        adminInstance = (SystemProperty) dynamicEntityDao.merge(adminInstance);
        // Fill out the DTO and add in the product option value properties to it
        return helper.getRecord(adminProperties, adminInstance, null, null);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform fetch for entity: " + SystemProperty.class.getName(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SystemProperty(org.broadleafcommerce.common.config.domain.SystemProperty) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 4 with SystemProperty

use of org.broadleafcommerce.common.config.domain.SystemProperty in project BroadleafCommerce by BroadleafCommerce.

the class SystemPropertiesTest method testEnvironmentResolvedFromDatabase.

@Test
@Transactional
public void testEnvironmentResolvedFromDatabase() {
    SystemProperty prop = new SystemPropertyImpl();
    prop.setName("test.property.with.environment");
    prop.setValue("database");
    propsDao.saveSystemProperty(prop);
    String resolvedProperty = env.getProperty(prop.getName(), String.class);
    Assert.assertEquals(resolvedProperty, prop.getValue());
}
Also used : SystemPropertyImpl(org.broadleafcommerce.common.config.domain.SystemPropertyImpl) SystemProperty(org.broadleafcommerce.common.config.domain.SystemProperty) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SystemProperty

use of org.broadleafcommerce.common.config.domain.SystemProperty in project BroadleafCommerce by BroadleafCommerce.

the class SystemPropertiesDaoImpl method readAllSystemProperties.

@Override
public List<SystemProperty> readAllSystemProperties() {
    CriteriaBuilder builder = em.getCriteriaBuilder();
    CriteriaQuery<SystemProperty> criteria = builder.createQuery(SystemProperty.class);
    Root<SystemPropertyImpl> handler = criteria.from(SystemPropertyImpl.class);
    criteria.select(handler);
    List<Predicate> restrictions = new ArrayList<Predicate>();
    List<Order> sorts = new ArrayList<Order>();
    try {
        if (queryExtensionManager != null) {
            queryExtensionManager.getProxy().setup(SystemPropertyImpl.class, null);
            queryExtensionManager.getProxy().refineRetrieve(SystemPropertyImpl.class, null, builder, criteria, handler, restrictions);
            queryExtensionManager.getProxy().refineOrder(SystemPropertyImpl.class, null, builder, criteria, handler, sorts);
        }
        criteria.where(restrictions.toArray(new Predicate[restrictions.size()]));
        return em.createQuery(criteria).getResultList();
    } catch (NoResultException e) {
        LOG.error(e);
        return new ArrayList<SystemProperty>();
    } finally {
        if (queryExtensionManager != null) {
            queryExtensionManager.getProxy().breakdown(SystemPropertyImpl.class, null);
        }
    }
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) Order(javax.persistence.criteria.Order) SystemPropertyImpl(org.broadleafcommerce.common.config.domain.SystemPropertyImpl) ArrayList(java.util.ArrayList) NoResultException(javax.persistence.NoResultException) SystemProperty(org.broadleafcommerce.common.config.domain.SystemProperty) Predicate(javax.persistence.criteria.Predicate)

Aggregations

SystemProperty (org.broadleafcommerce.common.config.domain.SystemProperty)6 SystemPropertyImpl (org.broadleafcommerce.common.config.domain.SystemPropertyImpl)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 NoResultException (javax.persistence.NoResultException)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Order (javax.persistence.criteria.Order)1 Predicate (javax.persistence.criteria.Predicate)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1