Exemplo n.º 1
0
  @Override
  public void creteUserAccountForParent(
      final String username,
      final String password,
      final String firstName,
      final String lastName,
      final Date dateOfBirth,
      final String admissionNumber) {

    Student student = this.studentDao.findActiveStudentByAdmissionNumber(admissionNumber);

    if (student == null) {
      throw new BusinessException(
          "Student not found with admission number or not active. " + admissionNumber + ".");
    }

    Collection<Relation> relations = this.relationDao.findRelationsByStudentId(student.getId());

    if (relations == null || relations.isEmpty()) {
      throw new BusinessException(
          "No relations found for student with admission number " + admissionNumber + ".");
    }

    Relation relationMatch = null;

    for (Relation relation : relations) {

      if (firstName.equals(relation.getFirstName())
          && lastName.equals(relation.getLastName())
          && dateOfBirth.equals(relation.getDateOfBirth())) {
        relationMatch = relation;
        break;
      }
    }

    if (relationMatch == null) {
      throw new BusinessException("Relation details does not match our records.");
    }

    UserAccount userAccount = new UserAccount();

    userAccount.setUsername(username);
    userAccount.setPassword(password);

    userAccount.setUserAccountType(UserAccountTypeConstant.PARENT);
    userAccount.setActive(true);

    userAccount = this.createNewUserAccount(userAccount);

    UserRole role = new UserRole();
    role.setUserRole(AuthorityConstant.ROLE_PARENT);
    role.setUserAccount(userAccount);
    this.userRoleDao.persist(role);

    relationMatch.setUserAccount(userAccount);

    this.relationDao.persist(relationMatch);
  }
Exemplo n.º 2
0
  @Override
  public void creteUserAccountForStudent(
      final String username,
      final String password,
      final String firstName,
      final String lastName,
      final Date dateOfBirth,
      final String admissionNumber) {

    Student student = this.studentDao.findActiveStudentByAdmissionNumber(admissionNumber);

    if (student == null) {
      throw new BusinessException(
          "Student not found with admission number '" + admissionNumber + "' or not active.");
    }

    if (!firstName.equals(student.getFirstName())
        || !lastName.equals(student.getLastName())
        || !dateOfBirth.equals(student.getDateOfBirth())) {
      throw new BusinessException("Student details does not match our records.");
    }

    UserAccount userAccount = new UserAccount();

    userAccount.setUsername(username);
    userAccount.setPassword(password);
    userAccount.setUserAccountType(UserAccountTypeConstant.STUDENT);
    userAccount.setActive(true);

    userAccount = this.createNewUserAccount(userAccount);

    UserRole role = new UserRole();
    role.setUserRole(AuthorityConstant.ROLE_STUDENT);
    role.setUserAccount(userAccount);

    this.userRoleDao.persist(role);

    student.setUserAccount(userAccount);

    this.studentService.saveStudent(student);
  }
Exemplo n.º 3
0
  @Override
  public void creteUserAccountForEmployee(
      final String username,
      final String password,
      final String firstName,
      final String lastName,
      final Date dateOfBirth,
      final String employeeNumber) {

    Employee employee = this.employeeDao.findAllEmployeesByEmployeeNumber(employeeNumber);

    if (employee == null) {
      throw new BusinessException(
          "Employee not found with empoyee number : " + employeeNumber + ".");
    }

    if (!firstName.equals(employee.getFirstName())
        || !lastName.equals(employee.getLastName())
        || !dateOfBirth.equals(employee.getDateOfBirth())) {
      throw new BusinessException("Employee details does not match our records.");
    }

    UserAccount userAccount = new UserAccount();

    userAccount.setUsername(username);
    userAccount.setPassword(password);
    userAccount.setUserAccountType(UserAccountTypeConstant.EMPLOYEE);
    userAccount.setActive(true);

    userAccount = this.createNewUserAccount(userAccount);

    UserRole role = new UserRole();
    role.setUserRole(AuthorityConstant.ROLE_EMPLOYEE);
    role.setUserAccount(userAccount);
    this.userRoleDao.persist(role);

    employee.setUserAccount(userAccount);

    this.employeeService.saveEmployee(employee);
  }