Search in sources :

Example 96 with Property

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);
        }
    }
}
Also used : CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) Property(org.broadleafcommerce.openadmin.dto.Property) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity)

Example 97 with Property

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);
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) StructuredContentTypeImpl(org.broadleafcommerce.cms.structure.domain.StructuredContentTypeImpl) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) StructuredContentType(org.broadleafcommerce.cms.structure.domain.StructuredContentType) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException)

Example 98 with Property

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]"));
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) Entity(org.broadleafcommerce.openadmin.dto.Entity) MVELToDataWrapperTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator) Property(org.broadleafcommerce.openadmin.dto.Property) ExpressionDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.ExpressionDTO)

Example 99 with Property

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));
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) Entity(org.broadleafcommerce.openadmin.dto.Entity) MVELToDataWrapperTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 100 with Property

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));
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) Entity(org.broadleafcommerce.openadmin.dto.Entity) MVELToDataWrapperTranslator(org.broadleafcommerce.openadmin.web.rulebuilder.MVELToDataWrapperTranslator) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

Property (org.broadleafcommerce.openadmin.dto.Property)120 Entity (org.broadleafcommerce.openadmin.dto.Entity)62 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)45 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)38 ArrayList (java.util.ArrayList)28 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)26 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)25 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)21 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 HashMap (java.util.HashMap)18 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 Map (java.util.Map)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)15 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)12 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)12