Search in sources :

Example 26 with ExtensionResultStatusType

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

the class SolrHelperServiceImpl method attachFacets.

@Override
public void attachFacets(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) {
    query.setFacet(true);
    for (Entry<String, SearchFacetDTO> entry : namedFacetMap.entrySet()) {
        SearchFacetDTO dto = entry.getValue();
        ExtensionResultStatusType status = searchExtensionManager.getProxy().attachFacet(query, entry.getKey(), dto, searchCriteria);
        if (ExtensionResultStatusType.NOT_HANDLED.equals(status)) {
            List<SearchFacetRange> facetRanges = searchFacetDao.readSearchFacetRangesForSearchFacet(dto.getFacet());
            if (searchExtensionManager != null) {
                searchExtensionManager.getProxy().filterSearchFacetRanges(dto, facetRanges);
            }
            if (CollectionUtils.isNotEmpty(facetRanges)) {
                for (SearchFacetRange range : facetRanges) {
                    query.addFacetQuery(getSolrTaggedFieldString(entry.getKey(), "key", range));
                }
            } else {
                query.addFacetField(getSolrTaggedFieldString(entry.getKey(), "ex", null));
            }
        }
    }
}
Also used : SearchFacetRange(org.broadleafcommerce.core.search.domain.SearchFacetRange) SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 27 with ExtensionResultStatusType

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

the class SolrHelperServiceImpl method attachActiveFacetFilters.

@Override
public void attachActiveFacetFilters(SolrQuery query, Map<String, SearchFacetDTO> namedFacetMap, SearchCriteria searchCriteria) {
    if (searchCriteria.getFilterCriteria() != null) {
        for (Entry<String, String[]> entry : searchCriteria.getFilterCriteria().entrySet()) {
            String solrKey = null;
            for (Entry<String, SearchFacetDTO> dtoEntry : namedFacetMap.entrySet()) {
                if (dtoEntry.getValue().getFacet().getField().getAbbreviation().equals(entry.getKey())) {
                    solrKey = dtoEntry.getKey();
                    dtoEntry.getValue().setActive(true);
                }
            }
            if (solrKey != null) {
                String[] selectedValues = entry.getValue().clone();
                boolean rangeQuery = false;
                for (int i = 0; i < selectedValues.length; i++) {
                    if (selectedValues[i].contains("range[")) {
                        rangeQuery = true;
                        String rangeValue = selectedValues[i].substring(selectedValues[i].indexOf('[') + 1, selectedValues[i].indexOf(']'));
                        String[] rangeValues = StringUtils.split(rangeValue, ':');
                        BigDecimal minValue = new BigDecimal(rangeValues[0]);
                        BigDecimal maxValue = null;
                        if (!rangeValues[1].equals("null")) {
                            maxValue = new BigDecimal(rangeValues[1]);
                        }
                        selectedValues[i] = getSolrRangeString(solrKey, minValue, maxValue);
                    } else {
                        selectedValues[i] = "\"" + scrubFacetValue(selectedValues[i]) + "\"";
                    }
                }
                List<String> valueStrings = new ArrayList<>();
                ExtensionResultStatusType status = searchExtensionManager.getProxy().buildActiveFacetFilter(namedFacetMap.get(solrKey).getFacet(), selectedValues, valueStrings);
                if (ExtensionResultStatusType.NOT_HANDLED.equals(status)) {
                    StringBuilder valueString = new StringBuilder();
                    if (rangeQuery) {
                        valueString.append(solrKey).append(":(");
                        valueString.append(StringUtils.join(selectedValues, " OR "));
                        valueString.append(")");
                    } else {
                        valueString.append("{!tag=").append(solrKey).append("}");
                        valueString.append(solrKey).append(":(");
                        valueString.append(StringUtils.join(selectedValues, " OR "));
                        valueString.append(")");
                    }
                    valueStrings.add(valueString.toString());
                }
                query.addFilterQuery(valueStrings.toArray(new String[valueStrings.size()]));
            }
        }
    }
}
Also used : SearchFacetDTO(org.broadleafcommerce.core.search.domain.SearchFacetDTO) ArrayList(java.util.ArrayList) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) BigDecimal(java.math.BigDecimal)

Example 28 with ExtensionResultStatusType

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

the class SolrHelperServiceImpl method getPropertyNameForIndexField.

@Override
public String getPropertyNameForIndexField(IndexField field, FieldType fieldType, String prefix) {
    ExtensionResultHolder<String> erh = new ExtensionResultHolder<>();
    ExtensionResultStatusType result = searchExtensionManager.getProxy().getPropertyNameForIndexField(field, fieldType, prefix, erh);
    if (!ExtensionResultStatusType.NOT_HANDLED.equals(result) && erh.getResult() != null) {
        return erh.getResult();
    }
    String fieldName = field.getField().getAbbreviation();
    if (StringUtils.isEmpty(fieldName)) {
        fieldName = field.getField().getPropertyName();
    }
    return new StringBuilder().append(prefix).append(fieldName).append("_").append(fieldType.getType()).toString();
}
Also used : ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 29 with ExtensionResultStatusType

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

the class SparseTranslationOverrideStrategy method initializeOverride.

@Override
public StandardCacheItem initializeOverride(Object entity) {
    String key = getCacheKey((Translation) entity);
    String dto = ((Translation) entity).getTranslatedValue();
    StandardCacheItem cacheItem = new StandardCacheItem();
    ItemStatus status = ItemStatus.NORMAL;
    if (extensionManager != null) {
        ExtensionResultHolder<ItemStatus> response = new ExtensionResultHolder<ItemStatus>();
        ExtensionResultStatusType result = extensionManager.buildStatus(entity, response);
        if (ExtensionResultStatusType.NOT_HANDLED != result && response.getResult() != null) {
            status = response.getResult();
        }
    }
    cacheItem.setItemStatus(status);
    cacheItem.setKey(key);
    cacheItem.setCacheItem(dto);
    return cacheItem;
}
Also used : ItemStatus(org.broadleafcommerce.common.extension.ItemStatus) Translation(org.broadleafcommerce.common.i18n.domain.Translation) StandardCacheItem(org.broadleafcommerce.common.extension.StandardCacheItem) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 30 with ExtensionResultStatusType

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

the class ProductCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Product.class.getName(), persistencePerspective);
        BasicFieldMetadata defaultCategory = ((BasicFieldMetadata) adminProperties.get("defaultCategory"));
        defaultCategory.setFriendlyName("ProductImpl_Parent_Category");
        if (entity.findProperty("defaultCategory") != null && !StringUtils.isEmpty(entity.findProperty("defaultCategory").getValue())) {
            // Change the inherited type so that this property is disconnected from the entity and validation is temporarily skipped.
            // This is useful when the defaultCategory was previously completely empty for whatever reason. Without this, such
            // a case would fail the validation, even though the property was specified in the submission.
            defaultCategory.setInheritedFromType(String.class.getName());
        }
        Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
        Product adminInstance = (Product) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
        if (adminInstance instanceof ProductBundle) {
            removeBundleFieldRestrictions((ProductBundle) adminInstance, adminProperties, entity);
        }
        CategoryProductXref oldDefault = getCurrentDefaultXref(adminInstance);
        // so override required flag for that field during deployment
        if (BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
            ((BasicFieldMetadata) adminProperties.get("defaultCategory")).setRequiredOverride(false);
        }
        adminInstance = (Product) 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;
            extensionManager.getProxy().manageFields(persistencePackage, adminInstance);
        }
        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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)

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