Search in sources :

Example 31 with ExtensionResultHolder

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

the class AdminBasicEntityController method saveEntityJson.

/**
 * Builds JSON that looks like this:
 *
 * {"errors":
 *      [{"message":"This field is Required",
 *        "code": "requiredValidationFailure"
 *        "field":"defaultSku--name",
 *        "errorType", "field",
 *        "tab": "General"
 *        },
 *        {"message":"This field is Required",
 *        "code": "requiredValidationFailure"
 *        "field":"defaultSku--name",
 *        "errorType", "field",
 *        "tab": "General"
 *        }]
 * }
 */
@RequestMapping(value = "/{id}", method = RequestMethod.POST, produces = "application/json")
public String saveEntityJson(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @ModelAttribute(value = "entityForm") EntityForm entityForm, BindingResult result, RedirectAttributes ra) throws Exception {
    saveEntity(request, response, model, pathVars, id, entityForm, result, ra);
    JsonResponse json = new JsonResponse(response);
    if (result.hasErrors()) {
        populateJsonValidationErrors(entityForm, result, json);
    }
    List<String> dirtyList = buildDirtyList(pathVars, request, id);
    if (CollectionUtils.isNotEmpty(dirtyList)) {
        json.with("dirty", dirtyList);
    }
    ExtensionResultHolder<String> resultHolder = new ExtensionResultHolder<>();
    ExtensionResultStatusType resultStatusType = extensionManager.getProxy().overrideSaveEntityJsonResponse(response, result.hasErrors(), getSectionKey(pathVars), id, resultHolder);
    if (resultStatusType.equals(ExtensionResultStatusType.HANDLED)) {
        return resultHolder.getResult();
    }
    return json.done();
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) JsonResponse(org.broadleafcommerce.common.web.JsonResponse) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with ExtensionResultHolder

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

the class CatalogServiceImpl method findSkuByURI.

@Override
public Sku findSkuByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findSkuByURI(createCatalogContextDTO(), uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Sku) holder.getResult();
        }
    }
    List<Sku> skus = skuDao.findSkuByURI(uri);
    if (skus == null || skus.size() == 0) {
        return null;
    } else if (skus.size() == 1) {
        return skus.get(0);
    } else {
        // First check for a direct hit on the url
        for (Sku sku : skus) {
            if (uri.equals(sku.getProduct().getUrl() + sku.getUrlKey())) {
                return sku;
            }
        }
        // Otherwise, return the first product
        return skus.get(0);
    }
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 33 with ExtensionResultHolder

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

the class ValidateAddRequestActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    ExtensionResultHolder<Exception> resultHolder = new ExtensionResultHolder<>();
    resultHolder.setResult(null);
    if (extensionManager != null && extensionManager.getProxy() != null) {
        ExtensionResultStatusType result = extensionManager.getProxy().validate(context.getSeedData(), resultHolder);
        if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
            if (resultHolder.getResult() != null) {
                throw resultHolder.getResult();
            }
        }
    }
    return validate(context);
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) RequiredAttributeNotProvidedException(org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 34 with ExtensionResultHolder

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

the class AdminNavigationServiceImpl method getClassNameForSection.

@Override
public String getClassNameForSection(String sectionKey) {
    AdminSection section = findAdminSectionByURI("/" + sectionKey);
    ExtensionResultHolder erh = new ExtensionResultHolder();
    extensionManager.getProxy().overrideClassNameForSection(erh, sectionKey, section);
    if (erh.getContextMap().get(AbstractAdminAbstractControllerExtensionHandler.NEW_CLASS_NAME) != null) {
        return (String) erh.getContextMap().get(AbstractAdminAbstractControllerExtensionHandler.NEW_CLASS_NAME);
    }
    return (section == null) ? sectionKey : section.getCeilingEntity();
}
Also used : AdminSection(org.broadleafcommerce.openadmin.server.security.domain.AdminSection) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 35 with ExtensionResultHolder

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

the class OfferCodeDaoImpl method readOfferCodesQuery.

protected Query readOfferCodesQuery(String code) {
    Query query;
    ExtensionResultHolder<Query> resultHolder = new ExtensionResultHolder<Query>();
    ExtensionResultStatusType extensionResult = extensionManager.getProxy().createReadOfferCodeByCodeQuery(em, resultHolder, code, true, "query.Offer");
    if (extensionResult != null && ExtensionResultStatusType.HANDLED.equals(extensionResult)) {
        query = resultHolder.getResult();
    } else {
        query = em.createNamedQuery("BC_READ_OFFER_CODE_BY_CODE");
        query.setParameter("code", code);
        query.setHint(QueryHints.HINT_CACHEABLE, true);
        query.setHint(QueryHints.HINT_CACHE_REGION, "query.Offer");
    }
    return query;
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Aggregations

ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)56 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)35 ArrayList (java.util.ArrayList)11 Product (org.broadleafcommerce.core.catalog.domain.Product)7 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)6 ParentEntityPersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.ParentEntityPersistenceException)5 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 List (java.util.List)4 Set (java.util.Set)4 File (java.io.File)3 Serializable (java.io.Serializable)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 HashMap (java.util.HashMap)3 Query (javax.persistence.Query)3 TypedQuery (javax.persistence.TypedQuery)3 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)3 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)3 Site (org.broadleafcommerce.common.site.domain.Site)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3