use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class PageTemplateCustomPersistenceHandler method populateFKLookupValues.
/**
* Some of the values in this entity might be foreign key lookups. In this case, we need to set the display
* value appropriately
*
* @param dynamicEntityDao
* @param entity
* @throws ClassNotFoundException
*/
protected void populateFKLookupValues(DynamicEntityDao dynamicEntityDao, Entity entity) throws ClassNotFoundException {
for (Property prop : entity.getProperties()) {
if (StringUtils.isNotBlank(prop.getValue()) && StringUtils.isNotBlank(prop.getMetadata().getOwningClass())) {
Class<?> clazz = Class.forName(prop.getMetadata().getOwningClass());
Class<?>[] lookupClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(clazz);
int i = 0;
Object foreignEntity = null;
while (foreignEntity == null && i < lookupClasses.length) {
foreignEntity = dynamicEntityDao.find(lookupClasses[i++], Long.parseLong(prop.getValue()));
}
if (foreignEntity instanceof AdminMainEntity) {
prop.setDisplayValue(((AdminMainEntity) foreignEntity).getMainEntityName());
}
prop.getMetadata().setOwningClass(null);
}
}
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class StructuredContentTypeCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
String structuredContentTypeId = persistencePackage.getCustomCriteria()[3];
StructuredContentType structuredContentType = structuredContentService.findStructuredContentTypeById(Long.valueOf(structuredContentTypeId));
ClassMetadata metadata = new ClassMetadata();
metadata.setCeilingType(StructuredContentType.class.getName());
ClassTree entities = new ClassTree(StructuredContentTypeImpl.class.getName());
metadata.setPolymorphicEntities(entities);
Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(structuredContentType.getStructuredContentFieldTemplate().getFieldGroups(), StructuredContentTypeImpl.class);
metadata.setProperties(properties);
DynamicResultSet results = new DynamicResultSet(metadata);
return results;
} catch (Exception e) {
throw new ServiceException("Unable to perform inspect for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslatorTest method testInBetweenRuleOrderGreaterThenAndLessThenAndCurrency.
public void testInBetweenRuleOrderGreaterThenAndLessThenAndCurrency() throws MVELTranslationException {
MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
Property[] properties = new Property[3];
Property mvelProperty = new Property();
mvelProperty.setName("orderMatchRule");
mvelProperty.setValue("order.?subTotal.getAmount()>45&&order.?subTotal.getAmount()<75&&order.?currency.?currencyCode==\"USD\"");
Property quantityProperty = new Property();
quantityProperty.setName("quantity");
quantityProperty.setValue("1");
Property idProperty = new Property();
idProperty.setName("id");
idProperty.setValue("100");
properties[0] = mvelProperty;
properties[1] = quantityProperty;
properties[2] = idProperty;
Entity[] entities = new Entity[1];
Entity entity = new Entity();
entity.setProperties(properties);
entities[0] = entity;
DataWrapper dataWrapper = translator.createRuleData(entities, "orderMatchRule", "quantity", "id", orderFieldService);
assert (dataWrapper.getData().size() == 1);
assert (dataWrapper.getData().get(0).getQuantity() == 1);
assert (dataWrapper.getData().get(0).getRules().size() == 2);
assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
ExpressionDTO exp = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
assert (exp.getId().equals("subTotal"));
assert (exp.getOperator().equals(BLCOperator.BETWEEN.name()));
assert (exp.getValue().equals("[45,75]"));
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslatorTest method testNestedExpressionExceptionForItemQualificationCollectionDataWrapper.
public void testNestedExpressionExceptionForItemQualificationCollectionDataWrapper() throws MVELTranslationException {
MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
Property[] p1 = new Property[3];
Property m1 = new Property();
m1.setName("orderItemMatchRule");
m1.setValue("CollectionUtils.intersection(discreteOrderItem.?category.?name,[\"test category\", \"test category 2\"]).size()>0&&discreteOrderItem.?quantity>5");
Property q1 = new Property();
q1.setName("quantity");
q1.setValue("1");
Property i1 = new Property();
i1.setName("id");
i1.setValue("100");
p1[0] = m1;
p1[1] = q1;
p1[2] = i1;
Entity e1 = new Entity();
e1.setProperties(p1);
Property[] p2 = new Property[3];
Property m2 = new Property();
m2.setName("orderItemMatchRule");
m2.setValue("!(discreteOrderItem.product.manufacturer==\"test manufacturer\")");
Property q2 = new Property();
q2.setName("quantity");
q2.setValue("2");
Property i2 = new Property();
i2.setName("id");
i2.setValue("200");
p2[0] = m2;
p2[1] = q2;
p2[2] = i2;
Entity e2 = new Entity();
e2.setProperties(p2);
Entity[] entities = new Entity[2];
entities[0] = e1;
entities[1] = e2;
DataWrapper dataWrapper = translator.createRuleData(entities, "orderItemMatchRule", "quantity", "id", orderItemFieldService);
assert (dataWrapper.getError().equals(MVELToDataWrapperTranslator.SUB_GROUP_MESSAGE));
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslatorTest method testNestedExpressionExceptionForItemQualificationDataWrapper.
public void testNestedExpressionExceptionForItemQualificationDataWrapper() throws MVELTranslationException {
MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
Property[] p1 = new Property[3];
Property m1 = new Property();
m1.setName("orderItemMatchRule");
m1.setValue("discreteOrderItem.category.name==\"test category\"");
Property q1 = new Property();
q1.setName("quantity");
q1.setValue("1");
Property i1 = new Property();
i1.setName("id");
i1.setValue("100");
p1[0] = m1;
p1[1] = q1;
p1[2] = i1;
Entity e1 = new Entity();
e1.setProperties(p1);
Property[] p2 = new Property[3];
Property m2 = new Property();
m2.setName("orderItemMatchRule");
m2.setValue("!(discreteOrderItem.product.manufacturer==\"test manufacturer\")");
Property q2 = new Property();
q2.setName("quantity");
q2.setValue("2");
Property i2 = new Property();
i2.setName("id");
i2.setValue("200");
p2[0] = m2;
p2[1] = q2;
p2[2] = i2;
Entity e2 = new Entity();
e2.setProperties(p2);
Entity[] entities = new Entity[2];
entities[0] = e1;
entities[1] = e2;
DataWrapper dataWrapper = translator.createRuleData(entities, "orderItemMatchRule", "quantity", "id", orderItemFieldService);
assert (dataWrapper.getError().equals(MVELToDataWrapperTranslator.SUB_GROUP_MESSAGE));
}
Aggregations