use of org.broadleafcommerce.openadmin.server.service.persistence.module.FieldManager in project BroadleafCommerce by BroadleafCommerce.
the class AfterStartDateValidator 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 otherField = validationConfiguration.get("otherField");
FieldManager fm = getFieldManager(propertyMetadata);
boolean valid = true;
String message = "";
Date startDate = null;
Date endDate = null;
if (StringUtils.isBlank(value) || StringUtils.isBlank(otherField)) {
return new PropertyValidationResult(true);
}
try {
startDate = (Date) fm.getFieldValue(instance, otherField);
endDate = (Date) fm.getFieldValue(instance, propertyName);
} catch (IllegalAccessException | FieldNotAvailableException e) {
valid = false;
message = e.getMessage();
}
if (valid && endDate != null && startDate != null && endDate.before(startDate)) {
valid = false;
message = END_DATE_BEFORE_START;
}
return new PropertyValidationResult(valid, message);
}
use of org.broadleafcommerce.openadmin.server.service.persistence.module.FieldManager 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.service.persistence.module.FieldManager in project BroadleafCommerce by BroadleafCommerce.
the class MaxGreaterThanMinValidator 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 otherField = validationConfiguration.get("otherField");
FieldManager fm = getFieldManager(propertyMetadata);
boolean valid = true;
String message = "";
BigDecimal min = new BigDecimal(0);
BigDecimal max = min;
if (StringUtils.isBlank(value) || StringUtils.isBlank(otherField)) {
return new PropertyValidationResult(true);
}
try {
Object minObj = fm.getFieldValue(instance, otherField);
if (minObj != null) {
min = new BigDecimal(minObj.toString());
}
max = new BigDecimal(fm.getFieldValue(instance, propertyName).toString());
} catch (IllegalAccessException | FieldNotAvailableException e) {
valid = false;
message = e.getMessage();
}
if (valid && max != null && min != null && max.compareTo(min) < 0) {
valid = false;
message = "minGreaterThanMax";
}
return new PropertyValidationResult(valid, message);
}
Aggregations