Search in sources :

Example 51 with ExtensionResultStatusType

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

Example 52 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType 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;
}
Also used : Serializable(java.io.Serializable) Calendar(java.util.Calendar) DecimalFormat(java.text.DecimalFormat) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Timestamp(java.sql.Timestamp) Date(java.util.Date) BigDecimal(java.math.BigDecimal) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FieldNotAvailableException(org.broadleafcommerce.openadmin.server.service.persistence.module.FieldNotAvailableException) PersistenceException(org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder) AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity)

Example 53 with ExtensionResultStatusType

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

Example 54 with ExtensionResultStatusType

use of org.broadleafcommerce.common.extension.ExtensionResultStatusType 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;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) HashMap(java.util.HashMap) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref) ExtensionResultHolder(org.broadleafcommerce.common.extension.ExtensionResultHolder)

Example 55 with ExtensionResultStatusType

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

the class SolrHelperServiceImpl method getCategoryId.

@Override
public Long getCategoryId(Long category) {
    Long[] returnId = new Long[1];
    // TODO (qa 607) Need to review the performance of retrieval of the Category instance here every time (using the id version breaks for indexing derived catalogs)
    ExtensionResultStatusType result = searchExtensionManager.getProxy().getCategoryId(genericEntityDao.readGenericEntity(CategoryImpl.class, category), returnId);
    if (result.equals(ExtensionResultStatusType.HANDLED)) {
        return returnId[0];
    }
    return category;
}
Also used : CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) 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