Search in sources :

Example 46 with Entity

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

the class CategoryCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        entity = validateParentCategory(entity, true);
        if (entity.isValidationFailure()) {
            return entity;
        } else {
            PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
            Category adminInstance = (Category) Class.forName(entity.getType()[0]).newInstance();
            Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective);
            adminInstance = (Category) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
            adminInstance = dynamicEntityDao.merge(adminInstance);
            boolean handled = false;
            if (extensionManager != null) {
                ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForAdd(persistencePackage, adminInstance);
                handled = ExtensionResultStatusType.NOT_HANDLED != result;
            }
            if (!handled) {
                setupXref(adminInstance);
            }
            adminInstance = dynamicEntityDao.merge(adminInstance);
            return helper.getRecord(adminProperties, adminInstance, null, null);
        }
    } catch (Exception e) {
        throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Category(org.broadleafcommerce.core.catalog.domain.Category) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 47 with Entity

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

the class CustomerCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Customer adminInstance = (Customer) Class.forName(entity.getType()[0]).newInstance();
        adminInstance.setId(customerService.findNextCustomerId());
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective);
        adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        if (useEmailForLogin) {
            adminInstance.setUsername(adminInstance.getEmailAddress());
        }
        if (!entity.isPreAdd()) {
            Entity errorEntity = validateUniqueUsername(entity, adminInstance);
            if (errorEntity != null) {
                return errorEntity;
            }
        }
        adminInstance = dynamicEntityDao.merge(adminInstance);
        customerService.createRegisteredCustomerRoles(adminInstance);
        Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
        return adminEntity;
    } catch (Exception e) {
        LOG.error("Unable to execute persistence activity", e);
        throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 48 with Entity

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

the class CustomerCustomPersistenceHandler method remove.

@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        Long customerId = Long.parseLong(entity.findProperty("id").getValue());
        Customer customer = customerService.readCustomerById(customerId);
        if (Status.class.isAssignableFrom(customer.getClass())) {
            ((Status) customer).setArchived('Y');
            // If the customer has a conditional weave on ArchiveStatus, nothing triggers the delete so other
            // normally-cascaded deletes don't happen (like CustomerAddress)
            List<CustomerAddress> addressList = customer.getCustomerAddresses();
            for (CustomerAddress address : addressList) {
                address.setArchived('Y');
            }
            customer = customerService.saveCustomer(customer);
            return;
        }
        // Remove the customer roles for the customer since it's not cascaded
        roleDao.removeCustomerRolesByCustomerId(customerId);
        helper.getCompatibleModule(OperationType.BASIC).remove(persistencePackage);
    } catch (Exception e) {
        LOG.error("Unable to execute persistence activity", e);
        throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
    }
}
Also used : Status(org.broadleafcommerce.common.persistence.Status) Entity(org.broadleafcommerce.openadmin.dto.Entity) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServiceException(org.broadleafcommerce.common.exception.ServiceException) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 49 with Entity

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

the class CustomerCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Customer.class.getName(), persistencePerspective);
        Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
        Customer adminInstance = (Customer) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
        String passwordBefore = adminInstance.getPassword();
        adminInstance.setPassword(null);
        adminInstance = (Customer) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        adminInstance.setPassword(passwordBefore);
        if (useEmailForLogin) {
            adminInstance.setUsername(adminInstance.getEmailAddress());
        }
        adminInstance = customerService.saveCustomer(adminInstance);
        Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
        return adminEntity;
    } 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) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 50 with Entity

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

the class IndexFieldCustomPersistenceHandler method getEntity.

protected Entity getEntity(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity, Map<String, FieldMetadata> adminProperties, IndexField adminInstance) throws ServiceException {
    adminInstance = (IndexField) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
    adminInstance = dynamicEntityDao.merge(adminInstance);
    ExtensionResultStatusType result = ExtensionResultStatusType.NOT_HANDLED;
    if (extensionManager != null) {
        result = extensionManager.getProxy().addtoSearchableFields(persistencePackage, adminInstance);
    }
    if (result.equals(ExtensionResultStatusType.NOT_HANDLED)) {
        // If there is no searchable field types then we need to add a default as String
        if (CollectionUtils.isEmpty(adminInstance.getFieldTypes())) {
            IndexFieldType indexFieldType = new IndexFieldTypeImpl();
            indexFieldType.setFieldType(FieldType.TEXT);
            indexFieldType.setIndexField(adminInstance);
            adminInstance.getFieldTypes().add(indexFieldType);
            adminInstance = dynamicEntityDao.merge(adminInstance);
        }
    }
    Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
    return adminEntity;
}
Also used : IndexFieldType(org.broadleafcommerce.core.search.domain.IndexFieldType) Entity(org.broadleafcommerce.openadmin.dto.Entity) IndexFieldTypeImpl(org.broadleafcommerce.core.search.domain.IndexFieldTypeImpl) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

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