use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class MultiTenantCopyContext method checkCloneStatus.
protected boolean checkCloneStatus(Object instance) {
boolean shouldClone = true;
ExtensionResultHolder<Boolean> shouldCloneHolder = new ExtensionResultHolder<Boolean>();
if (extensionManager != null) {
ExtensionResultStatusType status = extensionManager.getProxy().shouldClone(this, instance, shouldCloneHolder);
if (ExtensionResultStatusType.NOT_HANDLED != status) {
shouldClone = shouldCloneHolder.getResult();
}
}
return shouldClone;
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceUtilitiesImpl method updatePriceDetail.
@Override
public void updatePriceDetail(OrderItemPriceDetail itemDetail, PromotableOrderItemPriceDetail promotableDetail) {
Map<Long, OrderItemPriceDetailAdjustment> itemAdjustmentMap = buildItemDetailAdjustmentMap(itemDetail);
if (itemDetail.getQuantity() != promotableDetail.getQuantity()) {
itemDetail.setQuantity(promotableDetail.getQuantity());
}
if (promotableDetail.isAdjustmentsFinalized()) {
itemDetail.setUseSalePrice(promotableDetail.useSaleAdjustments());
}
for (PromotableOrderItemPriceDetailAdjustment adjustment : promotableDetail.getCandidateItemAdjustments()) {
OrderItemPriceDetailAdjustment itemAdjustment = itemAdjustmentMap.remove(adjustment.getOfferId());
if (itemAdjustment != null) {
// Update existing adjustment
if (!itemAdjustment.getValue().equals(adjustment.getAdjustmentValue())) {
updateItemAdjustment(itemAdjustment, adjustment);
}
} else {
// Add a new adjustment
final OrderItemPriceDetailAdjustment newItemAdjustment;
ExtensionResultHolder resultHolder = new ExtensionResultHolder();
if (extensionManager != null) {
extensionManager.createOrderItemPriceDetailAdjustment(resultHolder, itemDetail);
}
if (resultHolder != null && resultHolder.getContextMap().containsKey("OrderItemPriceDetailAdjustment")) {
newItemAdjustment = (OrderItemPriceDetailAdjustment) resultHolder.getContextMap().get("OrderItemPriceDetailAdjustment");
} else {
newItemAdjustment = offerDao.createOrderItemPriceDetailAdjustment();
}
newItemAdjustment.init(itemDetail, adjustment.getOffer(), null);
updateItemAdjustment(newItemAdjustment, adjustment);
itemDetail.getOrderItemPriceDetailAdjustments().add(newItemAdjustment);
}
}
if (itemAdjustmentMap.size() > 0) {
// Remove adjustments that were on the order item but no longer needed.
List<Long> adjustmentIdsToRemove = new ArrayList<Long>();
for (OrderItemPriceDetailAdjustment adjustmentToRemove : itemAdjustmentMap.values()) {
adjustmentIdsToRemove.add(adjustmentToRemove.getOffer().getId());
}
Iterator<OrderItemPriceDetailAdjustment> iterator = itemDetail.getOrderItemPriceDetailAdjustments().iterator();
while (iterator.hasNext()) {
OrderItemPriceDetailAdjustment adj = iterator.next();
if (adjustmentIdsToRemove.contains(adj.getOffer().getId())) {
iterator.remove();
}
}
}
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafCategoryController method handleRequest.
@Override
@SuppressWarnings("unchecked")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView model = new ModelAndView();
if (request.getParameterMap().containsKey("facetField")) {
// If we receive a facetField parameter, we need to convert the field to the
// product search criteria expected format. This is used in multi-facet selection. We
// will send a redirect to the appropriate URL to maintain canonical URLs
String fieldName = request.getParameter("facetField");
List<String> activeFieldFilters = new ArrayList<String>();
Map<String, String[]> parameters = new HashMap<String, String[]>(request.getParameterMap());
for (Iterator<Entry<String, String[]>> iter = parameters.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, String[]> entry = iter.next();
String key = entry.getKey();
if (key.startsWith(fieldName + "-")) {
activeFieldFilters.add(key.substring(key.indexOf('-') + 1));
iter.remove();
}
}
parameters.remove(SearchCriteria.PAGE_NUMBER);
parameters.put(fieldName, activeFieldFilters.toArray(new String[activeFieldFilters.size()]));
parameters.remove("facetField");
String newUrl = ProcessorUtils.getUrl(request.getRequestURL().toString(), parameters);
model.setViewName("redirect:" + newUrl);
} else {
// Else, if we received a GET to the category URL (either the user clicked this link or we redirected
// from the POST method, we can actually process the results
Category category = (Category) request.getAttribute(CategoryHandlerMapping.CURRENT_CATEGORY_ATTRIBUTE_NAME);
assert (category != null);
SearchCriteria searchCriteria = facetService.buildSearchCriteria(request);
SearchResult result = getSearchService().findSearchResults(searchCriteria);
facetService.setActiveFacetResults(result.getFacets(), request);
model.addObject(CATEGORY_ATTRIBUTE_NAME, category);
model.addObject(PRODUCTS_ATTRIBUTE_NAME, result.getProducts());
model.addObject(SKUS_ATTRIBUTE_NAME, result.getSkus());
model.addObject(FACETS_ATTRIBUTE_NAME, result.getFacets());
model.addObject(PRODUCT_SEARCH_RESULT_ATTRIBUTE_NAME, result);
if (request.getParameterMap().containsKey("q")) {
model.addObject(ORIGINAL_QUERY_ATTRIBUTE_NAME, request.getParameter("q"));
}
model.addObject("BLC_PAGE_TYPE", "category");
if (result.getProducts() != null) {
model.addObject(ALL_PRODUCTS_ATTRIBUTE_NAME, new HashSet<Product>(result.getProducts()));
}
if (result.getSkus() != null) {
model.addObject(ALL_SKUS_ATTRIBUTE_NAME, new HashSet<Sku>(result.getSkus()));
}
addDeepLink(model, deepLinkService, category);
String templatePath = null;
// Use the categories custom template if available
if (StringUtils.isNotBlank(category.getDisplayTemplate())) {
templatePath = category.getDisplayTemplate();
} else {
// Otherwise, use the controller default.
templatePath = getDefaultCategoryView();
}
// Allow extension managers to override.
ExtensionResultHolder<String> erh = new ExtensionResultHolder<String>();
ExtensionResultStatusType extResult = templateOverrideManager.getProxy().getOverrideTemplate(erh, category);
if (extResult != ExtensionResultStatusType.NOT_HANDLED) {
templatePath = erh.getResult();
}
model.setViewName(templatePath);
}
return model;
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class CartStateRequestProcessor method process.
@Override
public void process(WebRequest request) {
Customer customer = CustomerState.getCustomer();
if (customer == null) {
LOG.info("No customer was found on the current request, no cart will be added to the current request. Ensure that the" + " blCustomerStateFilter occurs prior to the blCartStateFilter");
return;
}
ExtensionResultHolder<Order> erh = new ExtensionResultHolder<Order>();
extensionManager.getProxy().lookupOrCreateCart(request, customer, erh);
Order cart;
if (erh.getResult() != null) {
cart = orderService.findCartForCustomerWithEnhancements(customer, erh.getResult());
} else {
cart = getOverrideCart(request);
if (cart == null && mergeCartNeeded(customer, request)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Merge cart required, calling mergeCart " + customer.getId());
}
cart = mergeCart(customer, request);
} else if (cart == null) {
cart = orderService.findCartForCustomerWithEnhancements(customer);
}
if (cart == null) {
cart = orderService.getNullOrder();
} else {
updateCartService.updateAndValidateCart(cart);
}
}
updateCartRequestAttributes(request, cart);
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class EntityDuplicatorImpl method copy.
@Override
public <T> T copy(Class<T> entityClass, Long id, Map<String, String> copyHints, EntityDuplicateModifier... modifiers) {
genericEntityService.flush();
genericEntityService.clear();
Object entity = genericEntityService.readGenericEntity(entityClass, id);
if (!(entity instanceof MultiTenantCloneable)) {
IllegalArgumentException e = new IllegalArgumentException("Copying is only supported for classes implementing MultiTenantCloneable");
LOG.error(String.format("Unable to duplicate entity %s:%s", entityClass.getName(), id), e);
throw e;
}
boolean isValid = validate(entity);
T dup;
if (isValid) {
try {
Site currentSite = BroadleafRequestContext.getBroadleafRequestContext().getNonPersistentSite();
MultiTenantCopyContext context = new MultiTenantCopyContext(null, null, currentSite, currentSite, genericEntityService, mtCopierExtensionManager);
if (extensionManager != null) {
ExtensionResultHolder<MultiTenantCopyContext> contextResponse = new ExtensionResultHolder<MultiTenantCopyContext>();
extensionManager.setupDuplicate(entity, contextResponse);
if (contextResponse.getResult() != null) {
context = contextResponse.getResult();
}
}
dup = performCopy(context, (MultiTenantCloneable<T>) entity, copyHints, modifiers);
} catch (Exception e) {
LOG.error(String.format("Unable to duplicate entity %s:%s", entityClass.getName(), id), e);
throw ExceptionHelper.refineException(e);
} finally {
if (extensionManager != null) {
extensionManager.tearDownDuplicate();
}
}
} else {
LOG.error(String.format("Entity not valid for duplication - %s:%s", entityClass.getName(), id));
throw new IllegalArgumentException(String.format("Entity not valid for duplication - %s:%s", entityClass.getName(), id));
}
return dup;
}
Aggregations