Search in sources :

Example 16 with Address

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();
}
Also used : Address(fi.otavanopisto.pyramus.domainmodel.base.Address) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 17 with Address

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();
}
Also used : Status(javax.ws.rs.core.Response.Status) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Path(javax.ws.rs.Path) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit) GET(javax.ws.rs.GET)

Example 18 with Address

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();
}
Also used : Status(javax.ws.rs.core.Response.Status) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit)

Example 19 with Address

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);
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO)

Example 20 with Address

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

Aggregations

Address (fi.otavanopisto.pyramus.domainmodel.base.Address)22 School (fi.otavanopisto.pyramus.domainmodel.base.School)10 Student (fi.otavanopisto.pyramus.domainmodel.students.Student)10 RESTPermit (fi.otavanopisto.pyramus.rest.annotation.RESTPermit)10 Path (javax.ws.rs.Path)10 Email (fi.otavanopisto.pyramus.domainmodel.base.Email)9 PhoneNumber (fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber)9 ContactType (fi.otavanopisto.pyramus.domainmodel.base.ContactType)8 AddressDAO (fi.otavanopisto.pyramus.dao.base.AddressDAO)7 Tag (fi.otavanopisto.pyramus.domainmodel.base.Tag)7 StaffMember (fi.otavanopisto.pyramus.domainmodel.users.StaffMember)7 ContactTypeDAO (fi.otavanopisto.pyramus.dao.base.ContactTypeDAO)6 GET (javax.ws.rs.GET)6 EmailDAO (fi.otavanopisto.pyramus.dao.base.EmailDAO)5 PhoneNumberDAO (fi.otavanopisto.pyramus.dao.base.PhoneNumberDAO)5 PersonDAO (fi.otavanopisto.pyramus.dao.base.PersonDAO)4 SchoolDAO (fi.otavanopisto.pyramus.dao.base.SchoolDAO)4 Language (fi.otavanopisto.pyramus.domainmodel.base.Language)4 Municipality (fi.otavanopisto.pyramus.domainmodel.base.Municipality)4 Nationality (fi.otavanopisto.pyramus.domainmodel.base.Nationality)4