Search in sources :

Example 31 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslatorTest method testBetweenDatesDataWrapper.

public void testBetweenDatesDataWrapper() throws MVELTranslationException {
    MVELToDataWrapperTranslator translator = new MVELToDataWrapperTranslator();
    Property[] p1 = new Property[1];
    Property m1 = new Property();
    m1.setName("matchRule");
    m1.setValue("(MvelHelper.convertField(\"DATE\",customer.?getCustomerAttributes()[\"invoice_date\"])>MvelHelper" + ".convertField(\"DATE\",\"2017.10.14 16:38:00 -0500\")&&MvelHelper.convertField(\"DATE\",customer" + ".?getCustomerAttributes()[\"invoice_date\"])<MvelHelper.convertField(\"DATE\"," + "\"2017.10.16 16:38:00 -0500\"))&&(MvelHelper.convertField(\"DATE\",customer.?getCustomerAttributes()" + "[\"invoice_date\"])>=MvelHelper.convertField(\"DATE\",\"2017.10.24 16:39:00 -0500\")&&MvelHelper" + ".convertField(\"DATE\",customer.?getCustomerAttributes()[\"invoice_date\"])<=MvelHelper" + ".convertField(\"DATE\",\"2017.10.25 16:40:00 -0500\"))");
    Property q1 = new Property();
    q1.setName("quantity");
    q1.setValue("1");
    Property i1 = new Property();
    i1.setName("id");
    i1.setValue("100");
    p1[0] = m1;
    Entity e1 = new Entity();
    e1.setProperties(p1);
    Entity[] entities = new Entity[1];
    entities[0] = e1;
    customerFieldService.getFields().add(new FieldData.Builder().label("Customer - invoice date").name("getCustomerAttributes()---invoice_date").operators(RuleOperatorType.DATE).options(RuleOptionType.EMPTY_COLLECTION).type(SupportedFieldType.DATE).build());
    DataWrapper dataWrapper = translator.createRuleData(entities, "matchRule", null, null, customerFieldService);
    customerFieldService.init();
    assert (dataWrapper.getData().get(0).getRules().size() == 2);
}
Also used : FieldData(org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldData) 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 32 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class MVELToDataWrapperTranslatorTest method testItemQualificationDataWrapper.

public void testItemQualificationDataWrapper() 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("CollectionUtils.intersection(orderItem.?product.?manufacturer,[\"test manufacturer\"]).size()==0");
    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.getData().size() == 2);
    assert (dataWrapper.getData().get(0).getQuantity() == 1);
    assert (dataWrapper.getData().get(0).getCondition().equals(BLCOperator.AND.name()));
    assert (dataWrapper.getData().get(0).getRules().size() == 1);
    assert (dataWrapper.getData().get(0).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO exp1 = (ExpressionDTO) dataWrapper.getData().get(0).getRules().get(0);
    assert (exp1.getId().equals("category.name"));
    assert (exp1.getOperator().equals(BLCOperator.EQUALS.name()));
    assert (exp1.getValue().equals("test category"));
    assert (dataWrapper.getData().get(1).getQuantity() == 2);
    assert (dataWrapper.getData().get(1).getRules().get(0) instanceof ExpressionDTO);
    ExpressionDTO expd1e1 = (ExpressionDTO) dataWrapper.getData().get(1).getRules().get(0);
    assert (expd1e1.getId().equals("product.manufacturer"));
    assert (expd1e1.getOperator().equals(BLCOperator.COLLECTION_NOT_IN.name()));
    assert (expd1e1.getValue().equals("[\"test manufacturer\"]"));
}
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 33 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class DynamicFieldPersistenceHandlerHelper method buildDynamicProperty.

public Property buildDynamicProperty(FieldDefinition definition, Class<?> inheritedType) {
    Property property = new Property();
    property.setName(definition.getName());
    BasicFieldMetadata fieldMetadata = new BasicFieldMetadata();
    property.setMetadata(fieldMetadata);
    fieldMetadata.setFieldType(definition.getFieldType());
    fieldMetadata.setMutable(true);
    fieldMetadata.setInheritedFromType(inheritedType.getName());
    fieldMetadata.setAvailableToTypes(new String[] { inheritedType.getName() });
    fieldMetadata.setForeignKeyCollection(false);
    fieldMetadata.setMergedPropertyType(MergedPropertyType.PRIMARY);
    fieldMetadata.setLength(definition.getMaxLength());
    if (definition.getDataDrivenEnumeration() != null && !CollectionUtils.isEmpty(definition.getDataDrivenEnumeration().getEnumValues())) {
        int count = definition.getDataDrivenEnumeration().getEnumValues().size();
        String[][] enumItems = new String[count][2];
        for (int j = 0; j < count; j++) {
            DataDrivenEnumerationValue item = definition.getDataDrivenEnumeration().getEnumValues().get(j);
            enumItems[j][0] = item.getKey();
            enumItems[j][1] = item.getDisplay();
        }
        fieldMetadata.setEnumerationValues(enumItems);
    }
    fieldMetadata.setName(definition.getName());
    fieldMetadata.setFriendlyName(definition.getFriendlyName());
    fieldMetadata.setSecurityLevel(definition.getSecurityLevel() == null ? "" : definition.getSecurityLevel());
    fieldMetadata.setVisibility(definition.getHiddenFlag() ? VisibilityEnum.HIDDEN_ALL : VisibilityEnum.VISIBLE_ALL);
    fieldMetadata.setTab("General");
    fieldMetadata.setTabOrder(100);
    fieldMetadata.setExplicitFieldType(SupportedFieldType.UNKNOWN);
    fieldMetadata.setLargeEntry(definition.getTextAreaFlag());
    fieldMetadata.setProminent(false);
    fieldMetadata.setColumnWidth(String.valueOf(definition.getColumnWidth()));
    fieldMetadata.setBroadleafEnumeration("");
    fieldMetadata.setReadOnly(false);
    fieldMetadata.setRequiredOverride(definition.getRequiredFlag());
    fieldMetadata.setHint(definition.getHint());
    fieldMetadata.setHelpText(definition.getHelpText());
    fieldMetadata.setTooltip(definition.getTooltip());
    fieldMetadata.setTranslatable(true);
    if (definition.getValidationRegEx() != null) {
        Map<String, String> itemMap = new HashMap<String, String>();
        itemMap.put("regularExpression", definition.getValidationRegEx());
        itemMap.put(ConfigurationItem.ERROR_MESSAGE, definition.getValidationErrorMesageKey());
        List<Map<String, String>> configurationItems = new ArrayList<Map<String, String>>();
        configurationItems.add(itemMap);
        fieldMetadata.getValidationConfigurations().put(RegexPropertyValidator.class.getName(), configurationItems);
    }
    if (definition.getFieldType().equals(SupportedFieldType.ADDITIONAL_FOREIGN_KEY)) {
        fieldMetadata.setForeignKeyClass(definition.getAdditionalForeignKeyClass());
        fieldMetadata.setOwningClass(definition.getAdditionalForeignKeyClass());
        fieldMetadata.setForeignKeyDisplayValueProperty("__adminMainEntity");
    }
    return property;
}
Also used : HashMap(java.util.HashMap) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) DataDrivenEnumerationValue(org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumerationValue) ArrayList(java.util.ArrayList) RegexPropertyValidator(org.broadleafcommerce.openadmin.server.service.persistence.validation.RegexPropertyValidator) Property(org.broadleafcommerce.openadmin.dto.Property) HashMap(java.util.HashMap) Map(java.util.Map)

Example 34 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class AdminProductController method showUpdateAdditionalSku.

protected String showUpdateAdditionalSku(HttpServletRequest request, Model model, String id, String collectionItemId, Map<String, String> pathVars, EntityForm entityForm) throws Exception {
    String collectionField = "additionalSkus";
    // Find out metadata for the additionalSkus property
    String mainClassName = getClassNameForSection(SECTION_KEY);
    List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, SECTION_KEY, id);
    ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
    Property collectionProperty = mainMetadata.getPMap().get(collectionField);
    FieldMetadata md = collectionProperty.getMetadata();
    // Find the metadata and the entity for the selected sku
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withCustomCriteria(new String[] { id });
    ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
    if (collectionMetadata.getCeilingType().equals(SkuImpl.class.getName())) {
        collectionMetadata.setCeilingType(Sku.class.getName());
    }
    Entity entity = service.getRecord(ppr, collectionItemId, collectionMetadata, true).getDynamicResultSet().getRecords()[0];
    String currentTabName = getCurrentTabName(pathVars, collectionMetadata);
    Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForSelectedTab(collectionMetadata, entity, sectionCrumbs, currentTabName);
    if (entityForm == null) {
        entityForm = formService.createEntityForm(collectionMetadata, entity, subRecordsMap, sectionCrumbs);
    } else {
        entityForm.clearFieldsMap();
        formService.populateEntityForm(collectionMetadata, entity, subRecordsMap, entityForm, sectionCrumbs);
        // remove all the actions since we're not trying to redisplay them on the form
        entityForm.removeAllActions();
    }
    entityForm.removeAction(DefaultEntityFormActions.DELETE);
    // Ensure that operations on the Sku subcollections go to the proper URL
    for (ListGrid lg : entityForm.getAllListGrids()) {
        lg.setSectionKey("org.broadleafcommerce.core.catalog.domain.Sku");
        lg.setSectionCrumbs(sectionCrumbs);
    }
    model.addAttribute("entityForm", entityForm);
    model.addAttribute("viewType", "modal/simpleEditEntity");
    model.addAttribute("currentUrl", request.getRequestURL().toString());
    model.addAttribute("modalHeaderType", ModalHeaderType.UPDATE_COLLECTION_ITEM.getType());
    model.addAttribute("collectionProperty", collectionProperty);
    setModelAttributes(model, SECTION_KEY);
    return "modules/modalContainer";
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 35 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method updateSubCollectionEntity.

@Override
public PersistenceResponse updateSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, String alternateId, List<SectionCrumb> sectionCrumbs) throws ServiceException, ClassNotFoundException {
    List<Property> properties = getPropertiesFromEntityForm(entityForm);
    FieldMetadata md = field.getMetadata();
    PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withEntity(new Entity());
    if (md instanceof BasicCollectionMetadata) {
        BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
        ppr.setCeilingEntityClassname(fmd.getCollectionCeilingEntity());
        ppr.getEntity().setType(new String[] { fmd.getCollectionCeilingEntity() });
        Property fp = new Property();
        fp.setName(ppr.getForeignKey().getManyToField());
        fp.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        if (!properties.contains(fp)) {
            properties.add(fp);
        }
    } else if (md instanceof AdornedTargetCollectionMetadata) {
        String adornedTargetEntityClassname = ppr.getAdornedList().getAdornedTargetEntityClassname();
        ppr.setCeilingEntityClassname(adornedTargetEntityClassname);
        ppr.getEntity().setType(new String[] { adornedTargetEntityClassname });
        for (Property property : properties) {
            if (property.getName().equals(ppr.getAdornedList().getLinkedObjectPath() + "." + ppr.getAdornedList().getLinkedIdProperty())) {
                break;
            }
        }
        if (!StringUtils.isEmpty(alternateId)) {
            Property p = new Property();
            p.setName(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
            p.setValue(alternateId);
            if (!properties.contains(p)) {
                properties.add(p);
            }
        }
    } else if (md instanceof MapMetadata) {
        ppr.getEntity().setType(new String[] { entityForm.getEntityType() });
        Property p = new Property();
        p.setName("symbolicId");
        p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
        properties.add(p);
    } else {
        throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was" + " not a collection field.", field.getName(), mainMetadata.getCeilingType()));
    }
    String sectionField = field.getName();
    if (sectionField.contains(".")) {
        sectionField = sectionField.substring(0, sectionField.lastIndexOf("."));
    }
    ppr.setSectionEntityField(sectionField);
    Property parentNameProp = parentEntity.getPMap().get(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
    if (parentNameProp != null) {
        ppr.setRequestingEntityName(parentNameProp.getValue());
    }
    Property p = new Property();
    p.setName(entityForm.getIdProperty());
    p.setValue(collectionItemId);
    if (!properties.contains(p)) {
        properties.add(p);
    }
    Property[] propArr = new Property[properties.size()];
    properties.toArray(propArr);
    ppr.getEntity().setProperties(propArr);
    return update(ppr);
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) MapMetadata(org.broadleafcommerce.openadmin.dto.MapMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)

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