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