Search in sources :

Example 6 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType 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;
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 7 with ExtensionResultStatusType

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

the class ProductCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Product adminInstance = (Product) Class.forName(entity.getType()[0]).newInstance();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Product.class.getName(), persistencePerspective);
        if (adminInstance instanceof ProductBundle) {
            removeBundleFieldRestrictions((ProductBundle) adminInstance, adminProperties, entity);
        }
        adminInstance = (Product) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        adminInstance = dynamicEntityDao.merge(adminInstance);
        // any Sku fields, and thus a Sku would not be created. Product still needs a default Sku so instantiate one
        if (adminInstance.getDefaultSku() == null) {
            Sku newSku = catalogService.createSku();
            dynamicEntityDao.persist(newSku);
            adminInstance.setDefaultSku(newSku);
            adminInstance = dynamicEntityDao.merge(adminInstance);
        }
        // also set the default product for the Sku
        adminInstance.getDefaultSku().setDefaultProduct(adminInstance);
        dynamicEntityDao.merge(adminInstance.getDefaultSku());
        // if this is a Pre-Add, skip the rest of the method
        if (entity.isPreAdd()) {
            return helper.getRecord(adminProperties, adminInstance, null, null);
        }
        boolean handled = false;
        if (extensionManager != null) {
            ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForAdd(persistencePackage, adminInstance);
            handled = ExtensionResultStatusType.NOT_HANDLED != result;
        }
        if (!handled) {
            setupXref(adminInstance);
        }
        return helper.getRecord(adminProperties, adminInstance, null, null);
    } catch (Exception e) {
        throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 8 with ExtensionResultStatusType

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

the class CategoryParentCategoryFieldPersistenceProvider method populateValue.

@Override
public MetadataProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance) {
    if (!canHandlePersistence(populateValueRequest, instance)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    boolean handled = false;
    if (extensionManager != null) {
        ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategory(populateValueRequest.getProperty(), (Category) instance);
        handled = ExtensionResultStatusType.NOT_HANDLED != result;
    }
    if (!handled || BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
        Long requestedValue = null;
        if (!StringUtils.isEmpty(populateValueRequest.getRequestedValue())) {
            requestedValue = Long.parseLong(populateValueRequest.getRequestedValue());
        }
        boolean dirty = checkDirtyState((Category) instance, requestedValue);
        if (dirty) {
            populateValueRequest.getProperty().setIsDirty(true);
            if (requestedValue != null) {
                ((Category) instance).setParentCategory((Category) populateValueRequest.getPersistenceManager().getDynamicEntityDao().find(CategoryImpl.class, requestedValue));
            } else {
                ((Category) instance).setParentCategory(null);
            }
        }
    }
    return MetadataProviderResponse.HANDLED_BREAK;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 9 with ExtensionResultStatusType

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

the class ProductParentCategoryFieldPersistenceProvider method populateValue.

@Override
public MetadataProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance) {
    if (!canHandlePersistence(populateValueRequest, instance)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    boolean handled = false;
    if (extensionManager != null) {
        ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategory(populateValueRequest.getProperty(), (Product) instance);
        handled = ExtensionResultStatusType.NOT_HANDLED != result;
    }
    if (!handled || BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
        Long requestedValue = null;
        if (StringUtils.isNotEmpty(populateValueRequest.getRequestedValue())) {
            requestedValue = Long.parseLong(populateValueRequest.getRequestedValue());
        }
        boolean dirty = checkDirtyState((Product) instance, requestedValue);
        if (dirty) {
            populateValueRequest.getProperty().setIsDirty(true);
            if (requestedValue != null) {
                ((Product) instance).setCategory((Category) populateValueRequest.getPersistenceManager().getDynamicEntityDao().find(CategoryImpl.class, requestedValue));
            } else {
                ((Product) instance).setCategory(null);
            }
        }
    }
    return MetadataProviderResponse.HANDLED_BREAK;
}
Also used : Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 10 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType 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;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) ModelAndView(org.springframework.web.servlet.ModelAndView) Product(org.broadleafcommerce.core.catalog.domain.Product) SearchResult(org.broadleafcommerce.core.search.domain.SearchResult) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) SearchCriteria(org.broadleafcommerce.core.search.domain.SearchCriteria) Entry(java.util.Map.Entry) Sku(org.broadleafcommerce.core.catalog.domain.Sku) 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