use of fi.otavanopisto.pyramus.domainmodel.base.Address in project pyramus by otavanopisto.
the class StaffRESTService method findStaffMemberAddress.
@Path("/members/{STAFFMEMBERID:[0-9]*}/addresses/{ID:[0-9]*}")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response findStaffMemberAddress(@PathParam("STAFFMEMBERID") Long staffMemberId, @PathParam("ID") Long id) {
StaffMember staffMember = userController.findStaffMemberById(staffMemberId);
if (staffMember == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (staffMember.getArchived()) {
return Response.status(Status.NOT_FOUND).build();
}
if (!restSecurity.hasPermission(new String[] { UserPermissions.FIND_STAFFMEMBERADDRESS }, staffMember) && !restSecurity.hasPermission(new String[] { PersonPermissions.PERSON_OWNER }, staffMember.getPerson())) {
return Response.status(Status.FORBIDDEN).build();
}
Address address = commonController.findAddressById(id);
if (address == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!address.getContactInfo().getId().equals(staffMember.getContactInfo().getId())) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(objectFactory.createModel(address)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.Address in project pyramus by otavanopisto.
the class StudentAddressRESTService method listStudentAddresses.
@Path("/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listStudentAddresses(@PathParam("STUDENTID") Long studentId) {
Student student = studentController.findStudentById(studentId);
Status studentStatus = checkStudent(student);
if (studentStatus != Status.OK) {
return Response.status(studentStatus).build();
}
if (!restSecurity.hasPermission(new String[] { StudentPermissions.LIST_STUDENTADDRESSS }, student) && !restSecurity.hasPermission(new String[] { PersonPermissions.PERSON_OWNER }, student.getPerson())) {
return Response.status(Status.FORBIDDEN).build();
}
List<Address> addresses = student.getContactInfo().getAddresses();
if (addresses.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(objectFactory.createModel(addresses)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.Address in project pyramus by otavanopisto.
the class StudentAddressRESTService method deleteStudentAddress.
@Path("/{ID:[0-9]*}")
@DELETE
@RESTPermit(StudentPermissions.DELETE_STUDENTADDRESS)
public Response deleteStudentAddress(@PathParam("STUDENTID") Long studentId, @PathParam("ID") Long id) {
Student student = studentController.findStudentById(studentId);
Status studentStatus = checkStudent(student);
if (studentStatus != Status.OK) {
return Response.status(studentStatus).build();
}
Address address = commonController.findAddressById(id);
if (address == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!address.getContactInfo().getId().equals(student.getContactInfo().getId())) {
return Response.status(Status.NOT_FOUND).build();
}
commonController.deleteAddress(address);
return Response.noContent().build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.Address in project pyramus by otavanopisto.
the class BaseService method updateAddress.
public void updateAddress(@WebParam(name = "addressId") Long addressId, @WebParam(name = "defaultAddress") Boolean defaultAddress, @WebParam(name = "contactTypeId") Long contactTypeId, @WebParam(name = "name") String name, @WebParam(name = "streetAddress") String streetAddress, @WebParam(name = "postalCode") String postalCode, @WebParam(name = "city") String city, @WebParam(name = "country") String country) {
AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
Address address = addressDAO.findById(addressId);
ContactType contactType = contactTypeDAO.findById(contactTypeId);
addressDAO.update(address, defaultAddress, contactType, name, streetAddress, postalCode, city, country);
}
use of fi.otavanopisto.pyramus.domainmodel.base.Address 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);
}
Aggregations