use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.
the class CategoryCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
entity = validateParentCategory(entity, false);
if (entity.isValidationFailure()) {
return entity;
} else {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Category adminInstance = (Category) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
CategoryXref oldDefault = getCurrentDefaultXref(adminInstance);
adminInstance = (Category) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance = dynamicEntityDao.merge(adminInstance);
boolean handled = false;
if (extensionManager != null) {
ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForUpdate(persistencePackage, adminInstance);
handled = ExtensionResultStatusType.NOT_HANDLED != result;
}
if (!handled) {
setupXref(adminInstance);
removeOldDefault(adminInstance, oldDefault, entity);
}
return helper.getRecord(adminProperties, adminInstance, null, null);
}
} catch (Exception e) {
throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.
the class ProductUrlFieldPersistenceProvider method populateValue.
@Override
public MetadataProviderResponse populateValue(PopulateValueRequest request, Serializable instance) {
String propName = request.getProperty().getName();
String val = request.getRequestedValue();
if ("url".equals(propName) && ProductImpl.class.isAssignableFrom(instance.getClass())) {
Product product = (Product) instance;
ExtensionResultHolder<String> holder = new ExtensionResultHolder<>();
ExtensionResultStatusType result = extensionManager.getProxy().modifyUrl(val, product, holder);
if (ExtensionResultStatusType.HANDLED == result) {
product.setUrl(holder.getResult());
return MetadataProviderResponse.HANDLED;
}
}
return super.populateValue(request, instance);
}
use of org.broadleafcommerce.common.extension.ExtensionResultStatusType in project BroadleafCommerce by BroadleafCommerce.
the class AdminCatalogServiceImpl method generateSkusFromProduct.
@Override
public Integer generateSkusFromProduct(Long productId) {
Product product = catalogService.findProductById(productId);
if (CollectionUtils.isEmpty(product.getProductOptions())) {
return -1;
}
List<List<ProductOptionValue>> allPermutations = generatePermutations(0, new ArrayList<ProductOptionValue>(), product.getProductOptions());
// return -2 to indicate that one of the Product Options used in Sku generation has no Allowed Values
if (allPermutations == null) {
return -2;
}
LOG.info("Total number of permutations: " + allPermutations.size());
LOG.info(allPermutations);
// determine the permutations that I already have Skus for
List<List<ProductOptionValue>> previouslyGeneratedPermutations = new ArrayList<List<ProductOptionValue>>();
if (CollectionUtils.isNotEmpty(product.getAdditionalSkus())) {
for (Sku additionalSku : product.getAdditionalSkus()) {
if (CollectionUtils.isNotEmpty(additionalSku.getProductOptionValues())) {
previouslyGeneratedPermutations.add(additionalSku.getProductOptionValues());
}
}
}
List<List<ProductOptionValue>> permutationsToGenerate = new ArrayList<List<ProductOptionValue>>();
for (List<ProductOptionValue> permutation : allPermutations) {
boolean previouslyGenerated = false;
for (List<ProductOptionValue> generatedPermutation : previouslyGeneratedPermutations) {
if (isSamePermutation(permutation, generatedPermutation)) {
previouslyGenerated = true;
break;
}
}
if (!previouslyGenerated) {
permutationsToGenerate.add(permutation);
}
}
int numPermutationsCreated = 0;
if (extensionManager != null) {
ExtensionResultHolder<Integer> result = new ExtensionResultHolder<Integer>();
ExtensionResultStatusType resultStatusType = extensionManager.getProxy().persistSkuPermutation(product, permutationsToGenerate, result);
if (ExtensionResultStatusType.HANDLED == resultStatusType) {
numPermutationsCreated = result.getResult();
}
}
return numPermutationsCreated;
}
use of org.broadleafcommerce.common.extension.ExtensionResultStatusType 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.ExtensionResultStatusType 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);
}
}
Aggregations