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