Search in sources :

Example 11 with Municipality

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

the class EditStudentJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    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();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    LanguageDAO languageDAO = DAOFactory.getInstance().getLanguageDAO();
    MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
    NationalityDAO nationalityDAO = DAOFactory.getInstance().getNationalityDAO();
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    TagDAO tagDAO = DAOFactory.getInstance().getTagDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    UserIdentificationDAO userIdentificationDAO = DAOFactory.getInstance().getUserIdentificationDAO();
    UserDAO userDAO = DAOFactory.getInstance().getUserDAO();
    CurriculumDAO curriculumDAO = DAOFactory.getInstance().getCurriculumDAO();
    StudentLodgingPeriodDAO lodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
    PersonVariableDAO personVariableDAO = DAOFactory.getInstance().getPersonVariableDAO();
    StudentStudyPeriodDAO studentStudyPeriodDAO = DAOFactory.getInstance().getStudentStudyPeriodDAO();
    StaffMemberDAO staffMemberDAO = DAOFactory.getInstance().getStaffMemberDAO();
    User loggedUser = userDAO.findById(requestContext.getLoggedUserId());
    Long personId = NumberUtils.createLong(requestContext.getRequest().getParameter("personId"));
    Person person = personDAO.findById(personId);
    Date birthday = requestContext.getDate("birthday");
    String ssecId = requestContext.getString("ssecId");
    Sex sex = (Sex) requestContext.getEnum("gender", Sex.class);
    String basicInfo = requestContext.getString("basicInfo");
    Long version = requestContext.getLong("version");
    Boolean secureInfo = requestContext.getBoolean("secureInfo");
    String username = requestContext.getString("username");
    String password = requestContext.getString("password1");
    String password2 = requestContext.getString("password2");
    if (UserUtils.allowEditCredentials(loggedUser, person)) {
        if (!person.getVersion().equals(version)) {
            throw new StaleObjectStateException(Person.class.getName(), person.getId());
        }
        boolean usernameBlank = StringUtils.isBlank(username);
        boolean passwordBlank = StringUtils.isBlank(password);
        UserIdentification userIdentification = userIdentificationDAO.findByAuthSourceAndPerson("internal", person);
        if (usernameBlank && passwordBlank) {
            // #1108: Existing credential deletion
            if (userIdentification != null && NumberUtils.isNumber(userIdentification.getExternalId())) {
                InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
                InternalAuth internalAuth = internalAuthDAO.findById(new Long(userIdentification.getExternalId()));
                if (internalAuth != null) {
                    internalAuthDAO.delete(internalAuth);
                }
                userIdentificationDAO.delete(userIdentification);
            }
        } else if (!usernameBlank || !passwordBlank) {
            if (!passwordBlank && !password.equals(password2)) {
                throw new SmvcRuntimeException(PyramusStatusCode.PASSWORD_MISMATCH, "Passwords don't match");
            }
            // #921: Check username
            InternalAuthDAO internalAuthDAO = DAOFactory.getInstance().getInternalAuthDAO();
            InternalAuth internalAuth = internalAuthDAO.findByUsername(username);
            if (internalAuth != null) {
                userIdentification = userIdentificationDAO.findByAuthSourceAndExternalId("internal", internalAuth.getId().toString());
                if (userIdentification != null && !person.getId().equals(userIdentification.getPerson().getId())) {
                    throw new RuntimeException(Messages.getInstance().getText(requestContext.getRequest().getLocale(), "generic.errors.usernameInUse"));
                }
            } else if (!usernameBlank && passwordBlank) {
                throw new RuntimeException(Messages.getInstance().getText(requestContext.getRequest().getLocale(), "generic.errors.nopassword"));
            }
            // TODO: Support for multiple internal authentication providers
            List<InternalAuthenticationProvider> internalAuthenticationProviders = AuthenticationProviderVault.getInstance().getInternalAuthenticationProviders();
            if (internalAuthenticationProviders.size() == 1) {
                InternalAuthenticationProvider internalAuthenticationProvider = internalAuthenticationProviders.get(0);
                if (internalAuthenticationProvider != null) {
                    userIdentification = userIdentificationDAO.findByAuthSourceAndPerson(internalAuthenticationProvider.getName(), person);
                    if (internalAuthenticationProvider.canUpdateCredentials()) {
                        if (userIdentification == null) {
                            String externalId = internalAuthenticationProvider.createCredentials(username, password);
                            userIdentificationDAO.create(person, internalAuthenticationProvider.getName(), externalId);
                        } else {
                            if ("-1".equals(userIdentification.getExternalId())) {
                                String externalId = internalAuthenticationProvider.createCredentials(username, password);
                                userIdentificationDAO.updateExternalId(userIdentification, externalId);
                            } else {
                                if (!StringUtils.isBlank(username))
                                    internalAuthenticationProvider.updateUsername(userIdentification.getExternalId(), username);
                                if (!StringUtils.isBlank(password))
                                    internalAuthenticationProvider.updatePassword(userIdentification.getExternalId(), password);
                            }
                        }
                    }
                }
            }
        }
    }
    // Abstract student
    personDAO.update(person, birthday, ssecId, sex, basicInfo, secureInfo);
    // Person Variables
    Integer personVariableCount = requestContext.getInteger("personVariablesTable.rowCount");
    if (personVariableCount != null) {
        for (int i = 0; i < personVariableCount; i++) {
            String colPrefix = "personVariablesTable." + i;
            Long edited = requestContext.getLong(colPrefix + ".edited");
            if (Objects.equals(new Long(1), edited)) {
                String variableKey = requestContext.getString(colPrefix + ".key");
                String variableValue = requestContext.getString(colPrefix + ".value");
                personVariableDAO.setPersonVariable(person, variableKey, variableValue);
            }
        }
    }
    List<Student> students = UserUtils.canAccessAllOrganizations(loggedUser) ? studentDAO.listByPerson(person) : studentDAO.listByPersonAndOrganization(person, loggedUser.getOrganization());
    for (Student student : students) {
        int rowCount = requestContext.getInteger("emailTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "emailTable." + student.getId() + "." + i;
            String email = StringUtils.trim(requestContext.getString(colPrefix + ".email"));
            if (StringUtils.isNotBlank(email)) {
                ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
                if (!UserUtils.isAllowedEmail(email, contactType, person.getId()))
                    throw new RuntimeException(Messages.getInstance().getText(requestContext.getRequest().getLocale(), "generic.errors.emailInUse"));
            }
        }
    }
    for (Student student : students) {
        Long studentVersion = requestContext.getLong("studentVersion." + student.getId());
        if (!student.getVersion().equals(studentVersion))
            throw new StaleObjectStateException(Student.class.getName(), student.getId());
        String firstName = StringUtils.trim(requestContext.getString("firstName." + student.getId()));
        String lastName = StringUtils.trim(requestContext.getString("lastName." + student.getId()));
        String nickname = StringUtils.trim(requestContext.getString("nickname." + student.getId()));
        String additionalInfo = requestContext.getString("additionalInfo." + student.getId());
        String additionalContactInfo = requestContext.getString("otherContactInfo." + student.getId());
        String education = requestContext.getString("education." + student.getId());
        Double previousStudies = requestContext.getDouble("previousStudies." + student.getId());
        Date studyTimeEnd = requestContext.getDate("studyTimeEnd." + student.getId());
        Date studyStartDate = requestContext.getDate("studyStartDate." + student.getId());
        Date studyEndDate = requestContext.getDate("studyEndDate." + student.getId());
        String studyEndText = requestContext.getString("studyEndText." + student.getId());
        String tagsText = requestContext.getString("tags." + student.getId());
        StudentFunding funding = (StudentFunding) requestContext.getEnum("funding." + student.getId(), StudentFunding.class);
        Set<Tag> tagEntities = new HashSet<>();
        if (!StringUtils.isBlank(tagsText)) {
            List<String> tags = Arrays.asList(tagsText.split("[\\ ,]"));
            for (String tag : tags) {
                if (!StringUtils.isBlank(tag)) {
                    Tag tagEntity = tagDAO.findByText(tag.trim());
                    if (tagEntity == null)
                        tagEntity = tagDAO.create(tag);
                    tagEntities.add(tagEntity);
                }
            }
        }
        Long entityId = requestContext.getLong("language." + student.getId());
        Language language = entityId == null ? null : languageDAO.findById(entityId);
        entityId = requestContext.getLong("activityType." + student.getId());
        StudentActivityType activityType = entityId == null ? null : activityTypeDAO.findById(entityId);
        entityId = requestContext.getLong("examinationType." + student.getId());
        StudentExaminationType examinationType = entityId == null ? null : examinationTypeDAO.findById(entityId);
        entityId = requestContext.getLong("educationalLevel." + student.getId());
        StudentEducationalLevel educationalLevel = entityId == null ? null : educationalLevelDAO.findById(entityId);
        entityId = requestContext.getLong("nationality." + student.getId());
        Nationality nationality = entityId == null ? null : nationalityDAO.findById(entityId);
        entityId = requestContext.getLong("municipality." + student.getId());
        Municipality municipality = entityId == null ? null : municipalityDAO.findById(entityId);
        entityId = requestContext.getLong("school." + student.getId());
        School school = entityId != null && entityId > 0 ? schoolDAO.findById(entityId) : null;
        entityId = requestContext.getLong("studyEndReason." + student.getId());
        StudentStudyEndReason studyEndReason = entityId == null ? null : studyEndReasonDAO.findById(entityId);
        entityId = requestContext.getLong("curriculum." + student.getId());
        Curriculum curriculum = entityId == null ? null : curriculumDAO.findById(entityId);
        entityId = requestContext.getLong("studyApprover." + student.getId());
        StaffMember approver = entityId == null ? null : staffMemberDAO.findById(entityId);
        Integer variableCount = requestContext.getInteger("variablesTable." + student.getId() + ".rowCount");
        if (variableCount != null) {
            for (int i = 0; i < variableCount; i++) {
                String colPrefix = "variablesTable." + student.getId() + "." + i;
                Long edited = requestContext.getLong(colPrefix + ".edited");
                if (Objects.equals(new Long(1), edited)) {
                    String variableKey = requestContext.getString(colPrefix + ".key");
                    String variableValue = requestContext.getString(colPrefix + ".value");
                    userVariableDAO.setUserVariable(student, variableKey, variableValue);
                }
            }
        }
        Integer lodgingPeriodsCount = requestContext.getInteger("lodgingPeriodsTable." + student.getId() + ".rowCount");
        if (lodgingPeriodsCount != null) {
            Set<Long> remainingIds = new HashSet<>();
            for (int i = 0; i < lodgingPeriodsCount; i++) {
                String colPrefix = "lodgingPeriodsTable." + student.getId() + "." + i;
                Long id = requestContext.getLong(colPrefix + ".id");
                Date begin = requestContext.getDate(colPrefix + ".begin");
                Date end = requestContext.getDate(colPrefix + ".end");
                if (id == -1 && begin != null) {
                    StudentLodgingPeriod lodgingPeriod = lodgingPeriodDAO.create(student, begin, end);
                    remainingIds.add(lodgingPeriod.getId());
                } else if (id > 0) {
                    StudentLodgingPeriod lodgingPeriod = lodgingPeriodDAO.findById(id);
                    remainingIds.add(id);
                    if (begin != null) {
                        if (lodgingPeriod != null) {
                            lodgingPeriodDAO.update(lodgingPeriod, begin, end);
                        }
                    }
                }
            }
            List<StudentLodgingPeriod> periods = lodgingPeriodDAO.listByStudent(student);
            periods.removeIf(period -> remainingIds.contains(period.getId()));
            periods.forEach(period -> lodgingPeriodDAO.delete(period));
        }
        Integer studyPeriodsCount = requestContext.getInteger("studentStudyPeriodsTable." + student.getId() + ".rowCount");
        if (studyPeriodsCount != null) {
            Set<Long> remainingIds = new HashSet<>();
            for (int i = 0; i < studyPeriodsCount; i++) {
                String colPrefix = "studentStudyPeriodsTable." + student.getId() + "." + i;
                Long id = requestContext.getLong(colPrefix + ".id");
                StudentStudyPeriodType periodType = (StudentStudyPeriodType) requestContext.getEnum(colPrefix + ".type", StudentStudyPeriodType.class);
                Date begin = requestContext.getDate(colPrefix + ".begin");
                // Null out the end date when period type allows only begin dates
                Date end = !StudentStudyPeriodType.BEGINDATE_ONLY.contains(periodType) ? requestContext.getDate(colPrefix + ".end") : null;
                if (id == -1 && begin != null) {
                    StudentStudyPeriod studyPeriod = studentStudyPeriodDAO.create(student, begin, end, periodType);
                    remainingIds.add(studyPeriod.getId());
                } else if (id > 0) {
                    StudentStudyPeriod studyPeriod = studentStudyPeriodDAO.findById(id);
                    remainingIds.add(id);
                    if (begin != null) {
                        if (studyPeriod != null) {
                            studentStudyPeriodDAO.update(studyPeriod, begin, end, periodType);
                        }
                    }
                }
            }
            List<StudentStudyPeriod> periods = studentStudyPeriodDAO.listByStudent(student);
            periods.removeIf(period -> remainingIds.contains(period.getId()));
            periods.forEach(period -> studentStudyPeriodDAO.delete(period));
        }
        boolean studiesEnded = student.getStudyEndDate() == null && studyEndDate != null;
        // Student
        studentDAO.update(student, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityType, examinationType, educationalLevel, education, nationality, municipality, language, school, curriculum, previousStudies, studyStartDate, studyEndDate, studyEndReason, studyEndText);
        studentDAO.updateApprover(student, approver);
        studentDAO.updateFunding(student, funding);
        // Tags
        studentDAO.setStudentTags(student, tagEntities);
        // Contact info
        contactInfoDAO.update(student.getContactInfo(), additionalContactInfo);
        // Student addresses
        Set<Long> existingAddresses = new HashSet<>();
        int rowCount = requestContext.getInteger("addressTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "addressTable." + student.getId() + "." + i;
            Long addressId = requestContext.getLong(colPrefix + ".addressId");
            Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
            ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
            String name = requestContext.getString(colPrefix + ".name");
            String street = requestContext.getString(colPrefix + ".street");
            String postal = requestContext.getString(colPrefix + ".postal");
            String city = requestContext.getString(colPrefix + ".city");
            String country = requestContext.getString(colPrefix + ".country");
            boolean hasAddress = name != null || street != null || postal != null || city != null || country != null;
            if (addressId == -1 && hasAddress) {
                Address address = addressDAO.create(student.getContactInfo(), contactType, name, street, postal, city, country, defaultAddress);
                existingAddresses.add(address.getId());
            } else if (addressId > 0) {
                Address address = addressDAO.findById(addressId);
                if (hasAddress) {
                    existingAddresses.add(addressId);
                    addressDAO.update(address, defaultAddress, contactType, name, street, postal, city, country);
                }
            }
        }
        List<Address> addresses = student.getContactInfo().getAddresses();
        for (int i = addresses.size() - 1; i >= 0; i--) {
            Address address = addresses.get(i);
            if (!existingAddresses.contains(address.getId())) {
                addressDAO.delete(address);
            }
        }
        // Email addresses
        Set<Long> existingEmails = new HashSet<>();
        rowCount = requestContext.getInteger("emailTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "emailTable." + student.getId() + "." + i;
            Boolean defaultAddress = requestContext.getBoolean(colPrefix + ".defaultAddress");
            ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
            String email = StringUtils.trim(requestContext.getString(colPrefix + ".email"));
            if (StringUtils.isNotBlank(email)) {
                Long emailId = requestContext.getLong(colPrefix + ".emailId");
                if (emailId == -1) {
                    emailId = emailDAO.create(student.getContactInfo(), contactType, defaultAddress, email).getId();
                } else {
                    emailDAO.update(emailDAO.findById(emailId), contactType, defaultAddress, email);
                }
                existingEmails.add(emailId);
            }
        }
        List<Email> emails = student.getContactInfo().getEmails();
        for (int i = emails.size() - 1; i >= 0; i--) {
            Email email = emails.get(i);
            if (!existingEmails.contains(email.getId())) {
                emailDAO.delete(email);
            }
        }
        // Phone numbers
        Set<Long> existingPhoneNumbers = new HashSet<>();
        rowCount = requestContext.getInteger("phoneTable." + student.getId() + ".rowCount");
        for (int i = 0; i < rowCount; i++) {
            String colPrefix = "phoneTable." + student.getId() + "." + i;
            Boolean defaultNumber = requestContext.getBoolean(colPrefix + ".defaultNumber");
            ContactType contactType = contactTypeDAO.findById(requestContext.getLong(colPrefix + ".contactTypeId"));
            String number = requestContext.getString(colPrefix + ".phone");
            Long phoneId = requestContext.getLong(colPrefix + ".phoneId");
            if (phoneId == -1 && number != null) {
                phoneId = phoneNumberDAO.create(student.getContactInfo(), contactType, defaultNumber, number).getId();
                existingPhoneNumbers.add(phoneId);
            } else if (phoneId > 0 && number != null) {
                phoneNumberDAO.update(phoneNumberDAO.findById(phoneId), contactType, defaultNumber, number);
                existingPhoneNumbers.add(phoneId);
            }
        }
        List<PhoneNumber> phoneNumbers = student.getContactInfo().getPhoneNumbers();
        for (int i = phoneNumbers.size() - 1; i >= 0; i--) {
            PhoneNumber phoneNumber = phoneNumbers.get(i);
            if (!existingPhoneNumbers.contains(phoneNumber.getId())) {
                phoneNumberDAO.delete(phoneNumber);
            }
        }
        Long studyProgrammeId = student.getStudyProgramme() != null ? student.getStudyProgramme().getId() : null;
        // #4226: Remove applications of nettipk/nettilukio students when their studies end
        if (studiesEnded && studyProgrammeId != null && (studyProgrammeId == 6L || studyProgrammeId == 7L)) {
            ApplicationDAO applicationDAO = DAOFactory.getInstance().getApplicationDAO();
            Application application = applicationDAO.findByStudent(student);
            if (application != null) {
                ApplicationUtils.deleteApplication(application);
            }
        }
    }
    // Contact information of a student won't be reflected to Person
    // used when searching students, so a manual re-index is needed
    person = personDAO.findById(person.getId());
    personDAO.forceReindex(person);
    requestContext.setRedirectURL(requestContext.getReferer(true));
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudentLodgingPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) InternalAuthenticationProvider(fi.otavanopisto.pyramus.plugin.auth.InternalAuthenticationProvider) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StudentEducationalLevelDAO(fi.otavanopisto.pyramus.dao.students.StudentEducationalLevelDAO) List(java.util.List) UserIdentificationDAO(fi.otavanopisto.pyramus.dao.users.UserIdentificationDAO) HashSet(java.util.HashSet) 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) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactInfoDAO(fi.otavanopisto.pyramus.dao.base.ContactInfoDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) StudentStudyPeriodType(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriodType) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) StaleObjectStateException(org.hibernate.StaleObjectStateException) Application(fi.otavanopisto.pyramus.domainmodel.application.Application) PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) User(fi.otavanopisto.pyramus.domainmodel.users.User) Sex(fi.otavanopisto.pyramus.domainmodel.students.Sex) StudentStudyEndReasonDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyEndReasonDAO) ApplicationDAO(fi.otavanopisto.pyramus.dao.application.ApplicationDAO) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) UserDAO(fi.otavanopisto.pyramus.dao.users.UserDAO) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) InternalAuth(fi.otavanopisto.pyramus.domainmodel.users.InternalAuth) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) StudentStudyPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentStudyPeriodDAO) StudentExaminationTypeDAO(fi.otavanopisto.pyramus.dao.students.StudentExaminationTypeDAO) CurriculumDAO(fi.otavanopisto.pyramus.dao.base.CurriculumDAO) TagDAO(fi.otavanopisto.pyramus.dao.base.TagDAO) StudentFunding(fi.otavanopisto.pyramus.domainmodel.students.StudentFunding) Date(java.util.Date) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) StudentLodgingPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentLodgingPeriod) PersonVariableDAO(fi.otavanopisto.pyramus.dao.users.PersonVariableDAO) InternalAuthDAO(fi.otavanopisto.pyramus.dao.users.InternalAuthDAO) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentStudyPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod) UserIdentification(fi.otavanopisto.pyramus.domainmodel.users.UserIdentification)

Example 12 with Municipality

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

the class CopyStudentStudyProgrammeJSONRequestController method process.

public void process(JSONRequestContext requestContext) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    CreditLinkDAO creditLinkDAO = DAOFactory.getInstance().getCreditLinkDAO();
    CourseAssessmentDAO courseAssessmentDAO = DAOFactory.getInstance().getCourseAssessmentDAO();
    TransferCreditDAO transferCreditDAO = DAOFactory.getInstance().getTransferCreditDAO();
    StaffMemberDAO userDAO = DAOFactory.getInstance().getStaffMemberDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    Long studentId = requestContext.getLong("studentId");
    Student oldStudent = studentDAO.findById(studentId);
    StaffMember loggedUser = userDAO.findById(requestContext.getLoggedUserId());
    if (!UserUtils.canAccessOrganization(loggedUser, oldStudent.getOrganization())) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Cannot access specified student");
    }
    Long newStudyProgrammeId = requestContext.getLong("newStudyProgrammeId");
    StudyProgramme newStudyProgramme = studyProgrammeDAO.findById(newStudyProgrammeId);
    if (newStudyProgramme == null) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNDEFINED, "New Study Programme not defined");
    }
    if (!UserUtils.canAccessOrganization(loggedUser, newStudyProgramme.getOrganization())) {
        throw new SmvcRuntimeException(PyramusStatusCode.UNAUTHORIZED, "Cannot access specified study programme");
    }
    Boolean linkCredits = requestContext.getBoolean("linkCredits");
    Boolean setAsDefaultUser = requestContext.getBoolean("setAsDefaultUser");
    Person person = oldStudent.getPerson();
    String firstName = oldStudent.getFirstName();
    String lastName = oldStudent.getLastName();
    String nickname = oldStudent.getNickname();
    String additionalInfo = oldStudent.getAdditionalInfo();
    // student.getPreviousStudies();
    Double previousStudies = null;
    // student.getStudyTimeEnd();
    Date studyTimeEnd = null;
    // student.getStudyStartDate();
    Date studyStartTime = null;
    // student.getStudyEndDate();
    Date studyEndTime = null;
    // student.getStudyEndText();
    String studyEndText = null;
    Language language = oldStudent.getLanguage();
    Municipality municipality = oldStudent.getMunicipality();
    StudentActivityType activityType = oldStudent.getActivityType();
    StudentExaminationType examinationType = oldStudent.getExaminationType();
    StudentEducationalLevel educationalLevel = oldStudent.getEducationalLevel();
    String education = oldStudent.getEducation();
    Nationality nationality = oldStudent.getNationality();
    School school = oldStudent.getSchool();
    // oldStudent.getStudyProgramme();
    StudyProgramme studyProgramme = newStudyProgramme;
    // student.getStudyEndReason();
    StudentStudyEndReason studyEndReason = null;
    Curriculum curriculum = oldStudent.getCurriculum();
    Student newStudent = studentDAO.create(person, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityType, examinationType, educationalLevel, education, nationality, municipality, language, school, studyProgramme, curriculum, previousStudies, studyStartTime, studyEndTime, studyEndReason, studyEndText, false);
    // Variables are not copied, but the default values are applied
    userVariableDAO.createDefaultValueVariables(newStudent);
    // Contact info
    contactInfoDAO.update(newStudent.getContactInfo(), oldStudent.getContactInfo().getAdditionalInfo());
    if (person.getDefaultUser() == null || Boolean.TRUE.equals(setAsDefaultUser)) {
        personDAO.updateDefaultUser(person, newStudent);
    }
    // Addresses
    List<Address> addresses = oldStudent.getContactInfo().getAddresses();
    for (int i = 0; i < addresses.size(); i++) {
        Address add = addresses.get(i);
        addressDAO.create(newStudent.getContactInfo(), add.getContactType(), add.getName(), add.getStreetAddress(), add.getPostalCode(), add.getCity(), add.getCountry(), add.getDefaultAddress());
    }
    // Email addresses
    List<Email> emails = oldStudent.getContactInfo().getEmails();
    for (int i = 0; i < emails.size(); i++) {
        Email email = emails.get(i);
        emailDAO.create(newStudent.getContactInfo(), email.getContactType(), email.getDefaultAddress(), email.getAddress());
    }
    // Phone numbers
    List<PhoneNumber> phoneNumbers = oldStudent.getContactInfo().getPhoneNumbers();
    for (int i = 0; i < phoneNumbers.size(); i++) {
        PhoneNumber phoneNumber = phoneNumbers.get(i);
        phoneNumberDAO.create(newStudent.getContactInfo(), phoneNumber.getContactType(), phoneNumber.getDefaultNumber(), phoneNumber.getNumber());
    }
    if (linkCredits) {
        List<CourseAssessment> assessments = courseAssessmentDAO.listByStudent(oldStudent);
        for (CourseAssessment assessment : assessments) {
            creditLinkDAO.create(assessment, newStudent, loggedUser);
        }
        List<TransferCredit> transferCredits = transferCreditDAO.listByStudent(oldStudent);
        for (TransferCredit transferCredit : transferCredits) {
            creditLinkDAO.create(transferCredit, newStudent, loggedUser);
        }
        List<CreditLink> creditLinks = creditLinkDAO.listByStudent(oldStudent);
        for (CreditLink creditLink : creditLinks) {
            creditLinkDAO.create(creditLink.getCredit(), newStudent, loggedUser);
        }
    }
    String redirectURL = requestContext.getRequest().getContextPath() + "/students/editstudent.page?student=" + newStudent.getPerson().getId();
    String refererAnchor = requestContext.getRefererAnchor();
    if (!StringUtils.isBlank(refererAnchor))
        redirectURL += "#" + refererAnchor;
    requestContext.setRedirectURL(redirectURL);
}
Also used : PhoneNumberDAO(fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) SmvcRuntimeException(fi.internetix.smvc.SmvcRuntimeException) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) StaffMemberDAO(fi.otavanopisto.pyramus.dao.users.StaffMemberDAO) TransferCreditDAO(fi.otavanopisto.pyramus.dao.grading.TransferCreditDAO) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) CourseAssessmentDAO(fi.otavanopisto.pyramus.dao.grading.CourseAssessmentDAO) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) CreditLinkDAO(fi.otavanopisto.pyramus.dao.grading.CreditLinkDAO) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Date(java.util.Date) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactInfoDAO(fi.otavanopisto.pyramus.dao.base.ContactInfoDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 13 with Municipality

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

the class SaveMunicipalitiesJSONRequestController method process.

public void process(JSONRequestContext jsonRequestContext) {
    MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
    int rowCount = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter("municipalitiesTable.rowCount")).intValue();
    for (int i = 0; i < rowCount; i++) {
        String colPrefix = "municipalitiesTable." + i;
        Long municipalityId = NumberUtils.createLong(jsonRequestContext.getRequest().getParameter(colPrefix + ".id"));
        String name = jsonRequestContext.getRequest().getParameter(colPrefix + ".name");
        String code = jsonRequestContext.getRequest().getParameter(colPrefix + ".code");
        boolean modified = NumberUtils.createInteger(jsonRequestContext.getRequest().getParameter(colPrefix + ".modified")) == 1;
        if (municipalityId == -1) {
            municipalityDAO.create(name, code);
        } else if (modified) {
            Municipality municipality = municipalityDAO.findById(municipalityId);
            municipalityDAO.update(municipality, name, code);
        }
    }
    jsonRequestContext.setRedirectURL(jsonRequestContext.getReferer(true));
}
Also used : Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO)

Example 14 with Municipality

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

the class ObjectFactory method init.

@PostConstruct
public void init() {
    mappers = new HashMap<>();
    addMappers(new Mapper<fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm>() {

        @Override
        public Object map(fi.otavanopisto.pyramus.domainmodel.base.AcademicTerm entity) {
            return new AcademicTerm(entity.getId(), entity.getName(), toOffsetDateTime(entity.getStartDate()), toOffsetDateTime(entity.getEndDate()), entity.getArchived());
        }
    }, new Mapper<CourseParticipationType>() {

        @Override
        public Object map(CourseParticipationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseParticipationType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseEnrolmentType>() {

        @Override
        public Object map(CourseEnrolmentType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseEnrolmentType(entity.getId(), entity.getName());
        }
    }, new Mapper<CourseState>() {

        @Override
        public Object map(CourseState entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseState(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseType>() {

        @Override
        public Object map(CourseType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseEducationType>() {

        @Override
        public Object map(CourseEducationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseEducationType(entity.getId(), entity.getEducationType().getId(), false);
        }
    }, new Mapper<CourseEducationSubtype>() {

        @Override
        public Object map(CourseEducationSubtype entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseEducationSubtype(entity.getId(), entity.getEducationSubtype().getId(), false);
        }
    }, new Mapper<Course>() {

        @Override
        public Object map(Course entity) {
            Long subjectId = null;
            Subject courseSubject = entity.getSubject();
            if (courseSubject != null) {
                subjectId = courseSubject.getId();
            }
            List<String> tags = new ArrayList<>();
            Set<Tag> courseTags = entity.getTags();
            if (courseTags != null) {
                for (Tag courseTag : courseTags) {
                    tags.add(courseTag.getText());
                }
            }
            Double length = entity.getCourseLength() != null ? entity.getCourseLength().getUnits() : null;
            Long lengthUnitId = entity.getCourseLength() != null && entity.getCourseLength().getUnit() != null ? entity.getCourseLength().getUnit().getId() : null;
            OffsetDateTime created = toOffsetDateTime(entity.getCreated());
            OffsetDateTime lastModified = toOffsetDateTime(entity.getLastModified());
            OffsetDateTime beginDate = fromDateToOffsetDateTime(entity.getBeginDate());
            OffsetDateTime endDate = fromDateToOffsetDateTime(entity.getEndDate());
            OffsetDateTime enrolmentTimeEnd = toOffsetDateTime(entity.getEnrolmentTimeEnd());
            Long creatorId = entity.getCreator() != null ? entity.getCreator().getId() : null;
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            Long moduleId = entity.getModule() != null ? entity.getModule().getId() : null;
            Long stateId = entity.getState() != null ? entity.getState().getId() : null;
            Long typeId = entity.getType() != null ? entity.getType().getId() : null;
            Set<Long> curriculumIds = new HashSet<Long>();
            for (fi.otavanopisto.pyramus.domainmodel.base.Curriculum curriculum : entity.getCurriculums()) curriculumIds.add(curriculum.getId());
            List<CourseBaseVariable> entityVariables = courseController.listCourseVariablesByCourse(entity);
            Map<String, String> variables = new HashMap<>();
            for (CourseBaseVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            ;
            // #1257: Course's primary education type and subtype
            // If the course has subject defined, primary education type is that of the subject.
            // If no subject is defined, and course has only one education type, that is primary.
            // Primary subtype exists, if the course has only one subtype belonging to the primary education type.
            EducationType educationType = null;
            EducationSubtype educationSubtype = null;
            if (entity.getSubject() != null && entity.getSubject().getEducationType() != null) {
                educationType = entity.getSubject().getEducationType();
            } else if (entity.getCourseEducationTypes().size() == 1) {
                educationType = entity.getCourseEducationTypes().get(0).getEducationType();
            }
            if (educationType != null && !entity.getCourseEducationTypes().isEmpty()) {
                for (CourseEducationType cet : entity.getCourseEducationTypes()) {
                    if (cet.getEducationType().getId().equals(educationType.getId())) {
                        if (cet.getCourseEducationSubtypes().size() == 1) {
                            educationSubtype = cet.getCourseEducationSubtypes().get(0).getEducationSubtype();
                        }
                        break;
                    }
                }
            }
            return new fi.otavanopisto.pyramus.rest.model.Course(entity.getId(), entity.getName(), created, lastModified, entity.getDescription(), entity.getArchived(), entity.getCourseNumber(), entity.getMaxParticipantCount(), beginDate, endDate, entity.getNameExtension(), entity.getLocalTeachingDays(), entity.getTeachingHours(), entity.getDistanceTeachingHours(), entity.getDistanceTeachingDays(), entity.getAssessingHours(), entity.getPlanningHours(), enrolmentTimeEnd, creatorId, lastModifierId, subjectId, curriculumIds, length, lengthUnitId, moduleId, stateId, typeId, variables, tags, entity.getOrganization() == null ? null : entity.getOrganization().getId(), entity.isCourseTemplate(), educationType == null ? null : educationType.getId(), educationSubtype == null ? null : educationSubtype.getId());
        }
    }, new Mapper<CourseComponent>() {

        @Override
        public Object map(CourseComponent entity) {
            Long lengthUnitId = entity.getLength() != null ? entity.getLength().getUnit().getId() : null;
            Double length = entity.getLength() != null ? entity.getLength().getUnits() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseComponent(entity.getId(), entity.getName(), entity.getDescription(), length, lengthUnitId, entity.getArchived());
        }
    }, new Mapper<CourseDescription>() {

        @Override
        public Object map(CourseDescription entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseDescription(entity.getId(), entity.getCourseBase().getId(), entity.getCategory().getId(), entity.getDescription());
        }
    }, new Mapper<CourseDescriptionCategory>() {

        @Override
        public Object map(CourseDescriptionCategory entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseDescriptionCategory(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<CourseAssessment>() {

        @Override
        public Object map(CourseAssessment entity) {
            Long courseStudentId = entity.getCourseStudent() != null ? entity.getCourseStudent().getId() : null;
            Long gradeId = entity.getGrade() != null ? entity.getGrade().getId() : null;
            Long gradingScaleId = entity.getGrade() != null && entity.getGrade().getGradingScale() != null ? entity.getGrade().getGradingScale().getId() : null;
            Long assessorId = entity.getAssessor() != null ? entity.getAssessor().getId() : null;
            Boolean passing = entity.getGrade() != null ? entity.getGrade().getPassingGrade() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseAssessment(entity.getId(), courseStudentId, gradeId, gradingScaleId, assessorId, toOffsetDateTime(entity.getDate()), entity.getVerbalAssessment(), passing);
        }
    }, new Mapper<TransferCredit>() {

        @Override
        public Object map(TransferCredit entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            OffsetDateTime date = toOffsetDateTime(entity.getDate());
            Long gradeId = entity.getGrade() != null ? entity.getGrade().getId() : null;
            Long gradigScaleId = entity.getGrade() != null ? entity.getGrade().getGradingScale().getId() : null;
            Long assessorId = entity.getAssessor() != null ? entity.getAssessor().getId() : null;
            Double length = entity.getCourseLength() != null ? entity.getCourseLength().getUnits() : null;
            Long lengthUnitId = entity.getCourseLength() != null ? entity.getCourseLength().getUnit().getId() : null;
            Long schoolId = entity.getSchool() != null ? entity.getSchool().getId() : null;
            Long subjectId = entity.getSubject() != null ? entity.getSubject().getId() : null;
            CourseOptionality optionality = entity.getOptionality() != null ? CourseOptionality.valueOf(entity.getOptionality().name()) : null;
            Long curriculumId = entity.getCurriculum() != null ? entity.getCurriculum().getId() : null;
            Boolean offCurriculum = entity.getOffCurriculum() != null ? entity.getOffCurriculum() : Boolean.FALSE;
            return new fi.otavanopisto.pyramus.rest.model.TransferCredit(entity.getId(), studentId, date, gradeId, gradigScaleId, entity.getVerbalAssessment(), assessorId, entity.getArchived(), entity.getCourseName(), entity.getCourseNumber(), length, lengthUnitId, schoolId, subjectId, optionality, curriculumId, offCurriculum);
        }
    }, new Mapper<CreditLink>() {

        @Override
        public Object map(CreditLink entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            if (entity.getCredit() != null) {
                switch(entity.getCredit().getCreditType()) {
                    case CourseAssessment:
                        fi.otavanopisto.pyramus.rest.model.CourseAssessment credit = (fi.otavanopisto.pyramus.rest.model.CourseAssessment) createModel(entity.getCredit());
                        return new fi.otavanopisto.pyramus.rest.model.CreditLinkCourseAssessment(entity.getId(), studentId, credit);
                    case TransferCredit:
                        fi.otavanopisto.pyramus.rest.model.TransferCredit tc = (fi.otavanopisto.pyramus.rest.model.TransferCredit) createModel(entity.getCredit());
                        return new fi.otavanopisto.pyramus.rest.model.CreditLinkTransferCredit(entity.getId(), studentId, tc);
                    default:
                        return null;
                }
            }
            return null;
        }
    }, new Mapper<CourseAssessmentRequest>() {

        @Override
        public Object map(CourseAssessmentRequest entity) {
            OffsetDateTime created = toOffsetDateTime(entity.getCreated());
            return new fi.otavanopisto.pyramus.rest.model.CourseAssessmentRequest(entity.getId(), entity.getCourseStudent().getId(), created, entity.getRequestText(), entity.getArchived(), entity.getHandled());
        }
    }, new Mapper<EducationType>() {

        @Override
        public Object map(EducationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.EducationType(entity.getId(), entity.getName(), entity.getCode(), entity.getArchived());
        }
    }, new Mapper<EducationSubtype>() {

        @Override
        public Object map(EducationSubtype entity) {
            Long educationTypeId = entity.getEducationType() != null ? entity.getEducationType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.EducationSubtype(entity.getId(), entity.getName(), entity.getCode(), educationTypeId, entity.getArchived());
        }
    }, new Mapper<Subject>() {

        @Override
        public Object map(Subject entity) {
            Long educationTypeId = entity.getEducationType() != null ? entity.getEducationType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Subject(entity.getId(), entity.getCode(), entity.getName(), educationTypeId, entity.getArchived());
        }
    }, new Mapper<GradingScale>() {

        @Override
        public Object map(GradingScale entity) {
            return new fi.otavanopisto.pyramus.rest.model.GradingScale(entity.getId(), entity.getName(), entity.getDescription(), entity.getArchived());
        }
    }, new Mapper<Grade>() {

        @Override
        public Object map(Grade entity) {
            Long gradingScaleId = entity.getGradingScale() != null ? entity.getGradingScale().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Grade(entity.getId(), entity.getName(), entity.getDescription(), gradingScaleId, entity.getPassingGrade(), entity.getQualification(), entity.getGPA(), entity.getArchived());
        }
    }, new Mapper<EducationalTimeUnit>() {

        @Override
        public Object map(EducationalTimeUnit entity) {
            return new fi.otavanopisto.pyramus.rest.model.EducationalTimeUnit(entity.getId(), entity.getName(), entity.getSymbol(), entity.getBaseUnits(), entity.getArchived());
        }
    }, new Mapper<Module>() {

        @Override
        public Object map(Module entity) {
            Long creatorId = entity.getCreator().getId();
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            Long subjectId = entity.getSubject() != null ? entity.getSubject().getId() : null;
            Double length = entity.getCourseLength() != null ? entity.getCourseLength().getUnits() : null;
            Long lenghtUnitId = entity.getCourseLength() != null && entity.getCourseLength().getUnit() != null ? entity.getCourseLength().getUnit().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> moduleTags = entity.getTags();
            if (moduleTags != null) {
                for (Tag courseTag : moduleTags) {
                    tags.add(courseTag.getText());
                }
            }
            Set<Long> curriculumIds = new HashSet<Long>();
            for (fi.otavanopisto.pyramus.domainmodel.base.Curriculum curriculum : entity.getCurriculums()) curriculumIds.add(curriculum.getId());
            return new fi.otavanopisto.pyramus.rest.model.Module(entity.getId(), entity.getName(), toOffsetDateTime(entity.getCreated()), toOffsetDateTime(entity.getLastModified()), entity.getDescription(), entity.getArchived(), entity.getCourseNumber(), entity.getMaxParticipantCount(), creatorId, lastModifierId, subjectId, curriculumIds, length, lenghtUnitId, tags);
        }
    }, new Mapper<ModuleComponent>() {

        @Override
        public Object map(ModuleComponent entity) {
            Long lengthUnitId = entity.getLength() != null && entity.getLength().getUnit() != null ? entity.getLength().getUnit().getId() : null;
            Double length = entity.getLength() != null ? entity.getLength().getUnits() : null;
            return new fi.otavanopisto.pyramus.rest.model.ModuleComponent(entity.getId(), entity.getName(), entity.getDescription(), length, lengthUnitId, entity.getArchived());
        }
    }, new Mapper<Project>() {

        @Override
        public Object map(Project entity) {
            Double optionalStudiesLength = entity.getOptionalStudiesLength() != null ? entity.getOptionalStudiesLength().getUnits() : null;
            Long optionalStudiesLengthUnitId = entity.getOptionalStudiesLength() != null && entity.getOptionalStudiesLength().getUnit() != null ? entity.getOptionalStudiesLength().getUnit().getId() : null;
            Long creatorId = entity.getCreator().getId();
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            return new fi.otavanopisto.pyramus.rest.model.Project(entity.getId(), entity.getName(), entity.getDescription(), optionalStudiesLength, optionalStudiesLengthUnitId, toOffsetDateTime(entity.getCreated()), creatorId, toOffsetDateTime(entity.getLastModified()), lastModifierId, tags, entity.getArchived());
        }
    }, new Mapper<ProjectModule>() {

        @Override
        public Object map(ProjectModule entity) {
            ProjectModuleOptionality optionality = null;
            switch(entity.getOptionality()) {
                case MANDATORY:
                    optionality = ProjectModuleOptionality.MANDATORY;
                    break;
                case OPTIONAL:
                    optionality = ProjectModuleOptionality.OPTIONAL;
                    break;
            }
            Long moduleId = entity.getModule() != null ? entity.getModule().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.ProjectModule(entity.getId(), moduleId, optionality);
        }
    }, new Mapper<School>() {

        @Override
        public Object map(School entity) {
            Long fieldId = entity.getField() != null ? entity.getField().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            List<SchoolVariable> entityVariables = schoolController.listSchoolVariablesBySchool(entity);
            Map<String, String> variables = new HashMap<>();
            for (SchoolVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            String additionalInfo = entity.getContactInfo() != null ? entity.getContactInfo().getAdditionalInfo() : null;
            return new fi.otavanopisto.pyramus.rest.model.School(entity.getId(), entity.getCode(), entity.getName(), tags, fieldId, additionalInfo, entity.getArchived(), variables);
        }
    }, new Mapper<SchoolField>() {

        @Override
        public Object map(SchoolField entity) {
            return new fi.otavanopisto.pyramus.rest.model.SchoolField(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<SchoolVariableKey>() {

        @Override
        public Object map(SchoolVariableKey entity) {
            return new fi.otavanopisto.pyramus.rest.model.VariableKey(entity.getVariableKey(), entity.getVariableName(), entity.getUserEditable(), toVariableType(entity.getVariableType()));
        }
    }, new Mapper<CourseBaseVariableKey>() {

        @Override
        public Object map(CourseBaseVariableKey entity) {
            return new fi.otavanopisto.pyramus.rest.model.VariableKey(entity.getVariableKey(), entity.getVariableName(), entity.getUserEditable(), toVariableType(entity.getVariableType()));
        }
    }, new Mapper<Language>() {

        @Override
        public Object map(Language entity) {
            return new fi.otavanopisto.pyramus.rest.model.Language(entity.getId(), entity.getCode(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<Municipality>() {

        @Override
        public Object map(Municipality entity) {
            return new fi.otavanopisto.pyramus.rest.model.Municipality(entity.getId(), entity.getCode(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<Nationality>() {

        @Override
        public Object map(Nationality entity) {
            return new fi.otavanopisto.pyramus.rest.model.Nationality(entity.getId(), entity.getCode(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudentActivityType>() {

        @Override
        public Object map(StudentActivityType entity) {
            return new fi.otavanopisto.pyramus.rest.model.StudentActivityType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudentEducationalLevel>() {

        @Override
        public Object map(StudentEducationalLevel entity) {
            return new fi.otavanopisto.pyramus.rest.model.StudentEducationalLevel(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudentExaminationType>() {

        @Override
        public Object map(StudentExaminationType entity) {
            return new fi.otavanopisto.pyramus.rest.model.StudentExaminationType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<StudyProgrammeCategory>() {

        @Override
        public Object map(StudyProgrammeCategory entity) {
            Long educationTypeId = entity.getEducationType() != null ? entity.getEducationType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudyProgrammeCategory(entity.getId(), entity.getName(), educationTypeId, entity.getArchived());
        }
    }, new Mapper<StudyProgramme>() {

        @Override
        public Object map(StudyProgramme entity) {
            Long categoryId = entity.getCategory() != null ? entity.getCategory().getId() : null;
            Long organizationId = entity.getOrganization() != null ? entity.getOrganization().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudyProgramme(entity.getId(), organizationId, entity.getCode(), entity.getName(), categoryId, entity.getHasEvaluationFees(), entity.getArchived());
        }
    }, new Mapper<StudentGroup>() {

        public Object map(StudentGroup entity) {
            Long creatorId = entity.getCreator().getId();
            Long lastModifierId = entity.getLastModifier() != null ? entity.getLastModifier().getId() : null;
            Long organizationId = entity.getOrganization() != null ? entity.getOrganization().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            return new fi.otavanopisto.pyramus.rest.model.StudentGroup(entity.getId(), entity.getName(), entity.getDescription(), toOffsetDateTime(entity.getBeginDate()), creatorId, toOffsetDateTime(entity.getCreated()), lastModifierId, toOffsetDateTime(entity.getLastModified()), tags, entity.getGuidanceGroup(), organizationId, entity.getArchived());
        }
    }, new Mapper<Person>() {

        public Object map(Person entity) {
            Sex sex = null;
            if (entity.getSex() != null) {
                switch(entity.getSex()) {
                    case FEMALE:
                        sex = Sex.FEMALE;
                        break;
                    case MALE:
                        sex = Sex.MALE;
                        break;
                    case OTHER:
                        sex = Sex.OTHER;
                        break;
                }
            }
            Long defaultUserId = entity.getDefaultUser() != null ? entity.getDefaultUser().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Person(entity.getId(), toOffsetDateTime(entity.getBirthday()), entity.getSocialSecurityNumber(), sex, entity.getSecureInfo(), entity.getBasicInfo(), defaultUserId);
        }
    }, new Mapper<Student>() {

        public Object map(Student entity) {
            Long personId = entity.getPerson() != null ? entity.getPerson().getId() : null;
            Long nationalityId = entity.getNationality() != null ? entity.getNationality().getId() : null;
            Long languageId = entity.getLanguage() != null ? entity.getLanguage().getId() : null;
            Long municipalityId = entity.getMunicipality() != null ? entity.getMunicipality().getId() : null;
            Long schoolId = entity.getSchool() != null ? entity.getSchool().getId() : null;
            Long activityTypeId = entity.getActivityType() != null ? entity.getActivityType().getId() : null;
            Long examinationTypeId = entity.getExaminationType() != null ? entity.getExaminationType().getId() : null;
            Long educationalLevelId = entity.getEducationalLevel() != null ? entity.getEducationalLevel().getId() : null;
            Long studyProgrammeId = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getId() : null;
            Long studyEndReasonId = entity.getStudyEndReason() != null ? entity.getStudyEndReason().getId() : null;
            Long curriculumId = entity.getCurriculum() != null ? entity.getCurriculum().getId() : null;
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            List<UserVariable> entityVariables = userController.listUserVariablesByUser(entity);
            Map<String, String> variables = new HashMap<>();
            for (UserVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            ;
            String additionalContectInfo = entity.getContactInfo() != null ? entity.getContactInfo().getAdditionalInfo() : null;
            // TODO Remove this from the rest model
            boolean lodging = false;
            return new fi.otavanopisto.pyramus.rest.model.Student(entity.getId(), personId, entity.getFirstName(), entity.getLastName(), entity.getNickname(), entity.getAdditionalInfo(), additionalContectInfo, nationalityId, languageId, municipalityId, schoolId, activityTypeId, examinationTypeId, educationalLevelId, toOffsetDateTime(entity.getStudyTimeEnd()), studyProgrammeId, curriculumId, entity.getPreviousStudies(), entity.getEducation(), lodging, toOffsetDateTime(entity.getStudyStartDate()), toOffsetDateTime(entity.getStudyEndDate()), studyEndReasonId, entity.getStudyEndText(), variables, tags, entity.getArchived());
        }
    }, new Mapper<StudentStudyEndReason>() {

        @Override
        public Object map(StudentStudyEndReason entity) {
            Long parentReasonId = entity.getParentReason() != null ? entity.getParentReason().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudentStudyEndReason(entity.getId(), entity.getName(), parentReasonId);
        }
    }, new Mapper<StudentContactLogEntry>() {

        @Override
        public Object map(StudentContactLogEntry entity) {
            StudentContactLogEntryType type = StudentContactLogEntryType.valueOf(entity.getType().name());
            return new fi.otavanopisto.pyramus.rest.model.StudentContactLogEntry(entity.getId(), entity.getText(), entity.getCreatorName(), toOffsetDateTime(entity.getEntryDate()), type, entity.getArchived());
        }
    }, new Mapper<StudentGroupStudent>() {

        @Override
        public Object map(StudentGroupStudent entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudentGroupStudent(entity.getId(), studentId);
        }
    }, new Mapper<StudentGroupUser>() {

        @Override
        public Object map(StudentGroupUser entity) {
            Long staffMemberId = entity.getStaffMember() != null ? entity.getStaffMember().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StudentGroupUser(entity.getId(), staffMemberId);
        }
    }, new Mapper<Email>() {

        @Override
        public Object map(Email entity) {
            Long contactTypeId = entity.getContactType() != null ? entity.getContactType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Email(entity.getId(), contactTypeId, entity.getDefaultAddress(), entity.getAddress());
        }
    }, new Mapper<PhoneNumber>() {

        @Override
        public Object map(PhoneNumber entity) {
            Long contactTypeId = entity.getContactType() != null ? entity.getContactType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.PhoneNumber(entity.getId(), contactTypeId, entity.getDefaultNumber(), entity.getNumber());
        }
    }, new Mapper<ContactURL>() {

        @Override
        public Object map(ContactURL entity) {
            Long contactURLTypeId = entity.getContactURLType() != null ? entity.getContactURLType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.ContactURL(entity.getId(), contactURLTypeId, entity.getURL());
        }
    }, new Mapper<Address>() {

        @Override
        public Object map(Address entity) {
            Long contactTypeId = entity.getContactType() != null ? entity.getContactType().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.Address(entity.getId(), contactTypeId, entity.getDefaultAddress(), entity.getName(), entity.getStreetAddress(), entity.getPostalCode(), entity.getCity(), entity.getCountry());
        }
    }, new Mapper<ContactType>() {

        @Override
        public Object map(ContactType entity) {
            return new fi.otavanopisto.pyramus.rest.model.ContactType(entity.getId(), entity.getName(), entity.getArchived(), entity.getNonUnique());
        }
    }, new Mapper<ContactURLType>() {

        @Override
        public Object map(ContactURLType entity) {
            return new fi.otavanopisto.pyramus.rest.model.ContactURLType(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<UserVariableKey>() {

        @Override
        public Object map(UserVariableKey entity) {
            return new fi.otavanopisto.pyramus.rest.model.VariableKey(entity.getVariableKey(), entity.getVariableName(), entity.getUserEditable(), toVariableType(entity.getVariableType()));
        }
    }, new Mapper<CourseStaffMemberRole>() {

        @Override
        public Object map(CourseStaffMemberRole entity) {
            return new fi.otavanopisto.pyramus.rest.model.CourseStaffMemberRole(entity.getId(), entity.getName());
        }
    }, new Mapper<CourseStaffMember>() {

        @Override
        public Object map(CourseStaffMember entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long userId = entity.getStaffMember() != null ? entity.getStaffMember().getId() : null;
            Long roleId = entity.getRole() != null ? entity.getRole().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseStaffMember(entity.getId(), courseId, userId, roleId);
        }
    }, new Mapper<CourseStudent>() {

        @Override
        public Object map(CourseStudent entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            Long participantTypeId = entity.getParticipationType() != null ? entity.getParticipationType().getId() : null;
            Long courseEnrolmentTypeId = entity.getCourseEnrolmentType() != null ? entity.getCourseEnrolmentType().getId() : null;
            CourseOptionality optionality = entity.getOptionality() != null ? CourseOptionality.valueOf(entity.getOptionality().name()) : null;
            Long billingDetailsId = entity.getBillingDetails() != null ? entity.getBillingDetails().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.CourseStudent(entity.getId(), courseId, studentId, toOffsetDateTime(entity.getEnrolmentTime()), entity.getArchived(), participantTypeId, courseEnrolmentTypeId, entity.getLodging(), optionality, billingDetailsId);
        }
    }, new Mapper<StaffMember>() {

        public Object map(StaffMember entity) {
            List<String> tags = new ArrayList<>();
            Set<Tag> entityTags = entity.getTags();
            if (entityTags != null) {
                for (Tag entityTag : entityTags) {
                    tags.add(entityTag.getText());
                }
            }
            List<UserVariable> entityVariables = userController.listUserVariablesByUser(entity);
            Map<String, String> variables = new HashMap<>();
            for (UserVariable entityVariable : entityVariables) {
                variables.put(entityVariable.getKey().getVariableKey(), entityVariable.getValue());
            }
            ;
            UserRole role = UserRole.valueOf(entity.getRole().name());
            String additionalContactInfo = entity.getContactInfo() != null ? entity.getContactInfo().getAdditionalInfo() : null;
            Long personId = entity.getPerson() != null ? entity.getPerson().getId() : null;
            Long organizationId = entity.getOrganization() != null ? entity.getOrganization().getId() : null;
            return new fi.otavanopisto.pyramus.rest.model.StaffMember(entity.getId(), personId, organizationId, additionalContactInfo, entity.getFirstName(), entity.getLastName(), entity.getTitle(), role, tags, variables);
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.base.Curriculum>() {

        @Override
        public Object map(fi.otavanopisto.pyramus.domainmodel.base.Curriculum entity) {
            return new Curriculum(entity.getId(), entity.getName(), entity.getArchived());
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.base.Organization>() {

        @Override
        public Object map(Organization entity) {
            BillingDetails billingDetails = entity.getBillingDetails();
            fi.otavanopisto.pyramus.rest.model.BillingDetails billingDetailsRestModel = null;
            if (billingDetails != null) {
                billingDetailsRestModel = new fi.otavanopisto.pyramus.rest.model.BillingDetails(billingDetails.getId(), billingDetails.getPersonName(), billingDetails.getCompanyName(), billingDetails.getStreetAddress1(), billingDetails.getStreetAddress2(), billingDetails.getPostalCode(), billingDetails.getCity(), billingDetails.getRegion(), billingDetails.getCountry(), billingDetails.getPhoneNumber(), billingDetails.getEmailAddress(), billingDetails.getCompanyIdentifier(), billingDetails.getReferenceNumber(), billingDetails.getElectronicBillingAddress(), billingDetails.getElectronicBillingOperator(), billingDetails.getNotes());
            }
            List<OrganizationContractPeriod> contractPeriods = organizationContractPeriodDAO.listBy(entity);
            List<fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod> contractPeriodsModel = contractPeriods.stream().map(contractPeriod -> {
                Long id = contractPeriod.getId();
                LocalDate begin = contractPeriod.getBegin() != null ? new java.sql.Date(contractPeriod.getBegin().getTime()).toLocalDate() : null;
                LocalDate end = contractPeriod.getEnd() != null ? new java.sql.Date(contractPeriod.getEnd().getTime()).toLocalDate() : null;
                return new fi.otavanopisto.pyramus.rest.model.OrganizationContractPeriod(id, begin, end);
            }).collect(Collectors.toList());
            List<OrganizationContactPerson> contactPersons = organizationContactPersonDAO.listBy(entity);
            List<fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson> contactPersonsModel = contactPersons.stream().map(contactPerson -> {
                Long id = contactPerson.getId();
                OrganizationContactPersonType type = contactPerson.getType() != null ? OrganizationContactPersonType.valueOf(contactPerson.getType().name()) : null;
                String name = contactPerson.getName();
                String email = contactPerson.getEmail();
                String phone = contactPerson.getPhone();
                String title = contactPerson.getTitle();
                return new fi.otavanopisto.pyramus.rest.model.OrganizationContactPerson(id, type, name, email, phone, title);
            }).collect(Collectors.toList());
            fi.otavanopisto.pyramus.rest.model.Organization organizationModel = new fi.otavanopisto.pyramus.rest.model.Organization(entity.getId(), entity.getName(), billingDetailsRestModel, entity.getArchived());
            organizationModel.setContactPersons(contactPersonsModel);
            organizationModel.setContractPeriods(contractPeriodsModel);
            return organizationModel;
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod>() {

        @Override
        public Object map(StudentStudyPeriod entity) {
            Long studentId = entity.getStudent() != null ? entity.getStudent().getId() : null;
            StudentStudyPeriodType type = entity.getPeriodType() != null ? StudentStudyPeriodType.valueOf(entity.getPeriodType().toString()) : null;
            LocalDate begin = entity.getBegin() != null ? Instant.ofEpochMilli(entity.getBegin().getTime()).atZone(ZoneId.systemDefault()).toLocalDate() : null;
            LocalDate end = entity.getEnd() != null ? Instant.ofEpochMilli(entity.getEnd().getTime()).atZone(ZoneId.systemDefault()).toLocalDate() : null;
            return new fi.otavanopisto.pyramus.rest.model.students.StudentStudyPeriod(entity.getId(), studentId, type, begin, end);
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup>() {

        @Override
        public Object map(CourseSignupStudentGroup entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long studentGroupId = entity.getStudentGroup() != null ? entity.getStudentGroup().getId() : null;
            String studentGroupName = entity.getStudentGroup() != null ? entity.getStudentGroup().getName() : null;
            Organization studentGroupOrganization = entity.getStudentGroup() != null ? entity.getStudentGroup().getOrganization() : null;
            fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo organization = studentGroupOrganization != null ? new fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo(studentGroupOrganization.getId(), studentGroupOrganization.getName(), studentGroupOrganization.getArchived()) : null;
            return new fi.otavanopisto.pyramus.rest.model.course.CourseSignupStudentGroup(entity.getId(), courseId, studentGroupId, studentGroupName, organization);
        }
    }, new Mapper<fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme>() {

        @Override
        public Object map(CourseSignupStudyProgramme entity) {
            Long courseId = entity.getCourse() != null ? entity.getCourse().getId() : null;
            Long studyProgrammeId = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getId() : null;
            String studyProgrammeName = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getName() : null;
            Organization studyProgrammeOrganization = entity.getStudyProgramme() != null ? entity.getStudyProgramme().getOrganization() : null;
            fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo organization = studyProgrammeOrganization != null ? new fi.otavanopisto.pyramus.rest.model.OrganizationBasicInfo(studyProgrammeOrganization.getId(), studyProgrammeOrganization.getName(), studyProgrammeOrganization.getArchived()) : null;
            return new fi.otavanopisto.pyramus.rest.model.course.CourseSignupStudyProgramme(entity.getId(), courseId, studyProgrammeId, studyProgrammeName, organization);
        }
    });
}
Also used : UserVariable(fi.otavanopisto.pyramus.domainmodel.users.UserVariable) LocalDate(java.time.LocalDate) Project(fi.otavanopisto.pyramus.domainmodel.projects.Project) OrganizationContactPersonType(fi.otavanopisto.pyramus.rest.model.OrganizationContactPersonType) Set(java.util.Set) HashSet(java.util.HashSet) Sex(fi.otavanopisto.pyramus.rest.model.Sex) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) ContactURL(fi.otavanopisto.pyramus.domainmodel.base.ContactURL) CourseEnrolmentType(fi.otavanopisto.pyramus.domainmodel.courses.CourseEnrolmentType) CourseBaseVariableKey(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariableKey) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Curriculum(fi.otavanopisto.pyramus.rest.model.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) StudentGroup(fi.otavanopisto.pyramus.domainmodel.students.StudentGroup) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) OrganizationContactPerson(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPerson) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) ArrayList(java.util.ArrayList) List(java.util.List) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course) EducationalTimeUnit(fi.otavanopisto.pyramus.domainmodel.base.EducationalTimeUnit) OffsetDateTime(java.time.OffsetDateTime) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) CourseOptionality(fi.otavanopisto.pyramus.rest.model.CourseOptionality) SchoolVariable(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariable) School(fi.otavanopisto.pyramus.domainmodel.base.School) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) CourseState(fi.otavanopisto.pyramus.domainmodel.courses.CourseState) CourseSignupStudentGroup(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudentGroup) SchoolField(fi.otavanopisto.pyramus.domainmodel.base.SchoolField) BillingDetails(fi.otavanopisto.pyramus.domainmodel.base.BillingDetails) Subject(fi.otavanopisto.pyramus.domainmodel.base.Subject) ProjectModuleOptionality(fi.otavanopisto.pyramus.rest.model.ProjectModuleOptionality) UserRole(fi.otavanopisto.pyramus.rest.model.UserRole) CourseStaffMember(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMember) OrganizationContractPeriod(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContractPeriod) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) UserVariableKey(fi.otavanopisto.pyramus.domainmodel.users.UserVariableKey) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) CourseBaseVariable(fi.otavanopisto.pyramus.domainmodel.base.CourseBaseVariable) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudyProgrammeCategory(fi.otavanopisto.pyramus.domainmodel.base.StudyProgrammeCategory) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) CourseStudent(fi.otavanopisto.pyramus.domainmodel.courses.CourseStudent) StudentGroupStudent(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupStudent) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) ModuleComponent(fi.otavanopisto.pyramus.domainmodel.modules.ModuleComponent) StudentStudyPeriodType(fi.otavanopisto.pyramus.rest.model.students.StudentStudyPeriodType) ProjectModule(fi.otavanopisto.pyramus.domainmodel.projects.ProjectModule) Module(fi.otavanopisto.pyramus.domainmodel.modules.Module) Map(java.util.Map) HashMap(java.util.HashMap) OrganizationContactPerson(fi.otavanopisto.pyramus.domainmodel.base.OrganizationContactPerson) Person(fi.otavanopisto.pyramus.domainmodel.base.Person) Organization(fi.otavanopisto.pyramus.domainmodel.base.Organization) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) EducationType(fi.otavanopisto.pyramus.domainmodel.base.EducationType) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) CourseSignupStudyProgramme(fi.otavanopisto.pyramus.domainmodel.courses.CourseSignupStudyProgramme) CourseComponent(fi.otavanopisto.pyramus.domainmodel.courses.CourseComponent) CourseType(fi.otavanopisto.pyramus.domainmodel.courses.CourseType) CourseAssessment(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessment) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag) StudentStudyPeriod(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyPeriod) GradingScale(fi.otavanopisto.pyramus.domainmodel.grading.GradingScale) CourseStaffMemberRole(fi.otavanopisto.pyramus.domainmodel.courses.CourseStaffMemberRole) StudentContactLogEntry(fi.otavanopisto.pyramus.domainmodel.students.StudentContactLogEntry) CourseDescription(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescription) CreditLink(fi.otavanopisto.pyramus.domainmodel.grading.CreditLink) CourseEducationType(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationType) CourseEducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.CourseEducationSubtype) EducationSubtype(fi.otavanopisto.pyramus.domainmodel.base.EducationSubtype) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) Grade(fi.otavanopisto.pyramus.domainmodel.grading.Grade) SchoolVariableKey(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariableKey) StudentContactLogEntryType(fi.otavanopisto.pyramus.rest.model.StudentContactLogEntryType) CourseAssessmentRequest(fi.otavanopisto.pyramus.domainmodel.grading.CourseAssessmentRequest) CourseDescriptionCategory(fi.otavanopisto.pyramus.domainmodel.courses.CourseDescriptionCategory) CourseParticipationType(fi.otavanopisto.pyramus.domainmodel.courses.CourseParticipationType) Date(java.util.Date) LocalDate(java.time.LocalDate) AcademicTerm(fi.otavanopisto.pyramus.rest.model.AcademicTerm) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) TransferCredit(fi.otavanopisto.pyramus.domainmodel.grading.TransferCredit) StudentGroupUser(fi.otavanopisto.pyramus.domainmodel.students.StudentGroupUser) PostConstruct(javax.annotation.PostConstruct)

Example 15 with Municipality

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

the class ApplicationRESTService method listMunicipalities.

@Path("/municipalities")
@GET
@Unsecure
public Response listMunicipalities() {
    List<Municipality> municipalities = municipalityDAO.listAll();
    municipalities.sort(new Comparator<Municipality>() {

        public int compare(Municipality o1, Municipality o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    List<HashMap<String, String>> municipalityList = new ArrayList<HashMap<String, String>>();
    for (Municipality municipality : municipalities) {
        HashMap<String, String> municipalityData = new HashMap<String, String>();
        municipalityData.put("text", municipality.getName());
        municipalityData.put("value", municipality.getId().toString());
        municipalityList.add(municipalityData);
    }
    return Response.ok(municipalityList).build();
}
Also used : Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) Unsecure(fi.otavanopisto.pyramus.rest.annotation.Unsecure)

Aggregations

Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)23 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)14 Nationality (fi.otavanopisto.pyramus.domainmodel.base.Nationality)14 MunicipalityDAO (fi.otavanopisto.pyramus.dao.base.MunicipalityDAO)13 StudyProgramme (fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme)13 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)13 Person (fi.otavanopisto.pyramus.domainmodel.base.Person)12 School (fi.otavanopisto.pyramus.domainmodel.base.School)12 StudentDAO (fi.otavanopisto.pyramus.dao.students.StudentDAO)10 StudentActivityType (fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType)10 StudentEducationalLevel (fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel)10 StudentExaminationType (fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType)10 StudentStudyEndReason (fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason)10 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)9 StudyProgrammeDAO (fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO)9 Curriculum (fi.otavanopisto.pyramus.domainmodel.base.Curriculum)9 LanguageDAO (fi.otavanopisto.pyramus.dao.base.LanguageDAO)8 NationalityDAO (fi.otavanopisto.pyramus.dao.base.NationalityDAO)8 StaffMemberDAO (fi.otavanopisto.pyramus.dao.users.StaffMemberDAO)7 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)7