Search in sources :

Example 51 with PersistencePerspective

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

the class AdminUserCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    adminRemoteSecurityService.securityCheck(persistencePackage, EntityOperationType.ADD);
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        AdminUser adminInstance = (AdminUser) Class.forName(entity.getType()[0]).newInstance();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(AdminUser.class.getName(), persistencePerspective);
        adminInstance = (AdminUser) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        Entity errorEntity = validateLegalUsernameAndEmail(entity, adminInstance, true);
        if (errorEntity != null) {
            return errorEntity;
        }
        adminInstance.setUnencodedPassword(adminInstance.getPassword());
        adminInstance.setPassword(null);
        adminInstance = adminSecurityService.saveAdminUser(adminInstance);
        Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
        return adminEntity;
    } catch (Exception 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) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException)

Aggregations

PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)51 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)44 ServiceException (org.broadleafcommerce.common.exception.ServiceException)39 Entity (org.broadleafcommerce.openadmin.dto.Entity)34 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)27 Serializable (java.io.Serializable)16 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)16 CriteriaTransferObject (org.broadleafcommerce.openadmin.dto.CriteriaTransferObject)16 ForeignKey (org.broadleafcommerce.openadmin.dto.ForeignKey)14 Map (java.util.Map)10 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)9 ValidationException (org.broadleafcommerce.openadmin.server.service.ValidationException)9 FilterMapping (org.broadleafcommerce.openadmin.server.service.persistence.module.criteria.FilterMapping)7 HashMap (java.util.HashMap)6 AdornedTargetList (org.broadleafcommerce.openadmin.dto.AdornedTargetList)6 MapStructure (org.broadleafcommerce.openadmin.dto.MapStructure)6 SimpleValueMapStructure (org.broadleafcommerce.openadmin.dto.SimpleValueMapStructure)6 ParentEntityPersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.ParentEntityPersistenceException)6 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)6