Search in sources :

Example 31 with DynamicResultSet

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

the class OfferCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    addIsActiveFiltering(cto);
    DynamicResultSet resultSet = helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
    String customCriteria = "";
    if (persistencePackage.getCustomCriteria().length > 0) {
        customCriteria = persistencePackage.getCustomCriteria()[0];
    }
    for (Entity entity : resultSet.getRecords()) {
        Property discountType = entity.findProperty("discountType");
        Property discountValue = entity.findProperty("value");
        String value = discountValue.getValue();
        if (discountType == null || StringUtils.isBlank(discountType.getValue())) {
            discountValue.setValue("");
        } else if (discountType.getValue().equals("PERCENT_OFF")) {
            value = !value.contains(".") ? value : value.replaceAll("0*$", "").replaceAll("\\.$", "");
            discountValue.setValue(value + "%");
        } else if (discountType.getValue().equals("AMOUNT_OFF")) {
            Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
            BroadleafCurrency currency = BroadleafRequestContext.getBroadleafRequestContext().getBroadleafCurrency();
            NumberFormat nf = BroadleafCurrencyUtils.getNumberFormatFromCache(locale.getJavaLocale(), currency.getJavaCurrency());
            discountValue.setValue(nf.format(new BigDecimal(value)));
        }
        Property timeRule = entity.findProperty("offerMatchRules---TIME");
        entity.addProperty(buildAdvancedVisibilityOptionsProperty(timeRule));
        Property offerItemQualifierRuleType = entity.findProperty(OFFER_ITEM_QUALIFIER_RULE_TYPE);
        entity.addProperty(buildQualifiersCanBeQualifiersProperty(offerItemQualifierRuleType));
        entity.addProperty(buildQualifiersCanBeTargetsProperty(offerItemQualifierRuleType));
        Property offerItemTargetRuleType = entity.findProperty(OFFER_ITEM_TARGET_RULE_TYPE);
        entity.addProperty(buildStackableProperty(offerItemTargetRuleType));
        if (!"listGridView".equals(customCriteria)) {
            String setValue = discountValue.getValue();
            setValue = setValue.replaceAll("\\%", "").replaceAll("\\$", "");
            discountValue.setValue(setValue);
        }
        addIsActiveStatus(helper, entity);
    }
    return resultSet;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) Entity(org.broadleafcommerce.openadmin.dto.Entity) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Property(org.broadleafcommerce.openadmin.dto.Property) BigDecimal(java.math.BigDecimal) NumberFormat(java.text.NumberFormat)

Example 32 with DynamicResultSet

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

the class SkuBundleItemCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
        // retrieve the default properties for Inventory
        Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(SkuBundleItem.class.getName(), persistencePerspective);
        // add in the consolidated product options field
        FieldMetadata options = skuPersistenceHandler.createConsolidatedOptionField(SkuBundleItemImpl.class);
        options.setOrder(3);
        properties.put(SkuCustomPersistenceHandler.CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME, options);
        allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
        Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(SkuBundleItem.class);
        ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
        return new DynamicResultSet(mergedMetadata, null, null);
    } catch (Exception e) {
        String className = persistencePackage.getCeilingEntityFullyQualifiedClassname();
        ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + className, e);
        LOG.error("Unable to retrieve inspection results for " + className, ex);
        throw ex;
    }
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) HashMap(java.util.HashMap) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) ServiceException(org.broadleafcommerce.common.exception.ServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 33 with DynamicResultSet

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

the class SkuCustomPersistenceHandler method fetch.

@SuppressWarnings("unchecked")
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        // get the default properties from Sku and its subclasses
        Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
        // Pull back the Skus based on the criteria from the client
        List<FilterMapping> filterMappings = helper.getFilterMappings(persistencePerspective, cto, ceilingEntityFullyQualifiedClassname, originalProps);
        // allow subclasses to provide additional criteria before executing the query
        applyProductOptionValueCriteria(filterMappings, cto, persistencePackage, null);
        applySkuBundleItemValueCriteria(filterMappings, cto, persistencePackage);
        applyAdditionalFetchCriteria(filterMappings, cto, persistencePackage);
        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);
        // Now fill out the relevant properties for the product options for the Skus that were returned
        updateProductOptionFieldsForFetch(records, payload);
        return new DynamicResultSet(payload, totalRecords);
    } catch (Exception e) {
        throw new ServiceException("Unable to perform fetch for entity: " + ceilingEntityFullyQualifiedClassname, e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Serializable(java.io.Serializable) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) FilterMapping(org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping) ServiceException(org.broadleafcommerce.common.exception.ServiceException) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Sku(org.broadleafcommerce.core.catalog.domain.Sku) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 34 with DynamicResultSet

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

the class CustomerPaymentCustomPersistenceHandler method fetch.

@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    OperationType fetchType = persistencePackage.getPersistencePerspective().getOperationTypes().getFetchType();
    PersistenceModule persistenceModule = helper.getCompatibleModule(fetchType);
    DynamicResultSet drs = persistenceModule.fetch(persistencePackage, cto);
    for (Entity entity : drs.getRecords()) {
        Property customerPaymentId = entity.findProperty("id");
        if (customerPaymentId != null) {
            CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(Long.parseLong(customerPaymentId.getValue()));
            if (customerPayment != null) {
                String savedPaymentDisplayValue = buildSavedPaymentDisplayValue(customerPayment);
                Property derivedLabel = new Property();
                derivedLabel.setName(SAVED_PAYMENT_INFO);
                derivedLabel.setValue(savedPaymentDisplayValue);
                entity.addProperty(derivedLabel);
            }
        }
    }
    return drs;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) OperationType(org.broadleafcommerce.common.presentation.client.OperationType) PersistenceModule(org.broadleafcommerce.openadmin.server.service.persistence.module.PersistenceModule) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 35 with DynamicResultSet

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

the class CustomerPaymentCustomPersistenceHandler method inspect.

@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
    Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
    PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
    Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(CustomerPayment.class.getName(), persistencePerspective);
    // Hide "Payment Gateway Type" column & create "Saved Payment Info" ListGrid column
    FieldMetadata paymentGatewayType = properties.get("paymentGatewayType");
    if (paymentGatewayType != null) {
        ((BasicFieldMetadata) paymentGatewayType).setProminent(false);
    }
    BasicFieldMetadata savedPaymentInfo = new BasicFieldMetadata();
    savedPaymentInfo.setName(SAVED_PAYMENT_INFO);
    savedPaymentInfo.setFriendlyName("CustomerPaymentImpl_Saved_Payment_Info");
    savedPaymentInfo.setFieldType(SupportedFieldType.STRING);
    savedPaymentInfo.setInheritedFromType(CustomerPaymentImpl.class.getName());
    savedPaymentInfo.setAvailableToTypes(new String[] { CustomerPaymentImpl.class.getName() });
    savedPaymentInfo.setProminent(true);
    savedPaymentInfo.setGridOrder(2000);
    savedPaymentInfo.setReadOnly(true);
    savedPaymentInfo.setVisibility(VisibilityEnum.FORM_HIDDEN);
    properties.put(SAVED_PAYMENT_INFO, savedPaymentInfo);
    allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
    Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(CustomerPayment.class);
    ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
    return new DynamicResultSet(mergedMetadata, null, null);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CustomerPaymentImpl(org.broadleafcommerce.profile.core.domain.CustomerPaymentImpl) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Aggregations

DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)44 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)26 Entity (org.broadleafcommerce.openadmin.dto.Entity)20 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)18 Property (org.broadleafcommerce.openadmin.dto.Property)16 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)16 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)14 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)14 HashMap (java.util.HashMap)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 Map (java.util.Map)10 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)9 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)7 FilterAndSortCriteria (org.broadleafcommerce.openadmin.dto.FilterAndSortCriteria)7 MergedPropertyType (org.broadleafcommerce.openadmin.dto.MergedPropertyType)7 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)7 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)6 FilterMapping (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping)6 Serializable (java.io.Serializable)5