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");
}
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);
}
}
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);
}
}
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());
}
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);
}
}
}
Aggregations