Search in sources :

Example 76 with Entity

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

the class SkuCustomPersistenceHandler method updateProductOptionFieldsForFetch.

/**
 * Sets the {@link ProductOptionValue}s of the given {@link Sku}s in a list format for display in a ListGrid context.
 *
 * @param records
 * @param payload
 * @return
 */
public void updateProductOptionFieldsForFetch(List<Serializable> records, Entity[] payload) {
    for (int i = 0; i < records.size(); i++) {
        Sku sku = (Sku) records.get(i);
        Entity entity = payload[i];
        List<ProductOptionValue> optionValues = BLCCollectionUtils.collectList(sku.getProductOptionValueXrefs(), new TypedTransformer<ProductOptionValue>() {

            @Override
            public ProductOptionValue transform(Object input) {
                return ((SkuProductOptionValueXref) input).getProductOptionValue();
            }
        });
        for (ProductOptionValue value : optionValues) {
            Property optionProperty = new Property();
            optionProperty.setName(PRODUCT_OPTION_FIELD_PREFIX + value.getProductOption().getId());
            optionProperty.setValue(value.getId().toString());
            optionProperty.setDisplayValue(value.getAttributeValue());
            entity.addProperty(optionProperty);
        }
        if (CollectionUtils.isNotEmpty(optionValues)) {
            entity.addProperty(getConsolidatedOptionProperty(optionValues));
        } else {
            entity.addProperty(getBlankConsolidatedOptionProperty());
        }
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 77 with Entity

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

the class SkuCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        // Fill out the Sku instance from the form
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Sku adminInstance = (Sku) Class.forName(entity.getType()[0]).newInstance();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
        filterOutProductMetadata(adminProperties);
        adminInstance = (Sku) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        // Verify that there isn't already a Sku for this particular product option value combo
        Entity errorEntity = validateUniqueProductOptionValueCombination(adminInstance.getProduct(), getProductOptionProperties(entity), null);
        if (errorEntity != null) {
            entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
            return entity;
        }
        // persist the newly-created Sku
        adminInstance = dynamicEntityDao.persist(adminInstance);
        // associate the product option values
        associateProductOptionValuesToSku(entity, adminInstance, dynamicEntityDao);
        // After associating the product option values, save off the Sku
        adminInstance = dynamicEntityDao.merge(adminInstance);
        // Fill out the DTO and add in the product option value properties to it
        Entity result = helper.getRecord(adminProperties, adminInstance, null, null);
        for (Property property : getProductOptionProperties(entity)) {
            result.addProperty(property);
        }
        return result;
    } catch (Exception e) {
        throw new ServiceException("Unable to perform fetch for entity: " + Sku.class.getName(), e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Property(org.broadleafcommerce.openadmin.dto.Property) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 78 with Entity

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

the class CategoryCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        entity = validateParentCategory(entity, false);
        if (entity.isValidationFailure()) {
            return entity;
        } else {
            PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
            Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective);
            Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
            Category adminInstance = (Category) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
            CategoryXref oldDefault = getCurrentDefaultXref(adminInstance);
            adminInstance = (Category) 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;
            }
            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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) Category(org.broadleafcommerce.core.catalog.domain.Category) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 79 with Entity

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

the class CustomerPasswordCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    Customer customer = customerService.readCustomerByUsername(entity.findProperty("username").getValue());
    if (StringUtils.isEmpty(customer.getEmailAddress())) {
        throw new ServiceException("Unable to update password because an email address is not available for this customer. An email address is required to send the customer the new system generated password.");
    }
    PasswordReset passwordReset = new PasswordReset();
    passwordReset.setUsername(entity.findProperty("username").getValue());
    passwordReset.setPasswordChangeRequired(false);
    passwordReset.setEmail(customer.getEmailAddress());
    passwordReset.setPasswordLength(22);
    passwordReset.setSendResetEmailReliableAsync(false);
    customer = customerService.resetPassword(passwordReset);
    return entity;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) PasswordReset(org.broadleafcommerce.common.security.util.PasswordReset)

Example 80 with Entity

use of org.broadleafcommerce.openadmin.dto.Entity 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)

Aggregations

Entity (org.broadleafcommerce.openadmin.dto.Entity)112 Property (org.broadleafcommerce.openadmin.dto.Property)62 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)51 ServiceException (org.broadleafcommerce.common.exception.ServiceException)48 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)36 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)34 ArrayList (java.util.ArrayList)25 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)24 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)24 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)20 Serializable (java.io.Serializable)19 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)19 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)17 Map (java.util.Map)16 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)16 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)16 HashMap (java.util.HashMap)15 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14