Search in sources :

Example 36 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType 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);
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) RequiredAttributeNotProvidedException(org.broadleafcommerce.core.order.service.exception.RequiredAttributeNotProvidedException) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 37 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType 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;
}
Also used : CriteriaQuery(javax.persistence.criteria.CriteriaQuery) TypedQuery(javax.persistence.TypedQuery) Query(javax.persistence.Query) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 38 with ExtensionResultStatusType

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

the class ValidateCheckoutActivity method execute.

@Override
public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context) throws Exception {
    ExtensionResultHolder<Exception> resultHolder = new ExtensionResultHolder<>();
    resultHolder.setResult(null);
    ExtensionResultStatusType result = extensionManager.getProxy().validateCheckout(context.getSeedData(), resultHolder);
    if (!ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
        if (resultHolder.getResult() != null) {
            throw resultHolder.getResult();
        }
    }
    return context;
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 39 with ExtensionResultStatusType

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

the class SolrIndexServiceImpl method attachIndexableDocumentFields.

@Override
public void attachIndexableDocumentFields(SolrInputDocument document, Indexable indexable, List<IndexField> fields, List<Locale> locales) {
    for (IndexField indexField : fields) {
        try {
            // If we find an IndexField entry for this field, then we need to store it in the index
            if (indexField != null) {
                List<IndexFieldType> searchableFieldTypes = indexField.getFieldTypes();
                // For each of its search field types, get the property values, and add a field to the document for each property value
                for (IndexFieldType sft : searchableFieldTypes) {
                    FieldType fieldType = sft.getFieldType();
                    Map<String, Object> propertyValues = getPropertyValues(indexable, indexField.getField(), fieldType, locales);
                    ExtensionResultStatusType result = extensionManager.getProxy().populateDocumentForIndexField(document, indexField, fieldType, propertyValues);
                    if (ExtensionResultStatusType.NOT_HANDLED.equals(result)) {
                        // Build out the field for every prefix
                        for (Entry<String, Object> entry : propertyValues.entrySet()) {
                            String prefix = entry.getKey();
                            prefix = StringUtils.isBlank(prefix) ? prefix : prefix + "_";
                            String solrPropertyName = shs.getPropertyNameForIndexField(indexField, fieldType, prefix);
                            Object value = entry.getValue();
                            if (FieldType.isMultiValued(fieldType)) {
                                document.addField(solrPropertyName, value);
                            } else {
                                document.setField(solrPropertyName, value);
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Could not get value for property[" + indexField.getField().getQualifiedFieldName() + "] for product id[" + indexable.getId() + "]", e);
            throw ExceptionHelper.refineException(e);
        }
    }
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) IndexField(org.broadleafcommerce.core.search.domain.IndexField) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceException(org.broadleafcommerce.common.exception.ServiceException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) FieldType(org.broadleafcommerce.core.search.domain.solr.FieldType)

Example 40 with ExtensionResultStatusType

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

the class SolrIndexServiceImpl method getPropertyValues.

/**
 * Returns a map of prefix to value for the requested attributes. For example, if the requested field corresponds to
 * a Sku's description and the locales list has the en_US locale and the es_ES locale, the resulting map could be
 *
 * { "en_US" : "A description",
 *   "es_ES" : "Una descripcion" }
 *
 * @param product
 * @param sku
 * @param field
 * @param fieldType
 * @param locales
 * @return the value of the property
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws NoSuchMethodException
 */
protected Map<String, Object> getPropertyValues(Indexable indexedItem, Field field, FieldType fieldType, List<Locale> locales) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    String propertyName = field.getPropertyName();
    Map<String, Object> values = new HashMap<>();
    ExtensionResultStatusType extensionResult = ExtensionResultStatusType.NOT_HANDLED;
    if (extensionManager != null) {
        extensionResult = extensionManager.getProxy().addPropertyValues(indexedItem, field, fieldType, values, propertyName, locales);
    }
    if (ExtensionResultStatusType.NOT_HANDLED.equals(extensionResult)) {
        Object propertyValue = shs.getPropertyValue(indexedItem, field);
        if (propertyValue != null) {
            values.put("", propertyValue);
        }
    }
    return values;
}
Also used : HashMap(java.util.HashMap) 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