Esempio n. 1
0
  public UserVO createUser(UserVO vo) throws MSMApplicationException {
    UserVO newUser = null;
    NdgUser userPending = findNdgUserByName(vo.getUsername());
    UserVO userByEmail = getUserByEmail(vo.getEmail());

    if (userPending != null) {
      throw new UserAlreadyExistException();
    } else if (userByEmail != null) {
      throw new EmailAlreadyExistException();
    } else {
      userPending = new NdgUser();
      try {
        userPending.setPassword(MD5.createMD5(vo.getPassword()));
      } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
      }
      userPending.setUsername(vo.getUsername());
      userPending.setFirstName(vo.getFirstName());
      userPending.setLastName(vo.getLastName());
      userPending.setEmail(vo.getEmail());

      userPending.setPhoneNumber(vo.getPhoneNumber());
      userPending.setAreaCode(vo.getAreaCode());
      userPending.setCountryCode(vo.getCountryCode());

      NdgRole role = findNdgRoleByName(vo.getRole().getName());
      if (role != null) {
        userPending.setRole(role);
      }
      NdgUser userAdmin = findNdgUserByName(vo.getUserAdmin());
      if (userPending != null) {
        userPending.setUserAdmin(userAdmin.getUsername());
        userPending.setCompany(userAdmin.getCompany());
        userPending.setEmailPreferences(userAdmin.getEmailPreferences());
        userPending.setWhoUseIt(userAdmin.getWhoUseIt());
      }

      userPending.setValidationKey(generateValidationKey(vo.getEmail()));
      userPending.setHasFullPermissions(vo.getHasFullPermissions());
      userPending.setUserValidated('Y');
      userPending.setHowDoYouPlanUseNdg("");
      userPending.setFirstTimeUse('Y');

      manager.persist(userPending);

      newUser = userPojoToVo(userPending);
    }

    return newUser;
  }
Esempio n. 2
0
  public void updateUser(UserVO userToUpdate) throws MSMApplicationException {
    NdgUser user = findNdgUserByName(userToUpdate.getUsername());

    if (user != null) {
      if (userToUpdate.getFirstName() != null) {
        user.setFirstName(userToUpdate.getFirstName());
      }
      if (userToUpdate.getLastName() != null) {
        user.setLastName(userToUpdate.getLastName());
      }
      if (userToUpdate.getEmail() != null) {
        user.setEmail(userToUpdate.getEmail());
      }
      if (userToUpdate.getCountryCode() != null) {
        user.setCountryCode(userToUpdate.getCountryCode());
      }
      if (userToUpdate.getAreaCode() != null) {
        user.setAreaCode(userToUpdate.getAreaCode());
      }
      if (userToUpdate.getPhoneNumber() != null) {
        user.setPhoneNumber(userToUpdate.getPhoneNumber());
      }
      if (userToUpdate.getRole() != null) {
        NdgRole role = findNdgRoleByName(userToUpdate.getRole().getName());
        if (role != null) {
          user.setRole(role);
        }
      }
      if (userToUpdate.getPassword() != null) {
        try {
          user.setPassword(MD5.createMD5(userToUpdate.getPassword()));
        } catch (NoSuchAlgorithmException e) {
          e.printStackTrace();
        }
      }

      user.setFirstTimeUse(userToUpdate.getFirstTimeUse());

      // if (userToUpdate.getHasFullPermissions() == 'y' ||
      //		userToUpdate.getHasFullPermissions() == 'Y') {
      //	user.setHasFullPermissions(userToUpdate.getHasFullPermissions());
      // }
      // user.setFirstTimeUse(userToUpdate.getFirstTimeUse());

      manager.merge(user);
    } else {
      throw new UserNotFoundException();
    }
  }
Esempio n. 3
0
  @Override
  public UserVO requestAccess(UserVO vo) throws MSMApplicationException, MSMSystemException {
    idSimpleSurvey = MD5.createIdSurvey();

    userDirectories =
        properties.getProperty(PropertiesUtil.SURVEY_ROOT)
            + SystemUtils.FILE_SEP
            + vo.getUsername()
            + SystemUtils.FILE_SEP
            + "survey"
            + idSimpleSurvey;

    UserVO newUser = null;

    NdgUser userPending = findNdgUserByName(vo.getUsername());
    if (userPending != null) {
      throw new UserAlreadyExistException();
    }
    UserVO userByEmail = getUserByEmail(vo.getEmail());
    if (userByEmail != null) {
      throw new EmailAlreadyExistException();
    }

    userPending = new NdgUser();
    userPending.setUsername(vo.getUsername());
    try {
      userPending.setPassword(MD5.createMD5(vo.getPassword()));
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
      userPending.setPassword(vo.getPassword());
    }

    userPending.setFirstName(vo.getFirstName());
    userPending.setLastName(vo.getLastName());
    userPending.setEmail(vo.getEmail());
    userPending.setWhoUseIt(vo.getWhoUseIt());
    userPending.setPhoneNumber(vo.getPhoneNumber());

    NdgRole role = findNdgRoleByName(vo.getRole().getName());
    if (role != null) {
      userPending.setRole(role);
    }

    Company company = findCompanyByName(vo.getCompany().getCompanyName());
    if (company != null) {
      userPending.setCompany(company);
    } else {
      Company newCompany = new Company();
      newCompany.setCompanyName(vo.getCompany().getCompanyName());
      newCompany.setCompanyType(vo.getCompany().getCompanyType());
      newCompany.setCompanyCountry(vo.getCompany().getCompanyCountry());
      newCompany.setCompanyIndustry(vo.getCompany().getCompanyIndustry());
      newCompany.setCompanySize(vo.getCompany().getCompanySize());
      userPending.setCompany(newCompany);
    }

    userPending.setAreaCode(vo.getAreaCode());
    userPending.setCountryCode(vo.getCountryCode());
    userPending.setEmailPreferences(vo.getEmailPreferences());
    userPending.setHowDoYouPlanUseNdg(vo.getHowDoYouPlanUseNdg());
    userPending.setValidationKey(generateValidationKey(vo.getEmail()));
    userPending.setUserValidated(vo.getUserValidated());
    userPending.setUserAdmin(userPending.getUsername());
    userPending.setFirstTimeUse(vo.getFirstTimeUse());
    userPending.setHasFullPermissions(vo.getHasFullPermissions());

    manager.persist(userPending);
    createUserFile(vo.getUsername());
    newUser = userPojoToVo(userPending);

    return newUser;
  }