use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class RuleFieldPersistenceProvider method transformId.
protected Long transformId(Long id, Object rule) {
if (extensionManager != null) {
ExtensionResultHolder<Long> resultHolder = new ExtensionResultHolder<Long>();
ExtensionResultStatusType result = extensionManager.getProxy().transformId(rule, resultHolder);
if (ExtensionResultStatusType.NOT_HANDLED != result && resultHolder.getResult() != null) {
id = resultHolder.getResult();
}
}
return id;
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class BasicFieldPersistenceProvider method extractValue.
@Override
public MetadataProviderResponse extractValue(ExtractValueRequest extractValueRequest, Property property) throws PersistenceException {
if (!canHandleExtraction(extractValueRequest, property)) {
return MetadataProviderResponse.NOT_HANDLED;
}
try {
if (extractValueRequest.getRequestedValue() != null) {
String val = null;
if (extractValueRequest.getMetadata().getForeignKeyCollection()) {
((BasicFieldMetadata) property.getMetadata()).setFieldType(extractValueRequest.getMetadata().getFieldType());
} else if (extractValueRequest.getMetadata().getFieldType().equals(SupportedFieldType.BOOLEAN) && extractValueRequest.getRequestedValue() instanceof Character) {
val = (extractValueRequest.getRequestedValue().equals('Y')) ? "true" : "false";
} else if (Date.class.isAssignableFrom(extractValueRequest.getRequestedValue().getClass())) {
val = extractValueRequest.getDataFormatProvider().getSimpleDateFormatter().format((Date) extractValueRequest.getRequestedValue());
} else if (Timestamp.class.isAssignableFrom(extractValueRequest.getRequestedValue().getClass())) {
val = extractValueRequest.getDataFormatProvider().getSimpleDateFormatter().format(new Date(((Timestamp) extractValueRequest.getRequestedValue()).getTime()));
} else if (Calendar.class.isAssignableFrom(extractValueRequest.getRequestedValue().getClass())) {
val = extractValueRequest.getDataFormatProvider().getSimpleDateFormatter().format(((Calendar) extractValueRequest.getRequestedValue()).getTime());
} else if (Double.class.isAssignableFrom(extractValueRequest.getRequestedValue().getClass())) {
val = extractValueRequest.getDataFormatProvider().getDecimalFormatter().format(extractValueRequest.getRequestedValue());
} else if (BigDecimal.class.isAssignableFrom(extractValueRequest.getRequestedValue().getClass())) {
BigDecimal decimal = (BigDecimal) extractValueRequest.getRequestedValue();
DecimalFormat format = extractValueRequest.getDataFormatProvider().getDecimalFormatter();
// track all the decimal places in the scale of the BigDecimal - even if they're all zeros
StringBuilder sb = new StringBuilder();
sb.append("0");
if (decimal.scale() > 0) {
sb.append(".");
for (int j = 0; j < decimal.scale(); j++) {
sb.append("0");
}
}
format.applyPattern(sb.toString());
val = format.format(extractValueRequest.getRequestedValue());
} else if (extractValueRequest.getMetadata().getForeignKeyClass() != null) {
try {
val = extractValueRequest.getFieldManager().getFieldValue(extractValueRequest.getRequestedValue(), extractValueRequest.getMetadata().getForeignKeyProperty()).toString();
if (extensionManager != null) {
ExtensionResultHolder<Serializable> resultHolder = new ExtensionResultHolder<Serializable>();
ExtensionResultStatusType result = extensionManager.getProxy().transformForeignKey(extractValueRequest, property, resultHolder);
if (ExtensionResultStatusType.NOT_HANDLED != result && resultHolder.getResult() != null) {
val = String.valueOf(resultHolder.getResult());
}
}
// see if there's a name property and use it for the display value
String entityName = null;
if (extractValueRequest.getRequestedValue() instanceof AdminMainEntity) {
entityName = ((AdminMainEntity) extractValueRequest.getRequestedValue()).getMainEntityName();
}
Object temp = null;
if (!StringUtils.isEmpty(extractValueRequest.getMetadata().getForeignKeyDisplayValueProperty())) {
String nameProperty = extractValueRequest.getMetadata().getForeignKeyDisplayValueProperty();
try {
temp = extractValueRequest.getFieldManager().getFieldValue(extractValueRequest.getRequestedValue(), nameProperty);
} catch (FieldNotAvailableException e) {
// do nothing
}
}
if (temp == null && StringUtils.isEmpty(entityName)) {
try {
temp = extractValueRequest.getFieldManager().getFieldValue(extractValueRequest.getRequestedValue(), "name");
} catch (FieldNotAvailableException e) {
// do nothing
}
}
if (temp != null) {
extractValueRequest.setDisplayVal(temp.toString());
} else if (!StringUtils.isEmpty(entityName)) {
extractValueRequest.setDisplayVal(entityName);
}
} catch (FieldNotAvailableException e) {
throw new IllegalArgumentException(e);
}
} else if (SupportedFieldType.ID == extractValueRequest.getMetadata().getFieldType()) {
val = extractValueRequest.getRequestedValue().toString();
if (extensionManager != null) {
ExtensionResultHolder<Serializable> resultHolder = new ExtensionResultHolder<Serializable>();
ExtensionResultStatusType result = extensionManager.getProxy().transformId(extractValueRequest, property, resultHolder);
if (ExtensionResultStatusType.NOT_HANDLED != result && resultHolder.getResult() != null) {
val = String.valueOf(resultHolder.getResult());
}
}
} else {
val = extractValueRequest.getRequestedValue().toString();
}
property.setValue(val);
property.setDisplayValue(extractValueRequest.getDisplayVal());
}
} catch (IllegalAccessException e) {
throw new PersistenceException(e);
}
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class AdornedTargetMaintainedFieldPropertyValidator method validate.
@Override
public PropertyValidationResult validate(Entity entity, Serializable instance, Map<String, FieldMetadata> entityFieldMetadata, BasicFieldMetadata propertyMetadata, String propertyName, String value) {
ExtensionResultHolder<Boolean> validationResult = new ExtensionResultHolder<Boolean>();
ExtensionResultStatusType status = adornedTargetAutoPopulateExtensionManager.getProxy().validateSubmittedAdornedTargetManagedFields(entity, instance, entityFieldMetadata, propertyMetadata, propertyName, value, validationResult);
Boolean valid = true;
if (ExtensionResultStatusType.NOT_HANDLED != status && validationResult.getResult() != null) {
valid = validationResult.getResult();
}
return new PropertyValidationResult(valid, ERROR_MESSAGE);
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class CategoriesProcessor method populateModelVariables.
@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
String resultVar = tagAttributes.get("resultVar");
String parentCategory = tagAttributes.get("parentCategory");
String unparsedMaxResults = tagAttributes.get("maxResults");
Map<String, Object> newModelVars = new HashMap<>();
if (extensionManager != null) {
ExtensionResultHolder holder = new ExtensionResultHolder();
ExtensionResultStatusType result = extensionManager.getProxy().findAllPossibleChildCategories(parentCategory, unparsedMaxResults, holder);
if (ExtensionResultStatusType.HANDLED.equals(result)) {
newModelVars.put(resultVar, holder.getResult());
return newModelVars;
}
}
// TODO: Potentially write an algorithm that will pick the minimum depth category
// instead of the first category in the list
List<Category> categories = catalogService.findCategoriesByName(parentCategory);
if (categories != null && categories.size() > 0) {
// gets child categories in order ONLY if they are in the xref table and active
List<CategoryXref> subcategories = categories.get(0).getChildCategoryXrefs();
List<Category> results = Collections.emptyList();
if (subcategories != null && !subcategories.isEmpty()) {
results = new ArrayList<>(subcategories.size());
if (StringUtils.isNotEmpty(unparsedMaxResults)) {
int maxResults = Integer.parseInt(unparsedMaxResults);
if (subcategories.size() > maxResults) {
subcategories = subcategories.subList(0, maxResults);
}
}
for (CategoryXref xref : subcategories) {
results.add(xref.getSubCategory());
}
}
newModelVars.put(resultVar, results);
}
return newModelVars;
}
use of org.broadleafcommerce.common.extension.ExtensionResultHolder in project BroadleafCommerce by BroadleafCommerce.
the class ProductOptionsProcessor method createPricingDto.
protected ProductOptionPricingDTO createPricingDto(Sku sku, List<Long> productOptionValueIds, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
Long[] values = new Long[productOptionValueIds.size()];
productOptionValueIds.toArray(values);
ProductOptionPricingDTO dto = new ProductOptionPricingDTO();
Money currentPrice = sku.getPrice();
// Check for Price Overrides
ExtensionResultHolder<Money> priceHolder = new ExtensionResultHolder<>();
priceHolder.setResult(currentPrice);
if (extensionManager != null) {
extensionManager.getProxy().modifyPriceForOverrides(sku, priceHolder, context, tagAttributes);
}
dto.setPrice(BLCMoneyFormatUtils.formatPrice(priceHolder.getResult()));
if (sku.getRetailPrice() != null) {
dto.setRetailPrice(BLCMoneyFormatUtils.formatPrice(sku.getRetailPrice()));
}
if (sku.getSalePrice() != null) {
dto.setSalePrice(BLCMoneyFormatUtils.formatPrice(sku.getSalePrice()));
}
dto.setOnSale(sku.isOnSale());
dto.setSelectedOptions(values);
return dto;
}
Aggregations