Search in sources :

Example 41 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafPageController method handleRequest.

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView model = new ModelAndView();
    PageDTO page = (PageDTO) request.getAttribute(PageHandlerMapping.PAGE_ATTRIBUTE_NAME);
    assert page != null;
    model.addObject(MODEL_ATTRIBUTE_NAME, page);
    // For convenience
    model.addObject("pageFields", page.getPageFields());
    model.addObject("BLC_PAGE_TYPE", "page");
    String plainTextStr = (String) page.getPageFields().get("plainText");
    if (!StringUtils.isEmpty(plainTextStr)) {
        if (Boolean.valueOf(plainTextStr)) {
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/plain");
        }
    }
    String templatePath = page.getTemplatePath();
    // Allow extension managers to override the path.
    ExtensionResultHolder<String> erh = new ExtensionResultHolder<String>();
    Boolean internalValidateFindPreviouslySet = false;
    ExtensionResultStatusType extResult;
    try {
        if (!BroadleafRequestContext.getBroadleafRequestContext().getInternalValidateFind()) {
            BroadleafRequestContext.getBroadleafRequestContext().setInternalValidateFind(true);
            internalValidateFindPreviouslySet = true;
        }
        extResult = templateOverrideManager.getProxy().getOverrideTemplate(erh, page);
    } finally {
        if (internalValidateFindPreviouslySet) {
            BroadleafRequestContext.getBroadleafRequestContext().setInternalValidateFind(false);
        }
    }
    if (extResult != ExtensionResultStatusType.NOT_HANDLED) {
        templatePath = erh.getResult();
    }
    model.setViewName(templatePath);
    addDeepLink(model, deepLinkService, page);
    return model;
}
Also used : PageDTO(org.broadleafcommerce.common.page.dto.PageDTO) ModelAndView(org.springframework.web.servlet.ModelAndView) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 42 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafFileServiceImpl method getLocalResource.

protected File getLocalResource(String resourceName, boolean skipSite) {
    if (skipSite) {
        String baseDirectory = getBaseDirectory(skipSite);
        // convert the separators to the system this is currently run on
        String systemResourcePath = FilenameUtils.separatorsToSystem(resourceName);
        String filePath = FilenameUtils.normalize(baseDirectory + File.separator + systemResourcePath);
        return new File(filePath);
    } else {
        String baseDirectory = getBaseDirectory(true);
        ExtensionResultHolder<String> holder = new ExtensionResultHolder<String>();
        if (extensionManager != null) {
            ExtensionResultStatusType result = extensionManager.getProxy().processPathForSite(baseDirectory, resourceName, holder);
            if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
                return new File(holder.getResult());
            }
        }
        return getLocalResource(resourceName, true);
    }
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) File(java.io.File) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 43 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class FileSystemFileServiceProvider method getResource.

@Override
public File getResource(String url, FileApplicationType applicationType) {
    String fileName = buildResourceName(url);
    String baseDirectory = getBaseDirectory(true);
    ExtensionResultHolder<String> holder = new ExtensionResultHolder<String>();
    if (extensionManager != null) {
        ExtensionResultStatusType result = extensionManager.getProxy().processPathForSite(baseDirectory, fileName, holder);
        if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
            return new File(holder.getResult());
        }
    }
    String filePath = FilenameUtils.normalize(getBaseDirectory(false) + File.separator + fileName);
    return new File(filePath);
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) File(java.io.File) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 44 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafProductController method handleRequest.

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    ModelAndView model = new ModelAndView();
    Product product = (Product) request.getAttribute(ProductHandlerMapping.CURRENT_PRODUCT_ATTRIBUTE_NAME);
    assert (product != null);
    model.addObject(MODEL_ATTRIBUTE_NAME, product);
    model.addObject(PAGE_TYPE_ATTRIBUTE_NAME, "product");
    // Build the add to cart request and add it to the page
    ConfigurableOrderItemRequest itemRequest = orderItemService.createConfigurableOrderItemRequestFromProduct(product);
    orderItemService.modifyOrderItemRequest(itemRequest);
    model.addObject(CONFIGURATION_ATTRIBUTE_NAME, itemRequest);
    model.addObject(ALL_PRODUCTS_ATTRIBUTE_NAME, orderItemService.findAllProductsInRequest(itemRequest));
    addDeepLink(model, deepLinkService, product);
    String templatePath;
    // Use the products custom template if available
    if (StringUtils.isNotBlank(product.getDisplayTemplate())) {
        templatePath = product.getDisplayTemplate();
    } else {
        // Otherwise, use the controller default.
        templatePath = getDefaultProductView();
    }
    // Allow extension managers to override.
    ExtensionResultHolder<String> erh = new ExtensionResultHolder<String>();
    ExtensionResultStatusType extResult = templateOverrideManager.getProxy().getOverrideTemplate(erh, product);
    if (extResult != ExtensionResultStatusType.NOT_HANDLED) {
        templatePath = erh.getResult();
    }
    model.setViewName(templatePath);
    // Check if this is request to edit an existing order item
    String isEditRequest = request.getParameter("edit");
    String oidParam = request.getParameter("oid");
    if (StringUtils.isNotEmpty(isEditRequest) && StringUtils.isNotEmpty(oidParam)) {
        Long oid = Long.parseLong(oidParam);
        OrderItem orderItem = orderItemService.readOrderItemById(oid);
        if (orderItemBelongsToCurrentCustomer(orderItem)) {
            // Update the itemRequest to contain user's previous input
            orderItemService.mergeOrderItemRequest(itemRequest, orderItem);
            // Add the order item to the model
            model.addObject("isUpdateRequest", true);
            model.addObject("orderItem", orderItem);
        }
    }
    return model;
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ModelAndView(org.springframework.web.servlet.ModelAndView) Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 45 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method findCartForCustomerWithEnhancements.

@Override
public Order findCartForCustomerWithEnhancements(Customer customer) {
    ExtensionResultHolder<Order> erh = new ExtensionResultHolder<Order>();
    ExtensionResultStatusType resultStatusType = extensionManager.findCartForCustomerWithEnhancements(customer, erh);
    if (ExtensionResultStatusType.NOT_HANDLED != resultStatusType) {
        return erh.getResult();
    }
    return findCartForCustomer(customer);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Aggregations

ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)59 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)35 ArrayList (java.util.ArrayList)11 Product (org.broadleafcommerce.core.catalog.domain.Product)9 Category (org.broadleafcommerce.core.catalog.domain.Category)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)7 ServiceException (org.broadleafcommerce.common.exception.ServiceException)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)6 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 List (java.util.List)4 Query (javax.persistence.Query)4 TypedQuery (javax.persistence.TypedQuery)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)4 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)4 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 File (java.io.File)3