Search in sources :

Example 6 with Property

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;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldNotAvailableException(org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException) MVELTranslationException(org.broadleafcommerce.openadmin.web.rulebuilder.MVELTranslationException) PersistenceException(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException) ParentEntityPersistenceException(org.broadleafcommerce.openadmin.server.service.persistence.ParentEntityPersistenceException) DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) EntityManager(javax.persistence.EntityManager) QuantityBasedRule(org.broadleafcommerce.common.rule.QuantityBasedRule) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 7 with Property

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;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Property(org.broadleafcommerce.openadmin.dto.Property) Timestamp(java.sql.Timestamp) Date(java.util.Date) SimpleValueMapStructure(org.broadleafcommerce.openadmin.dto.SimpleValueMapStructure)

Example 8 with Property

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);
    }
}
Also used : Serializable(java.io.Serializable) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) OperationType(org.broadleafcommerce.common.presentation.client.OperationType) PersistencePerspectiveItemType(org.broadleafcommerce.common.presentation.client.PersistencePerspectiveItemType) StringType(org.hibernate.type.StringType) Type(org.hibernate.type.Type) StringType(org.hibernate.type.StringType) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 9 with Property

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;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 10 with Property

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;
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) 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