Search in sources :

Example 16 with Municipality

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

the class StudentRESTService method updateMunicipality.

@Path("/municipalities/{ID:[0-9]*}")
@PUT
@RESTPermit(MunicipalityPermissions.UPDATE_MUNICIPALITY)
public Response updateMunicipality(@PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.Municipality entity) {
    Municipality municipality = municipalityController.findMunicipalityById(id);
    if (municipality == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    if (municipality.getArchived()) {
        return Response.status(Status.NOT_FOUND).build();
    }
    String name = entity.getName();
    String code = entity.getCode();
    if (StringUtils.isBlank(name) || StringUtils.isBlank(code)) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    return Response.ok().entity(objectFactory.createModel(municipalityController.updateMunicipality(municipality, name, code))).build();
}
Also used : Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) PUT(javax.ws.rs.PUT)

Example 17 with Municipality

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

the class BaseService method listMunicipalities.

public MunicipalityEntity[] listMunicipalities() {
    MunicipalityDAO municipalityDAO = DAOFactory.getInstance().getMunicipalityDAO();
    List<Municipality> municipalities = municipalityDAO.listUnarchived();
    Collections.sort(municipalities, new StringAttributeComparator("getName"));
    return (MunicipalityEntity[]) EntityFactoryVault.buildFromDomainObjects(municipalities);
}
Also used : Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) MunicipalityDAO(fi.otavanopisto.pyramus.dao.base.MunicipalityDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator)

Example 18 with Municipality

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

the class StudentsService method addStudyProgramme.

public StudentEntity addStudyProgramme(@WebParam(name = "studentId") Long studentId, @WebParam(name = "studyProgrammeId") Long studyProgrammeId) {
    // TODO Generalize to StudentDAO (also used in CopyStudentStudyProgrammeJSONRequestController)
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    StudyProgrammeDAO studyProgrammeDAO = DAOFactory.getInstance().getStudyProgrammeDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    ContactInfoDAO contactInfoDAO = DAOFactory.getInstance().getContactInfoDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    PhoneNumberDAO phoneNumberDAO = DAOFactory.getInstance().getPhoneNumberDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    Student oldStudent = studentDAO.findById(studentId);
    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();
    StudyProgramme studyProgramme = studyProgrammeId == null ? null : studyProgrammeDAO.findById(studyProgrammeId);
    // 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);
    // Contact info
    contactInfoDAO.update(newStudent.getContactInfo(), oldStudent.getContactInfo().getAdditionalInfo());
    // Default user
    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());
    }
    // E-mail 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());
    }
    return EntityFactoryVault.buildFromDomainObject(newStudent);
}
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) 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) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) StudyProgrammeDAO(fi.otavanopisto.pyramus.dao.base.StudyProgrammeDAO) Date(java.util.Date) 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) Curriculum(fi.otavanopisto.pyramus.domainmodel.base.Curriculum) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

Example 19 with Municipality

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

the class MunicipalityDAO method create.

public Municipality create(String name, String code) {
    EntityManager entityManager = getEntityManager();
    Municipality municipality = new Municipality();
    municipality.setName(name);
    municipality.setCode(code);
    entityManager.persist(municipality);
    return municipality;
}
Also used : EntityManager(javax.persistence.EntityManager) Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality)

Example 20 with Municipality

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

the class StudentAPI method create.

public Long create(Long personId, String firstName, String lastName, String email, Long emailContactTypeId, String nickname, String additionalInfo, Date studyTimeEnd, Long activityType, Long examinationType, Long educationalLevel, String education, Long nationality, Long municipality, Long language, Long schoolId, Long studyProgrammeId, Double previousStudies, Date studyStartDate, Date studyEndDate, Long studyEndReasonId, String studyEndText, boolean lodging) throws InvalidScriptException {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    EmailDAO emailDAO = DAOFactory.getInstance().getEmailDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    PersonDAO personDAO = DAOFactory.getInstance().getPersonDAO();
    StudentLodgingPeriodDAO studentLodgingPeriodDAO = DAOFactory.getInstance().getStudentLodgingPeriodDAO();
    UserVariableDAO userVariableDAO = DAOFactory.getInstance().getUserVariableDAO();
    email = email != null ? email.trim() : null;
    Person personEntity = null;
    if (personId != null) {
        personEntity = personDAO.findById(personId);
    }
    StudentActivityType activityTypeEntity = null;
    if (activityType != null) {
        activityTypeEntity = DAOFactory.getInstance().getStudentActivityTypeDAO().findById(activityType);
    }
    StudentExaminationType examinationTypeEntity = null;
    if (examinationType != null) {
        examinationTypeEntity = DAOFactory.getInstance().getStudentExaminationTypeDAO().findById(examinationType);
    }
    StudentEducationalLevel educationalLevelEntity = null;
    if (educationalLevel != null) {
        educationalLevelEntity = DAOFactory.getInstance().getStudentEducationalLevelDAO().findById(educationalLevel);
    }
    Nationality nationalityEntity = null;
    if (nationality != null) {
        nationalityEntity = DAOFactory.getInstance().getNationalityDAO().findById(nationality);
    }
    Municipality municipalityEntity = null;
    if (municipality != null) {
        municipalityEntity = DAOFactory.getInstance().getMunicipalityDAO().findById(municipality);
    }
    Language languageEntity = null;
    if (language != null) {
        languageEntity = DAOFactory.getInstance().getLanguageDAO().findById(language);
    }
    School school = null;
    if (schoolId != null) {
        school = DAOFactory.getInstance().getSchoolDAO().findById(schoolId);
    }
    StudyProgramme studyProgramme = null;
    if (studyProgrammeId != null) {
        studyProgramme = DAOFactory.getInstance().getStudyProgrammeDAO().findById(studyProgrammeId);
    }
    StudentStudyEndReason studyEndReason = null;
    if (studyEndReasonId != null) {
        studyEndReason = DAOFactory.getInstance().getStudentStudyEndReasonDAO().findById(studyEndReasonId);
    }
    firstName = StringUtils.trim(firstName);
    lastName = StringUtils.trim(lastName);
    nickname = StringUtils.trim(nickname);
    Student student = studentDAO.create(personEntity, firstName, lastName, nickname, additionalInfo, studyTimeEnd, activityTypeEntity, examinationTypeEntity, educationalLevelEntity, education, nationalityEntity, municipalityEntity, languageEntity, school, studyProgramme, null, previousStudies, studyStartDate, studyEndDate, studyEndReason, studyEndText, false);
    userVariableDAO.createDefaultValueVariables(student);
    if (lodging && studyStartDate != null)
        studentLodgingPeriodDAO.create(student, studyStartDate, studyEndDate);
    if (personEntity.getDefaultUser() == null) {
        personDAO.updateDefaultUser(personEntity, student);
    }
    if (StringUtils.isNotBlank(email)) {
        ContactType emailContactType = contactTypeDAO.findById(emailContactTypeId);
        if (emailContactType == null) {
            throw new InvalidScriptException("Could not find contact type for email");
        }
        emailDAO.create(student.getContactInfo(), emailContactType, true, email);
    }
    return student.getId();
}
Also used : Municipality(fi.otavanopisto.pyramus.domainmodel.base.Municipality) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) StudyProgramme(fi.otavanopisto.pyramus.domainmodel.base.StudyProgramme) InvalidScriptException(fi.otavanopisto.pyramus.util.dataimport.scripting.InvalidScriptException) StudentExaminationType(fi.otavanopisto.pyramus.domainmodel.students.StudentExaminationType) StudentStudyEndReason(fi.otavanopisto.pyramus.domainmodel.students.StudentStudyEndReason) StudentEducationalLevel(fi.otavanopisto.pyramus.domainmodel.students.StudentEducationalLevel) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) EmailDAO(fi.otavanopisto.pyramus.dao.base.EmailDAO) StudentLodgingPeriodDAO(fi.otavanopisto.pyramus.dao.students.StudentLodgingPeriodDAO) Nationality(fi.otavanopisto.pyramus.domainmodel.base.Nationality) StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) PersonDAO(fi.otavanopisto.pyramus.dao.base.PersonDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) Language(fi.otavanopisto.pyramus.domainmodel.base.Language) UserVariableDAO(fi.otavanopisto.pyramus.dao.users.UserVariableDAO) StudentActivityType(fi.otavanopisto.pyramus.domainmodel.students.StudentActivityType) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) Person(fi.otavanopisto.pyramus.domainmodel.base.Person)

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