예제 #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);
  }
예제 #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);
  }
예제 #3
0
  public void loadStudentTree() {
    if (this.isLoadStudentTreeFlag()) {

      if (this.studentBean.getStudent() != null && this.studentBean.getStudent().getId() != null) {

        Student student = this.studentBean.getStudent();

        // Some sorting login need to implemented.
        this.studentRootNode = new DefaultTreeNode("Root", null);
        this.studentRootNode.setExpanded(Boolean.TRUE);

        // Tree for class name node.
        this.studentNameNode = new DefaultTreeNode(student.getDisplayName(), this.studentRootNode);
        this.studentNameNode.setSelected(true);
        this.studentNameNode.setExpanded(true);

        TreeNode studentAcademicYearsTreeNode =
            new DefaultTreeNode("Academic years", this.studentNameNode);
        studentAcademicYearsTreeNode.setExpanded(true);
        studentAcademicYearsTreeNode.setSelectable(false);

        Collection<StudentAcademicYear> studentAcademicYears =
            this.serviceAcademicYearService.findStudentAcademicYearsByStudentId(student.getId());

        for (StudentAcademicYear studentAcademicYear : studentAcademicYears) {

          StudentAcademicYearTreeNode studentAcademicYearTreeNode =
              new StudentAcademicYearTreeNode(
                  studentAcademicYear.getAcademicYear().getDisplayLabel(),
                  studentAcademicYear.getAcademicYear(),
                  studentAcademicYearsTreeNode);

          studentAcademicYearTreeNode.setSelectable(true);
        }
        this.setLoadStudentTreeFlag(false);
      }
    }
  }