Search in sources :

Example 66 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class PaymentMethodVariableExpression method getPaymentProcessingError.

/**
 * This method is responsible for gathering any Payment Processing Errors that may have been stored
 * as a Redirect Attribute when attempting to checkout.
 */
public String getPaymentProcessingError() {
    BroadleafRequestContext blcContext = BroadleafRequestContext.getBroadleafRequestContext();
    HttpServletRequest request = blcContext.getRequest();
    return request.getParameter(PaymentGatewayAbstractController.PAYMENT_PROCESSING_ERROR);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 67 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class HTMLFieldPersistenceProvider method fixAssetPathsForDisplay.

/**
 * @param val
 * @return
 */
public String fixAssetPathsForDisplay(String val) {
    String contextPath = "/";
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    if (brc != null) {
        HttpServletRequest request = brc.getRequest();
        if (request != null) {
            contextPath = request.getContextPath();
        }
    }
    if (!contextPath.endsWith("/")) {
        contextPath = contextPath + "/";
    }
    if (staticAssetUrlPrefix != null) {
        String tmpPrefix = staticAssetUrlPrefix;
        if (tmpPrefix.startsWith("/")) {
            tmpPrefix = tmpPrefix.substring(1);
        }
        return val.replaceAll("(?<=src=\").*?(?=" + tmpPrefix + ")", contextPath);
    }
    return val;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 68 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class FieldPersistenceProviderAdapter method setNonDisplayableValues.

protected void setNonDisplayableValues(PopulateValueRequest request) {
    BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
    MessageSource messages = context.getMessageSource();
    String label = "(" + messages.getMessage("Workflow_not_displayable", null, "Not Displayable", context.getJavaLocale()) + ")";
    request.getProperty().setDisplayValue(label);
    request.getProperty().setOriginalDisplayValue(label);
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) MessageSource(org.springframework.context.MessageSource)

Example 69 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class MoneyFieldPersistenceProvider method getCurrency.

@Override
protected Currency getCurrency(ExtractValueRequest extractValueRequest, Property property) {
    String currencyCodeField = extractValueRequest.getMetadata().getCurrencyCodeField();
    if (!StringUtils.isEmpty(currencyCodeField)) {
        try {
            return Currency.getInstance((String) extractValueRequest.getFieldManager().getFieldValue(extractValueRequest.getEntity(), currencyCodeField));
        } catch (Exception e) {
        // do nothing
        }
    }
    if (extractValueRequest.getEntity() instanceof CurrencyCodeIdentifiable) {
        try {
            return Currency.getInstance(((CurrencyCodeIdentifiable) extractValueRequest.getEntity()).getCurrencyCode());
        } catch (Exception e) {
        // do nothing
        }
    }
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    return brc.getJavaCurrency();
}
Also used : BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) CurrencyCodeIdentifiable(org.broadleafcommerce.common.currency.util.CurrencyCodeIdentifiable)

Example 70 with BroadleafRequestContext

use of org.broadleafcommerce.common.web.BroadleafRequestContext in project BroadleafCommerce by BroadleafCommerce.

the class RuleFieldPersistenceProvider method updateQuantityRule.

protected boolean updateQuantityRule(EntityManager em, DataDTOToMVELTranslator translator, String entityKey, String fieldService, String jsonPropertyValue, Collection<QuantityBasedRule> criteriaList, Class<?> memberType, Object parent, String mappedBy, Property property) {
    boolean dirty = false;
    if (!StringUtils.isEmpty(jsonPropertyValue)) {
        // avoid lazy init exception on the criteria list for criteria created during an add
        criteriaList.size();
        DataWrapper dw = ruleFieldExtractionUtility.convertJsonToDataWrapper(jsonPropertyValue);
        if (dw != null && StringUtils.isEmpty(dw.getError())) {
            List<QuantityBasedRule> updatedRules = new ArrayList<QuantityBasedRule>();
            for (DataDTO dto : dw.getData()) {
                if (dto.getPk() != null && !CollectionUtils.isEmpty(criteriaList)) {
                    checkId: {
                        // Update Existing Criteria
                        for (QuantityBasedRule quantityBasedRule : criteriaList) {
                            // make compatible with enterprise module
                            boolean isParentRelated = sandBoxHelper.isRelatedToParentCatalogIds(quantityBasedRule, dto.getPk());
                            boolean isMatch = isParentRelated || dto.getPk().equals(quantityBasedRule.getId());
                            if (isMatch) {
                                String mvel;
                                // don't update if the data has not changed
                                if (!quantityBasedRule.getQuantity().equals(dto.getQuantity())) {
                                    dirty = true;
                                }
                                try {
                                    mvel = ruleFieldExtractionUtility.convertDTOToMvelString(translator, entityKey, dto, fieldService);
                                    if (!quantityBasedRule.getMatchRule().equals(mvel)) {
                                        dirty = true;
                                    }
                                } catch (MVELTranslationException e) {
                                    throw new RuntimeException(e);
                                }
                                if (!dirty && extensionManager != null) {
                                    ExtensionResultHolder<Boolean> resultHolder = new ExtensionResultHolder<Boolean>();
                                    ExtensionResultStatusType result = extensionManager.getProxy().establishDirtyState(quantityBasedRule, resultHolder);
                                    if (ExtensionResultStatusType.NOT_HANDLED != result && resultHolder.getResult() != null) {
                                        dirty = resultHolder.getResult();
                                    }
                                }
                                if (dirty) {
                                    // pre-merge (can result in a clone for enterprise)
                                    quantityBasedRule = em.merge(quantityBasedRule);
                                    // update the quantity based rule
                                    quantityBasedRule.setQuantity(dto.getQuantity());
                                    quantityBasedRule.setMatchRule(mvel);
                                    quantityBasedRule = em.merge(quantityBasedRule);
                                }
                                updatedRules.add(quantityBasedRule);
                                break checkId;
                            }
                        }
                        throw new IllegalArgumentException("Unable to update the rule of type (" + memberType.getName() + ") because an update was requested for id (" + dto.getPk() + "), which does not exist.");
                    }
                } else {
                    // Create a new Criteria
                    QuantityBasedRule quantityBasedRule;
                    try {
                        quantityBasedRule = (QuantityBasedRule) memberType.newInstance();
                        quantityBasedRule.setQuantity(dto.getQuantity());
                        quantityBasedRule.setMatchRule(ruleFieldExtractionUtility.convertDTOToMvelString(translator, entityKey, dto, fieldService));
                        if (StringUtils.isEmpty(quantityBasedRule.getMatchRule()) && !StringUtils.isEmpty(dw.getRawMvel())) {
                            quantityBasedRule.setMatchRule(dw.getRawMvel());
                        }
                        PropertyUtils.setNestedProperty(quantityBasedRule, mappedBy, parent);
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                    em.persist(quantityBasedRule);
                    dto.setPk(quantityBasedRule.getId());
                    Object contained = findContainedRuleIfApplicable(quantityBasedRule);
                    if (contained != null) {
                        dto.setContainedPk((Long) em.unwrap(Session.class).getIdentifier(contained));
                    }
                    if (extensionManager != null) {
                        ExtensionResultHolder resultHolder = new ExtensionResultHolder();
                        extensionManager.getProxy().postAdd(quantityBasedRule, resultHolder);
                        if (resultHolder.getResult() != null) {
                            quantityBasedRule = (QuantityBasedRule) resultHolder.getResult();
                        }
                    }
                    if (cascadeExtensionManager != null) {
                        ExtensionResultHolder resultHolder = new ExtensionResultHolder();
                        cascadeExtensionManager.getProxy().postCascadeAdd(quantityBasedRule, dto, resultHolder);
                        if (resultHolder.getResult() != null) {
                            quantityBasedRule = (QuantityBasedRule) resultHolder.getResult();
                        }
                    }
                    updatedRules.add(quantityBasedRule);
                    dirty = true;
                }
            }
            // if an item was not included in the comprehensive submit from the client, we can assume that the
            // listing was deleted, so we remove it here.
            Iterator<QuantityBasedRule> itr = criteriaList.iterator();
            // Since this class explicitly removes the quantity based rule - we must also preserve the id of the element
            // as the CacheInvalidationProducer will need this in order to remove each collection member cache instance as well.
            BroadleafRequestContext context = BroadleafRequestContext.getBroadleafRequestContext();
            context.getAdditionalProperties().put("deletedQuantityBasedRules", new HashSet<QuantityBasedRule>());
            while (itr.hasNext()) {
                checkForRemove: {
                    QuantityBasedRule original = itr.next();
                    for (QuantityBasedRule quantityBasedRule : updatedRules) {
                        Long id = sandBoxHelper.getOriginalId(quantityBasedRule);
                        boolean isMatch = original.getId().equals(id) || original.getId().equals(quantityBasedRule.getId());
                        if (isMatch) {
                            break checkForRemove;
                        }
                    }
                    ((Set<QuantityBasedRule>) context.getAdditionalProperties().get("deletedQuantityBasedRules")).add(original);
                    em.remove(original);
                    itr.remove();
                    dirty = true;
                }
            }
            ObjectMapper mapper = new ObjectMapper();
            String json;
            try {
                json = mapper.writeValueAsString(dw);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            property.setValue(json);
        }
    }
    return dirty;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MVELTranslationException(org.broadleafcommerce.openadmin.web.rulebuilder.MVELTranslationException) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext) ArrayList(java.util.ArrayList) DataDTO(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataDTO) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) 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) QuantityBasedRule(org.broadleafcommerce.common.rule.QuantityBasedRule) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Session(org.hibernate.Session)

Aggregations

BroadleafRequestContext (org.broadleafcommerce.common.web.BroadleafRequestContext)78 Site (org.broadleafcommerce.common.site.domain.Site)16 HashMap (java.util.HashMap)12 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 Locale (org.broadleafcommerce.common.locale.domain.Locale)8 SandBox (org.broadleafcommerce.common.sandbox.domain.SandBox)5 StructuredContentDTO (org.broadleafcommerce.common.structure.dto.StructuredContentDTO)5 MessageSource (org.springframework.context.MessageSource)5 List (java.util.List)4 StructuredContent (org.broadleafcommerce.cms.structure.domain.StructuredContent)4 Field (java.lang.reflect.Field)3 HashSet (java.util.HashSet)3 Locale (java.util.Locale)3 Catalog (org.broadleafcommerce.common.site.domain.Catalog)3 BroadleafAttributeModifier (org.broadleafcommerce.presentation.model.BroadleafAttributeModifier)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 File (java.io.File)2 PrintWriter (java.io.PrintWriter)2