Search in sources :

Example 1 with Person

use of fi.otavanopisto.pyramus.domainmodel.base.Person in project pyramus by otavanopisto.

the class CreateCredentialsJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    // Validation of request data and basic necessities
    String applicationId = StringUtils.trim(requestContext.getString("applicationId"));
    String credentialToken = StringUtils.trim(requestContext.getString("token"));
    String username = StringUtils.trim(requestContext.getString("username"));
    String password = StringUtils.trim(requestContext.getString("password"));
    List<InternalAuthenticationProvider> providers = AuthenticationProviderVault.getInstance().getInternalAuthenticationProviders();
    InternalAuthenticationProvider provider = providers.size() == 1 ? providers.get(0) : null;
    if (provider == null || !provider.canUpdateCredentials() || StringUtils.isAnyBlank(applicationId, username, password, credentialToken)) {
        fail(requestContext, "Sisäinen virhe");
        return;
    }
    // Validate application
    ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
    Application application = applicationDAO.findByApplicationId(applicationId);
    if (application == null || application.getStudent() == null || !StringUtils.equals(credentialToken, application.getCredentialToken())) {
        fail(requestContext, "Hakemus ei mahdollista tunnusten luontia");
        return;
    }
    // Validate student
    Person person = application.getStudent().getPerson();
    InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson(provider.getName(), person);
    if (userIdentification != null) {
        fail(requestContext, "Käyttäjätilillä on jo tunnukset");
        return;
    }
    InternalAuth internalAuth = internalAuthDAO.findByUsername(username);
    if (internalAuth != null) {
        fail(requestContext, "Valittu käyttäjätunnus on jo varattu");
        return;
    }
    String externalId = provider.createCredentials(username, password);
    userIdentificationDAO.create(person, provider.getName(), externalId);
    requestContext.addResponseParameter("status", "OK");
}
Also used : InternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider) InternalAuthDAO(fi.otavanopisto.pyramus.dao.users.InternalAuthDAO) InternalAuth(fi.otavanopisto.pyramus.domainmodel.users.InternalAuth) ApplicationDAO(fi.otavanopisto.pyramus.dao.application.ApplicationDAO) Application(fi.otavanopisto.pyramus.domainmodel.application.Application) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) UserIdentification(fi.otavanopisto.pyramus.domainmodel.users.UserIdentification) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO)

Example 2 with Person

use of fi.otavanopisto.pyramus.domainmodel.base.Person in project pyramus by otavanopisto.

the class StudentsService method createStudent.

public StudentEntity createStudent(@WebParam(name = "abstractStudentId") Long abstractStudentId, @WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "nickname") String nickname, @WebParam(name = "phone") String phone, @WebParam(name = "additionalInfo") String additionalInfo, @WebParam(name = "parentalInfo") String parentalInfo, @WebParam(name = "studyTimeEnd") Date studyTimeEnd, @WebParam(name = "activityTypeId") Long activityTypeId, @WebParam(name = "examinationTypeId") Long examinationTypeId, @WebParam(name = "educationalLevelId") Long educationalLevelId, @WebParam(name = "education") String education, @WebParam(name = "nationalityId") Long nationalityId, @WebParam(name = "municipalityId") Long municipalityId, @WebParam(name = "languageId") Long languageId, @WebParam(name = "schoolId") Long schoolId, @WebParam(name = "studyProgrammeId") Long studyProgrammeId, @WebParam(name = "previousStudies") Double previousStudies, @WebParam(name = "studyStartDate") Date studyStartDate, @WebParam(name = "studyEndDate") Date studyEndDate, @WebParam(name = "studyEndReasonId") Long studyEndReasonId, @WebParam(name = "studyEndText") String studyEndText, @WebParam(name = "lodging") Boolean lodging) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentActivityTypeDAO activityTypeDAO = DAOFactory.getInstance().getStudentActivityTypeDAO();
    StudentExaminationTypeDAO examinationTypeDAO = DAOFactory.getInstance().getStudentExaminationTypeDAO();
    StudentEducationalLevelDAO educationalLevelDAO = DAOFactory.getInstance().getStudentEducationalLevelDAO();
    StudentStudyEndReasonDAO studyEndReasonDAO = DAOFactory.getInstance().getStudentStudyEndReasonDAO();
    LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
    MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
    NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
    ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    StudentLodgingPeriodDAO studentLodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
    Person person = personDAO.findById(abstractStudentId);
    Nationality nationality = nationalityId == null ? null : nationalityDAO.findById(nationalityId);
    Municipality municipality = municipalityId == null ? null : municipalityDAO.findById(municipalityId);
    Language language = languageId == null ? null : languageDAO.findById(languageId);
    StudentActivityType activityType = activityTypeId == null ? null : activityTypeDAO.findById(activityTypeId);
    StudentExaminationType examinationType = examinationTypeId == null ? null : examinationTypeDAO.findById(examinationTypeId);
    StudentEducationalLevel educationalLevel = educationalLevelId == null ? null : educationalLevelDAO.findById(educationalLevelId);
    School school = schoolId == null ? null : schoolDAO.findById(schoolId);
    StudyProgramme studyProgramme = studyProgrammeId == null ? null : studyProgrammeDAO.findById(studyProgrammeId);
    StudentStudyEndReason studyEndReason = studyEndReasonId == null ? null : studyEndReasonDAO.findById(studyEndReasonId);
    firstName = StringUtils.trim(firstName);
    lastName = StringUtils.trim(lastName);
    nickname = StringUtils.trim(nickname);
    Student student = studentDAO.create(person, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityType, examinationType, educationalLevel, education, nationality, municipality, language, school, studyProgramme, null, previousStudies, studyStartDate, studyEndDate, studyEndReason, studyEndText, false);
    if (lodging && studyStartDate != null)
        studentLodgingPeriodDAO.create(student, studyStartDate, studyEndDate);
    if (phone != null) {
        ContactType contactType = contactTypeDAO.findById(new Long(1));
        phoneNumberDAO.create(student.getContactInfo(), contactType, Boolean.TRUE, phone);
    }
    contactInfoDAO.update(student.getContactInfo(), parentalInfo);
    // Default user
    personDAO.updateDefaultUser(person, student);
    validateEntity(student);
    return EntityFactoryVault.buildFromDomainObject(student);
}
Also used : PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) StudentStudyEndReasonDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) StudentLodgingPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StudentEducationalLevelDAO(fi.otavanopisto.pyramus.dao.students.StudentEducationalLevelDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) StudentExaminationTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) LanguageDAO(fi.otavanopisto.pyramus.dao.base.LanguageDAO) NationalityDAO(fi.otavanopisto.pyramus.dao.base.NationalityDAO) StudentActivityTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentActivityTypeDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactInfoDAO(fi.otavanopisto.pyramus.dao.base.ContactInfoDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 3 with Person

use of fi.otavanopisto.pyramus.domainmodel.base.Person in project pyramus by otavanopisto.

the class StudentsService method listStudentsByAbstractStudent.

public StudentEntity[] listStudentsByAbstractStudent(@WebParam(name = "abstractStudentId") Long abstractStudentId) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    Person person = personDAO.findById(abstractStudentId);
    return (StudentEntity[]) EntityFactoryVault.buildFromDomainObjects(studentDAO.listByPerson(person));
}
Also used : StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 4 with Person

use of fi.otavanopisto.pyramus.domainmodel.base.Person in project pyramus by otavanopisto.

the class UsersService method createUser.

public UserEntity createUser(@WebParam(name = "firstName") String firstName, @WebParam(name = "lastName") String lastName, @WebParam(name = "externalId") String externalId, @WebParam(name = "authProvider") String authProvider, @WebParam(name = "role") String role) {
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    // TODO: should not create if user exists
    Person person = personDAO.create(null, null, null, null, Boolean.FALSE);
    userIdentificationDAO.create(person, authProvider, externalId);
    Role userRole = EnumType.valueOf(Role.class, role);
    // TODO organization
    Organization organization = null;
    StaffMember staffMember = staffMemberDAO.create(organization, firstName, lastName, userRole, person, false);
    personDAO.updateDefaultUser(person, staffMember);
    validateEntity(staffMember);
    return EntityFactoryVault.buildFromDomainObject(staffMember);
}
Also used : Role(fi.otavanopisto.pyramus.domainmodel.users.Role) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO)

Example 5 with Person

use of fi.otavanopisto.pyramus.domainmodel.base.Person in project pyramus by otavanopisto.

the class YTLReportBinaryRequestController method enrollmentToKokelas.

private AbstractKokelas enrollmentToKokelas(MatriculationExamEnrollment enrollment, List<YTLAineKoodi> mapping) {
    MatriculationExamAttendanceDAO matriculationExamAttendanceDAO = DAOFactory.getInstance().getMatriculationExamAttendanceDAO();
    PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
    Student student = enrollment.getStudent();
    if (student == null || student.getPerson() == null) {
        return null;
    }
    List<MatriculationExamAttendance> attendances = matriculationExamAttendanceDAO.listByEnrollmentAndStatus(enrollment, MatriculationExamAttendanceStatus.ENROLLED);
    Person person = student.getPerson();
    String hetu = enrollment.getSsn();
    if (hetu == null) {
        hetu = person.getSocialSecurityNumber();
        if (hetu == null && person.getBirthday() != null) {
            DateFormat format = new SimpleDateFormat("dd.MM.yyyy");
            hetu = format.format(person.getBirthday());
        }
    }
    List<String> etunimet = Arrays.asList(StringUtils.split(student.getFirstName(), " "));
    String oppijanumero = personVariableDAO.findByPersonAndKey(person, KOSKI_HENKILO_OID);
    oppijanumero = StringUtils.isNotBlank(oppijanumero) ? oppijanumero : null;
    int kokelasnumero = enrollment.getCandidateNumber();
    Koulutustyyppi koulutustyyppi = schoolTypeToKoulutustyyppi(enrollment.getEnrollAs());
    Tutkintotyyppi tutkintotyyppi = degreeTypeToTutkintoTyyppi(enrollment.getDegreeType());
    boolean uudelleenaloittaja = enrollment.isRestartExam();
    AbstractKokelas kokelas;
    switch(enrollment.getDegreeStructure()) {
        case PRE2022:
            kokelas = vanhaKokelas(student, attendances, mapping);
            break;
        case POST2022:
            kokelas = uusiKokelas(student, attendances, mapping);
            break;
        default:
            throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "Invalid degree structure.");
    }
    kokelas.getEtunimet().addAll(etunimet);
    kokelas.setSukunimi(student.getLastName());
    kokelas.setHetu(hetu);
    kokelas.setKokelasnumero(kokelasnumero);
    kokelas.setOppijanumero(oppijanumero);
    kokelas.setKoulutustyyppi(koulutustyyppi);
    kokelas.setTutkintotyyppi(tutkintotyyppi);
    kokelas.setUudelleenaloittaja(uudelleenaloittaja);
    return kokelas;
}
Also used : SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) AbstractKokelas(fi.otavanopisto.pyramus.ytl.AbstractKokelas) MatriculationExamAttendance(fi.otavanopisto.pyramus.domainmodel.matriculation.MatriculationExamAttendance) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) MatriculationExamAttendanceDAO(fi.otavanopisto.pyramus.dao.matriculation.MatriculationExamAttendanceDAO) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Tutkintotyyppi(fi.otavanopisto.pyramus.ytl.Tutkintotyyppi) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) SimpleDateFormat(java.text.SimpleDateFormat) Koulutustyyppi(fi.otavanopisto.pyramus.ytl.Koulutustyyppi)

Aggregations

Person (fi.otavanopisto.pyramus.domainmodel.base.Person)68 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)42 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)30 User (fi.otavanopisto.pyramus.domainmodel.users.User)22 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)21 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)15 StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)14 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)14 Date (java.util.Date)13 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)12 Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)12 Nationality (fi.otavanopisto.pyramus.domainmodel.base.Nationality)12 Path (javax.ws.rs.Path)12 School (fi.otavanopisto.pyramus.domainmodel.base.School)11 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)11 EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)10 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)10 PersonVariableDAO (fi.otavanopisto.pyramus.dao.users.PersonVariableDAO)10 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)10 UserDAO (fi.otavanopisto.pyramus.dao.users.UserDAO)9