Search in sources :

Example 16 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class OfferCustomPersistenceHandler method buildStackableProperty.

protected Property buildStackableProperty(Property offerItemTargetRuleType) {
    boolean stackable = isTargetType(offerItemTargetRuleType) || isQualifierTargetType(offerItemTargetRuleType);
    Property property = new Property();
    property.setName(STACKABLE);
    property.setValue(String.valueOf(stackable));
    return property;
}
Also used : Property(org.broadleafcommerce.openadmin.dto.Property)

Example 17 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class OfferCustomPersistenceHandler method addIsActiveStatus.

protected void addIsActiveStatus(RecordHelper helper, Entity entity) {
    if (isActiveFilter) {
        try {
            boolean isActive = false;
            Property startDate = entity.findProperty("startDate");
            if (startDate != null && StringUtils.isNotBlank(startDate.getValue())) {
                Property endDate = entity.findProperty("endDate");
                Date end = null;
                if (endDate != null && StringUtils.isNotBlank(endDate.getValue())) {
                    end = helper.getSimpleDateFormatter().parse(endDate.getValue());
                }
                Date date = helper.getSimpleDateFormatter().parse(startDate.getValue());
                isActive = DateUtil.isActive(date, end, true);
            }
            entity.addProperty(buildIsActiveProperty(isActive));
        } catch (ParseException e) {
            throw ExceptionHelper.refineException(e);
        }
    }
}
Also used : ParseException(java.text.ParseException) Property(org.broadleafcommerce.openadmin.dto.Property) Date(java.util.Date)

Example 18 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class OfferCustomPersistenceHandler method buildOfferItemTargetRuleTypeProperty.

protected Property buildOfferItemTargetRuleTypeProperty(Property stackable) {
    String offerItemTargetRuleType;
    boolean isStackable = stackable == null ? false : Boolean.parseBoolean(stackable.getValue());
    if (isStackable) {
        offerItemTargetRuleType = OfferItemRestrictionRuleType.QUALIFIER_TARGET.getType();
    } else {
        offerItemTargetRuleType = OfferItemRestrictionRuleType.NONE.getType();
    }
    Property property = new Property();
    property.setName(OFFER_ITEM_TARGET_RULE_TYPE);
    property.setValue(offerItemTargetRuleType);
    return property;
}
Also used : Property(org.broadleafcommerce.openadmin.dto.Property)

Example 19 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class SkuBundleItemCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        ForeignKey foreignKey = (ForeignKey) persistencePerspective.getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
        // sort it
        if (foreignKey != null && foreignKey.getSortField() != null) {
            FilterAndSortCriteria sortCriteria = cto.get(foreignKey.getSortField());
            sortCriteria.setSortAscending(foreignKey.getSortAscending());
        }
        // get the default properties from Inventory and its subclasses
        Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(SkuBundleItem.class.getName(), persistencePerspective);
        // Pull back the Inventory based on the criteria from the client
        List<FilterMapping> filterMappings = helper.getFilterMappings(persistencePerspective, cto, ceilingEntityFullyQualifiedClassname, originalProps);
        // attach the product option criteria
        skuPersistenceHandler.applyProductOptionValueCriteria(filterMappings, cto, persistencePackage, "sku");
        List<Serializable> records = helper.getPersistentRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings, cto.getFirstResult(), cto.getMaxResults());
        // Convert Skus into the client-side Entity representation
        Entity[] payload = helper.getRecords(originalProps, records);
        int totalRecords = helper.getTotalRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings);
        for (int i = 0; i < payload.length; i++) {
            Entity entity = payload[i];
            SkuBundleItem bundleItem = (SkuBundleItem) records.get(i);
            Sku bundleSku = bundleItem.getSku();
            entity.findProperty("sku").setDisplayValue(bundleSku.getName());
            List<ProductOptionValue> productOptionValues = new ArrayList<>();
            for (SkuProductOptionValueXref skuProductOptionValueXref : bundleSku.getProductOptionValueXrefs()) {
                productOptionValues.add(skuProductOptionValueXref.getProductOptionValue());
            }
            Property optionsProperty = skuPersistenceHandler.getConsolidatedOptionProperty(productOptionValues);
            entity.addProperty(optionsProperty);
        }
        return new DynamicResultSet(null, payload, totalRecords);
    } catch (Exception e) {
        throw new ServiceException("There was a problem fetching inventory. See server logs for more details", e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) ArrayList(java.util.ArrayList) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) ForeignKey(org.broadleafcommerce.openadmin.dto.ForeignKey) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) SkuProductOptionValueXref(org.broadleafcommerce.core.catalog.domain.SkuProductOptionValueXref) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) FilterAndSortCriteria(org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 20 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class SkuCustomPersistenceHandler method validateUniqueProductOptionValueCombination.

/**
 * Ensures that the given list of {@link ProductOptionValue} IDs is unique for the given {@link Product}.
 *
 * If sku browsing is enabled, then it is assumed that a single combination of {@link ProductOptionValue} IDs
 * is not unique and more than one {@link Sku} could have the exact same combination of {@link ProductOptionValue} IDs.
 * In this case, the following validation is skipped.
 *
 * @param product
 * @param productOptionProperties
 * @param currentSku - for update operations, this is the current Sku that is being updated; should be excluded from
 * attempting validation
 * @return <b>null</b> if successfully validation, the error entity otherwise
 */
protected Entity validateUniqueProductOptionValueCombination(Product product, List<Property> productOptionProperties, Sku currentSku) {
    if (useSku) {
        return null;
    }
    // do not attempt POV validation if no PO properties were passed in
    if (CollectionUtils.isNotEmpty(productOptionProperties)) {
        List<Long> productOptionValueIds = new ArrayList<>();
        for (Property property : productOptionProperties) {
            productOptionValueIds.add(Long.parseLong(property.getValue()));
        }
        boolean validated = true;
        for (Sku sku : product.getAdditionalSkus()) {
            if (currentSku == null || !sku.getId().equals(currentSku.getId())) {
                List<Long> testList = new ArrayList<>();
                for (ProductOptionValue optionValue : sku.getProductOptionValues()) {
                    testList.add(optionValue.getId());
                }
                if (CollectionUtils.isNotEmpty(testList) && productOptionValueIds.containsAll(testList) && productOptionValueIds.size() == testList.size()) {
                    validated = false;
                    break;
                }
            }
        }
        if (!validated) {
            Entity errorEntity = new Entity();
            for (Property productOptionProperty : productOptionProperties) {
                errorEntity.addValidationError(productOptionProperty.getName(), "uniqueSkuError");
            }
            return errorEntity;
        }
    }
    return null;
}
Also used : ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) Entity(org.broadleafcommerce.openadmin.dto.Entity) ArrayList(java.util.ArrayList) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

Property (org.broadleafcommerce.openadmin.dto.Property)120 Entity (org.broadleafcommerce.openadmin.dto.Entity)62 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)45 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)38 ArrayList (java.util.ArrayList)28 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)26 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)25 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)21 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 HashMap (java.util.HashMap)18 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 Map (java.util.Map)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)15 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)12 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)12