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);
}
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;
}
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);
}
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();
}
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;
}
Aggregations