use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class RuleFieldPersistenceProvider method convertQuantityBasedRuleToJson.
protected Property convertQuantityBasedRuleToJson(MVELToDataWrapperTranslator translator, ObjectMapper mapper, Collection<QuantityBasedRule> quantityBasedRules, String jsonProp, String fieldService) {
int k = 0;
Entity[] targetItemCriterias = new Entity[quantityBasedRules.size()];
for (QuantityBasedRule quantityBasedRule : quantityBasedRules) {
Property[] properties = new Property[4];
Property mvelProperty = new Property();
mvelProperty.setName("matchRule");
mvelProperty.setValue(quantityBasedRule.getMatchRule());
Property quantityProperty = new Property();
quantityProperty.setName("quantity");
quantityProperty.setValue(quantityBasedRule.getQuantity().toString());
Property idProperty = new Property();
idProperty.setName("id");
Long id = quantityBasedRule.getId();
id = transformId(id, quantityBasedRule);
idProperty.setValue(String.valueOf(id));
Object containedRule = findContainedRuleIfApplicable(quantityBasedRule);
Property containedIdProperty = new Property();
if (containedRule != null) {
containedIdProperty.setName("containedId");
EntityManager em = PersistenceManagerFactory.getDefaultPersistenceManager().getDynamicEntityDao().getStandardEntityManager();
Long containedId = (Long) em.unwrap(Session.class).getIdentifier(containedRule);
containedId = transformId(containedId, containedRule);
containedIdProperty.setValue(String.valueOf(containedId));
}
properties[0] = mvelProperty;
properties[1] = quantityProperty;
properties[2] = idProperty;
properties[3] = containedIdProperty;
Entity criteria = new Entity();
criteria.setProperties(properties);
targetItemCriterias[k] = criteria;
k++;
}
String json;
try {
DataWrapper oiWrapper = translator.createRuleData(targetItemCriterias, "matchRule", "quantity", "id", "containedId", ruleBuilderFieldServiceFactory.createInstance(fieldService));
json = mapper.writeValueAsString(oiWrapper);
} catch (Exception e) {
throw new RuntimeException(e);
}
Property p = new Property();
p.setName(jsonProp);
p.setValue(json);
return p;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class MapStructurePersistenceModule method getMapRecord.
protected Entity getMapRecord(String ceilingClass, Serializable valueInstance, MapStructure mapStructure, Map<String, FieldMetadata> valueMergedProperties, Property symbolicIdProperty, Object key, String[] customCriteria) {
Entity entityItem = new Entity();
entityItem.setType(new String[] { ceilingClass });
List<Property> props = new ArrayList<Property>();
Property keyProperty = new Property();
keyProperty.setName(mapStructure.getKeyPropertyName());
String keyPropertyValue;
if (Date.class.isAssignableFrom(key.getClass())) {
keyPropertyValue = getSimpleDateFormatter().format((Date) key);
} else if (Timestamp.class.isAssignableFrom(key.getClass())) {
keyPropertyValue = getSimpleDateFormatter().format(new Date(((Timestamp) key).getTime()));
} else if (Calendar.class.isAssignableFrom(key.getClass())) {
keyPropertyValue = getSimpleDateFormatter().format(((Calendar) key).getTime());
} else if (Double.class.isAssignableFrom(key.getClass())) {
keyPropertyValue = getDecimalFormatter().format(key);
} else if (BigDecimal.class.isAssignableFrom(key.getClass())) {
keyPropertyValue = getDecimalFormatter().format(key);
} else {
keyPropertyValue = key.toString();
}
keyProperty.setValue(keyPropertyValue);
props.add(keyProperty);
if (SimpleValueMapStructure.class.isInstance(mapStructure)) {
SimpleValueMapStructure simpleValueMapStructure = (SimpleValueMapStructure) mapStructure;
Property valueProperty = new Property();
valueProperty.setName(simpleValueMapStructure.getValuePropertyName());
valueProperty.setDisplayValue((String) valueInstance);
valueProperty.setValue((String) valueInstance);
props.add(valueProperty);
}
extractPropertiesFromPersistentEntity(valueMergedProperties, valueInstance, props, customCriteria);
if (symbolicIdProperty != null) {
props.add(symbolicIdProperty);
}
Property[] properties = new Property[props.size()];
properties = props.toArray(properties);
entityItem.setProperties(properties);
return entityItem;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class MapStructurePersistenceModule method procureSandBoxMapValue.
protected Serializable procureSandBoxMapValue(MapStructure mapStructure, Entity entity) {
try {
Serializable valueInstance = null;
// this is probably a sync from another sandbox where they've updated a map item for which we've updated the key in our own sandbox
// (i.e. the map entry key was changed by us in our sandbox, so our map does not have the requested key)
Class<?> valueClass = Class.forName(mapStructure.getValueClassName());
Map<String, Object> idMetadata = getPersistenceManager().getDynamicEntityDao().getIdMetadata(valueClass);
String idProperty = (String) idMetadata.get("name");
Property prop = entity.findProperty(idProperty);
if (prop != null) {
Serializable identifier;
if (!(((Type) idMetadata.get("type")) instanceof StringType)) {
identifier = Long.parseLong(prop.getValue());
} else {
identifier = prop.getValue();
}
valueInstance = (Serializable) getPersistenceManager().getDynamicEntityDao().find(valueClass, identifier);
BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
if (sandBoxHelper.isSandBoxable(valueInstance.getClass().getName()) && context != null && !context.isProductionSandBox()) {
if (sandBoxHelper.isPromote() && !sandBoxHelper.isReject()) {
// if this is a prod record (i.e. the destination map has deleted our record), then duplicate our value
// so it's available in this sandbox
valueInstance = getPersistenceManager().getDynamicEntityDao().merge(valueInstance);
} else {
valueInstance = null;
}
}
}
return valueInstance;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldPersistenceProvider method canHandlePersistence.
protected boolean canHandlePersistence(PopulateValueRequest populateValueRequest, Serializable instance) {
BasicFieldMetadata metadata = populateValueRequest.getMetadata();
Property property = populateValueRequest.getProperty();
// don't handle map fields here - we'll get them in a separate provider
boolean response = detectBasicType(metadata, property);
if (!response) {
// we'll allow this provider to handle money filter mapping for persistence
response = metadata.getFieldType() == SupportedFieldType.MONEY;
}
return response;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldPersistenceProvider method canHandleSearchMapping.
protected boolean canHandleSearchMapping(AddSearchMappingRequest addSearchMappingRequest, List<FilterMapping> filterMappings) {
FieldMetadata metadata = addSearchMappingRequest.getMergedProperties().get(addSearchMappingRequest.getPropertyName());
Property property = null;
// don't handle map fields here - we'll get them in a separate provider
boolean response = detectBasicType(metadata, property) || detectAdditionalSearchTypes(metadata, property);
return response;
}
Aggregations