Search in sources :

Example 6 with UserRole

use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.

the class UserMaintenanceTx method postCreate.

// .//GEN-END:_createDomain_3_be
// .//GEN-BEGIN:_postCreate_1_be
/**
 * This method is invoked after the domain object has been created.
 */
private User postCreate(UOW uow, UserMaintenanceCreateInDto input, User domain, boolean fromPrevalidate) throws FrameworkException, ApplicationExceptions {
    // .//GEN-END:_postCreate_1_be
    // Add custom code //GEN-FIRST:_postCreate_1
    ApplicationExceptions appExps = null;
    String[] userRole = null;
    // Build an array of roles
    userRole = new String[input.getUserRoleCount()];
    UserRoleDto[] userRoleDtos = input.getUserRole();
    for (int i = 0; i < userRoleDtos.length; i++) userRole[i] = userRoleDtos[i].getRoleName();
    Arrays.sort(userRole);
    performUserRoleValidations(userRole, domain);
    if (!fromPrevalidate) {
        // add the the roles
        for (int i = 0; i < userRole.length; i++) {
            try {
                UserRole ur = new UserRole();
                ur.updateRoleName(userRole[i]);
                ur.updateUserName(input.getUserName());
                uow.add(ur);
            } catch (ValidationException e) {
                if (appExps == null)
                    appExps = new ApplicationExceptions();
                appExps.add(e);
            }
        }
    }
    if (input.getNotifyUser().booleanValue()) {
        try {
            EmailerBean email = new EmailerBean();
            String[] to = new String[] { domain.getEMailAddress() };
            String body = "Your UserName is " + domain.getUserName() + " and your password is " + domain.getPassword() + ". Your account is currently " + domain.getStatus() + ".";
            email.sendMail(to, "Account Information", body);
        } catch (javax.mail.MessagingException e) {
            e.printStackTrace();
        }
    }
    if (input.getRequestId() != null && input.getRequestId().length() > 0) {
        try {
            UserRequest userRequest = UserRequest.findByPK(uow, new Long(input.getRequestId()));
            userRequest.setStatus("S");
            uow.update(userRequest);
        } catch (ValidationException e) {
            if (appExps == null)
                appExps = new ApplicationExceptions();
            appExps.add(e);
        }
    }
    if (appExps != null && appExps.size() > 0)
        throw appExps;
    // .//GEN-BEGIN:_postCreate_2_be
    return domain;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ValidationException(org.jaffa.datatypes.ValidationException) EmailerBean(org.jaffa.util.EmailerBean) UserRole(org.jaffa.applications.jaffa.modules.admin.domain.UserRole) UserRequest(org.jaffa.applications.jaffa.modules.user.domain.UserRequest)

Example 7 with UserRole

use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.

the class UserMaintenanceTx method deleteRelatedObjects.

// .//GEN-END:_addRelatedDtosToRetrieveOut_2_be
// .//GEN-BEGIN:_deleteRelatedObjects_1_be
/**
 * Delete the related domain objects if the 'Cascading' constraint is specified. Throw an exception in case 'Restricted' constraint is specified.
 */
private void deleteRelatedObjects(UOW uow, UserMaintenanceDeleteInDto input, User user) throws FrameworkException, ApplicationExceptions {
    ApplicationExceptions appExps = null;
    // .//GEN-BEGIN:_deleteRelatedObjects_UserRole_1_be
    if (user.getUserName() != null) {
        Criteria criteria = new Criteria();
        criteria.setTable(UserRoleMeta.getName());
        criteria.addCriteria(UserRoleMeta.USER_NAME, user.getUserName());
        criteria.setLocking(Criteria.LOCKING_PARANOID);
        // .//GEN-END:_deleteRelatedObjects_UserRole_1_be
        // Add custom code to set the criteria before the query //GEN-FIRST:_deleteRelatedObjects_UserRole_1
        // .//GEN-LAST:_deleteRelatedObjects_UserRole_1
        // .//GEN-BEGIN:_deleteRelatedObjects_UserRole_4_be
        Iterator itr = uow.query(criteria).iterator();
        while (itr.hasNext()) {
            UserRole userRole = (UserRole) itr.next();
            if (log.isDebugEnabled())
                log.debug("Deleting the related object " + userRole);
            uow.delete(userRole);
        }
    // .//GEN-END:_deleteRelatedObjects_UserRole_4_be
    // .//GEN-BEGIN:_deleteRelatedObjects_UserRole_6_be
    }
    // .//GEN-BEGIN:_deleteRelatedObjects_2_be
    if (appExps != null)
        throw appExps;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) UserRole(org.jaffa.applications.jaffa.modules.admin.domain.UserRole) Criteria(org.jaffa.persistence.Criteria)

Example 8 with UserRole

use of org.jaffa.applications.jaffa.modules.admin.domain.UserRole in project jaffa-framework by jaffa-projects.

the class User method newUserRoleObject.

/**
 * Creates a new UserRole object and initializes the related fields.
 * This will uncache the related UserRole objects.
 * @throws ValidationException if an invalid value is passed.
 * @throws FrameworkException Indicates some system error
 * @return the related UserRole object with the initialized related fields.
 */
public UserRole newUserRoleObject() throws ValidationException, FrameworkException {
    m_userRoleCollection = null;
    UserRole userRole = new UserRole();
    userRole.setUserName(getUserName());
    // .//GEN-BEGIN:userRoleArray_3_be
    return userRole;
}
Also used : UserRole(org.jaffa.applications.jaffa.modules.admin.domain.UserRole)

Aggregations

UserRole (org.jaffa.applications.jaffa.modules.admin.domain.UserRole)8 Criteria (org.jaffa.persistence.Criteria)5 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)4 ValidationException (org.jaffa.datatypes.ValidationException)2 EmailerBean (org.jaffa.util.EmailerBean)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 UserMaintenanceException (org.jaffa.applications.jaffa.modules.admin.components.usermaintenance.tx.exceptions.UserMaintenanceException)1 UserRoleDto (org.jaffa.applications.jaffa.modules.admin.components.userviewer.dto.UserRoleDto)1 UserRequest (org.jaffa.applications.jaffa.modules.user.domain.UserRequest)1 DateTime (org.jaffa.datatypes.DateTime)1 UOW (org.jaffa.persistence.UOW)1 UOWException (org.jaffa.persistence.exceptions.UOWException)1 Exclude (org.jaffa.security.securityrolesdomain.Exclude)1 Include (org.jaffa.security.securityrolesdomain.Include)1 Role (org.jaffa.security.securityrolesdomain.Role)1 Roles (org.jaffa.security.securityrolesdomain.Roles)1