use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class AbstractGeneratedResourceHandler method getRawResource.
/**
* This method can be used to read in a resource given a path and at least one resource location
*
* @param path
* @param locations
* @return the resource from the file system, classpath, etc, if it exists
*/
protected Resource getRawResource(String path, List<Resource> locations) {
ExtensionResultHolder erh = new ExtensionResultHolder();
extensionManager.getProxy().getOverrideResource(path, erh);
if (erh.getContextMap().get(ResourceRequestExtensionHandler.RESOURCE_ATTR) != null) {
return (Resource) erh.getContextMap().get(ResourceRequestExtensionHandler.RESOURCE_ATTR);
}
for (Resource location : locations) {
try {
Resource resource = location.createRelative(path);
if (resource.exists() && resource.isReadable()) {
return resource;
}
} catch (IOException ex) {
LOG.debug("Failed to create relative resource - trying next resource location", ex);
}
}
return null;
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder 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.ExtensionResultHolder 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.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminRequestProcessor method prepareProfile.
protected void prepareProfile(WebRequest request, BroadleafRequestContext brc) {
AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
if (adminUser == null) {
// clear any profile
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.removeAttribute(PROFILE_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
}
} else {
Site profile = null;
if (StringUtils.isNotBlank(request.getParameter(PROFILE_REQ_PARAM))) {
Long profileId = Long.parseLong(request.getParameter(PROFILE_REQ_PARAM));
profile = siteService.retrievePersistentSiteById(profileId);
if (profile == null) {
throw new IllegalArgumentException(String.format("Unable to find the requested profile: %s", profileId));
}
String token = request.getParameter(staleStateProtectionService.getStateVersionTokenParameter());
staleStateProtectionService.compareToken(token);
staleStateProtectionService.invalidateState(true);
}
if (profile == null) {
Long previouslySetProfileId = null;
if (BLCRequestUtils.isOKtoUseSession(request)) {
previouslySetProfileId = (Long) request.getAttribute(PROFILE_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
}
if (previouslySetProfileId != null) {
profile = siteService.retrievePersistentSiteById(previouslySetProfileId);
}
}
if (profile == null) {
List<Site> profiles = new ArrayList<Site>();
if (brc.getNonPersistentSite() != null) {
Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
if (extensionManager != null) {
ExtensionResultHolder<Set<Site>> profilesResult = new ExtensionResultHolder<Set<Site>>();
extensionManager.retrieveProfiles(currentSite, profilesResult);
if (!CollectionUtils.isEmpty(profilesResult.getResult())) {
profiles.addAll(profilesResult.getResult());
}
}
}
if (profiles.size() > 0) {
profile = profiles.get(0);
}
}
if (profile != null) {
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.setAttribute(PROFILE_REQ_PARAM, profile.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
}
brc.setCurrentProfile(profile);
}
}
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminRequestProcessor method prepareCatalog.
protected void prepareCatalog(WebRequest request, BroadleafRequestContext brc) {
AdminUser adminUser = adminRemoteSecurityService.getPersistentAdminUser();
if (adminUser == null) {
// clear any catalog
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.removeAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
}
} else {
Catalog catalog = null;
if (StringUtils.isNotBlank(request.getParameter(CATALOG_REQ_PARAM))) {
Long catalogId = Long.parseLong(request.getParameter(CATALOG_REQ_PARAM));
catalog = siteService.findCatalogById(catalogId);
if (catalog == null) {
throw new IllegalArgumentException(String.format("Unable to find the requested catalog: %s", catalogId));
}
String token = request.getParameter(staleStateProtectionService.getStateVersionTokenParameter());
staleStateProtectionService.compareToken(token);
staleStateProtectionService.invalidateState(true);
}
if (catalog == null) {
Long previouslySetCatalogId = null;
if (BLCRequestUtils.isOKtoUseSession(request)) {
previouslySetCatalogId = (Long) request.getAttribute(CATALOG_REQ_PARAM, WebRequest.SCOPE_GLOBAL_SESSION);
}
if (previouslySetCatalogId != null) {
catalog = siteService.findCatalogById(previouslySetCatalogId);
}
}
if (catalog == null) {
List<Catalog> catalogs = new ArrayList<Catalog>();
if (brc.getNonPersistentSite() != null) {
Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
if (extensionManager != null) {
ExtensionResultHolder<Set<Catalog>> catalogResult = new ExtensionResultHolder<Set<Catalog>>();
extensionManager.retrieveCatalogs(currentSite, catalogResult);
if (!CollectionUtils.isEmpty(catalogResult.getResult())) {
catalogs.addAll(catalogResult.getResult());
}
}
}
if (catalogs.size() > 0) {
catalog = catalogs.get(0);
}
}
if (catalog != null) {
if (BLCRequestUtils.isOKtoUseSession(request)) {
request.setAttribute(CATALOG_REQ_PARAM, catalog.getId(), WebRequest.SCOPE_GLOBAL_SESSION);
}
brc.setCurrentCatalog(catalog);
}
if (extensionManager != null) {
if (brc.getNonPersistentSite() != null) {
Site currentSite = siteService.retrievePersistentSiteById(brc.getNonPersistentSite().getId());
ExtensionResultHolder<Catalog> catalogResult = new ExtensionResultHolder<Catalog>();
extensionManager.overrideCurrentCatalog(request, currentSite, catalogResult);
if (catalogResult.getResult() != null) {
brc.setCurrentCatalog(catalogResult.getResult());
}
ExtensionResultHolder<Site> profileResult = new ExtensionResultHolder<Site>();
extensionManager.overrideCurrentProfile(request, currentSite, profileResult);
if (profileResult.getResult() != null) {
brc.setCurrentProfile(profileResult.getResult());
}
}
}
}
}
Aggregations