Search in sources :

Example 16 with ExtensionResultStatusType

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

the class CatalogServiceImpl method findProductByURI.

@Override
public Product findProductByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findProductByURI(createCatalogContextDTO(), uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Product) holder.getResult();
        }
    }
    return findOriginalProductByURI(uri);
}
Also used : Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 17 with ExtensionResultStatusType

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

the class CatalogServiceImpl method findCategoryByURI.

@Override
public Category findCategoryByURI(String uri) {
    if (extensionManager != null) {
        ExtensionResultHolder holder = new ExtensionResultHolder();
        ExtensionResultStatusType result = extensionManager.getProxy().findCategoryByURI(createCatalogContextDTO(), uri, holder);
        if (ExtensionResultStatusType.HANDLED.equals(result)) {
            return (Category) holder.getResult();
        }
    }
    return findOriginalCategoryByURI(uri);
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 18 with ExtensionResultStatusType

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

the class InventoryServiceImpl method retrieveQuantitiesAvailable.

@Override
public Map<Sku, Integer> retrieveQuantitiesAvailable(Collection<Sku> skus, Map<String, Object> context) {
    ExtensionResultHolder<Map<Sku, Integer>> holder = new ExtensionResultHolder<Map<Sku, Integer>>();
    ExtensionResultStatusType res = extensionManager.getProxy().retrieveQuantitiesAvailable(skus, context, holder);
    if (ExtensionResultStatusType.NOT_HANDLED.equals(res)) {
        Map<Sku, Integer> inventories = new HashMap<>();
        for (Sku sku : skus) {
            Integer quantityAvailable = 0;
            if (checkBasicAvailablility(sku)) {
                InventoryType skuInventoryType = sku.getInventoryType();
                if (InventoryType.CHECK_QUANTITY.equals(skuInventoryType)) {
                    if (sku.getQuantityAvailable() != null) {
                        quantityAvailable = sku.getQuantityAvailable();
                    }
                } else if (sku.getInventoryType() == null || InventoryType.ALWAYS_AVAILABLE.equals(skuInventoryType)) {
                    quantityAvailable = null;
                }
            }
            inventories.put(sku, quantityAvailable);
        }
        return inventories;
    } else {
        return holder.getResult();
    }
}
Also used : HashMap(java.util.HashMap) InventoryType(org.broadleafcommerce.core.inventory.service.type.InventoryType) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Sku(org.broadleafcommerce.core.catalog.domain.Sku) HashMap(java.util.HashMap) Map(java.util.Map) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 19 with ExtensionResultStatusType

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

the class CategoryCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        entity = validateParentCategory(entity, true);
        if (entity.isValidationFailure()) {
            return entity;
        } else {
            PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
            Category adminInstance = (Category) Class.forName(entity.getType()[0]).newInstance();
            Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective);
            adminInstance = (Category) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
            adminInstance = dynamicEntityDao.merge(adminInstance);
            boolean handled = false;
            if (extensionManager != null) {
                ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForAdd(persistencePackage, adminInstance);
                handled = ExtensionResultStatusType.NOT_HANDLED != result;
            }
            if (!handled) {
                setupXref(adminInstance);
            }
            adminInstance = dynamicEntityDao.merge(adminInstance);
            return helper.getRecord(adminProperties, adminInstance, null, null);
        }
    } catch (Exception e) {
        throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Category(org.broadleafcommerce.core.catalog.domain.Category) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 20 with ExtensionResultStatusType

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

the class IndexFieldCustomPersistenceHandler method getEntity.

protected Entity getEntity(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity, Map<String, FieldMetadata> adminProperties, IndexField adminInstance) throws ServiceException {
    adminInstance = (IndexField) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
    adminInstance = dynamicEntityDao.merge(adminInstance);
    ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
    if (extensionManager != null) {
        result = extensionManager.getProxy().addtoSearchableFields(persistencePackage, adminInstance);
    }
    if (result.equals(ExtensionResultStatusType.NOT_HANDLED)) {
        // If there is no searchable field types then we need to add a default as String
        if (CollectionUtils.isEmpty(adminInstance.getFieldTypes())) {
            IndexFieldType indexFieldType = new IndexFieldTypeImpl();
            indexFieldType.setFieldType(FieldType.TEXT);
            indexFieldType.setIndexField(adminInstance);
            adminInstance.getFieldTypes().add(indexFieldType);
            adminInstance = dynamicEntityDao.merge(adminInstance);
        }
    }
    Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
    return adminEntity;
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) Entity(org.broadleafcommerce.openadmin.dto.Entity) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Aggregations

ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)59 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)35 ArrayList (java.util.ArrayList)11 Product (org.broadleafcommerce.core.catalog.domain.Product)9 Category (org.broadleafcommerce.core.catalog.domain.Category)7 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)7 ServiceException (org.broadleafcommerce.common.exception.ServiceException)6 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 Entity (org.broadleafcommerce.openadmin.dto.Entity)6 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)6 FieldNotAvailableException (org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException)5 List (java.util.List)4 Query (javax.persistence.Query)4 TypedQuery (javax.persistence.TypedQuery)4 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)4 IndexFieldType (org.broadleafcommerce.core.search.domain.IndexFieldType)4 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)4 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 File (java.io.File)3