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();
}
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);
}
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);
}
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;
}
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();
}
Aggregations