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