Search in sources :

Example 1 with Address

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

the class StudentsService method addStudentAddress.

public void addStudentAddress(@WebParam(name = "studentId") Long studentId, @WebParam(name = "addressType") String addressType, @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) {
    StudentDAO studentDAO = DAOFactory.getInstance().getStudentDAO();
    AddressDAO addressDAO = DAOFactory.getInstance().getAddressDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    Student student = studentDAO.findById(studentId);
    // TODO contactType and default address
    ContactType contactType = contactTypeDAO.findById(new Long(1));
    Address address = addressDAO.create(student.getContactInfo(), contactType, name, streetAddress, postalCode, city, country, Boolean.TRUE);
    validateEntity(address);
}
Also used : StudentDAO(fi.otavanopisto.pyramus.dao.students.StudentDAO) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) Student(fi.otavanopisto.pyramus.domainmodel.students.Student) AddressDAO(fi.otavanopisto.pyramus.dao.base.AddressDAO)

Example 2 with Address

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

the class AddressDAO method create.

public Address create(ContactInfo contactInfo, ContactType contactType, String name, String streetAddress, String postalCode, String city, String country, Boolean defaultAddress) {
    EntityManager entityManager = getEntityManager();
    Address address = new Address();
    address.setContactInfo(contactInfo);
    address.setContactType(contactType);
    address.setName(name);
    address.setStreetAddress(streetAddress);
    address.setPostalCode(postalCode);
    address.setCity(city);
    address.setCountry(country);
    address.setDefaultAddress(defaultAddress);
    entityManager.persist(address);
    contactInfo.addAddress(address);
    entityManager.persist(contactInfo);
    return address;
}
Also used : EntityManager(javax.persistence.EntityManager) Address(fi.otavanopisto.pyramus.domainmodel.base.Address)

Example 3 with Address

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

the class EditSchoolViewController method process.

/**
 * Processes the page request by including the corresponding JSP page to the response.
 *
 * @param pageRequestContext Page request context
 */
public void process(PageRequestContext pageRequestContext) {
    SchoolDAO schoolDAO = DAOFactory.getInstance().getSchoolDAO();
    SchoolFieldDAO schoolFieldDAO = DAOFactory.getInstance().getSchoolFieldDAO();
    SchoolVariableDAO schoolVariableDAO = DAOFactory.getInstance().getSchoolVariableDAO();
    SchoolVariableKeyDAO schoolVariableKeyDAO = DAOFactory.getInstance().getSchoolVariableKeyDAO();
    ContactTypeDAO contactTypeDAO = DAOFactory.getInstance().getContactTypeDAO();
    ContactURLTypeDAO contactURLTypeDAO = DAOFactory.getInstance().getContactURLTypeDAO();
    Long schoolId = NumberUtils.createLong(pageRequestContext.getRequest().getParameter("school"));
    School school = schoolDAO.findById(schoolId);
    StringBuilder tagsBuilder = new StringBuilder();
    Iterator<Tag> tagIterator = school.getTags().iterator();
    while (tagIterator.hasNext()) {
        Tag tag = tagIterator.next();
        tagsBuilder.append(tag.getText());
        if (tagIterator.hasNext())
            tagsBuilder.append(' ');
    }
    List<ContactURLType> contactURLTypes = contactURLTypeDAO.listUnarchived();
    Collections.sort(contactURLTypes, new StringAttributeComparator("getName"));
    List<SchoolVariableKey> schoolUserEditableVariableKeys = schoolVariableKeyDAO.listUserEditableVariableKeys();
    Collections.sort(schoolUserEditableVariableKeys, new StringAttributeComparator("getVariableName"));
    List<ContactType> contactTypes = contactTypeDAO.listUnarchived();
    Collections.sort(contactTypes, new StringAttributeComparator("getName"));
    String jsonContactTypes = new JSONArrayExtractor("id", "name").extractString(contactTypes);
    List<Address> addresses = school.getContactInfo().getAddresses();
    JSONArray jsonAddresses = new JSONArrayExtractor("id", "defaultAddress", "name", "streetAddress", "postalCode", "city", "country").extract(addresses);
    for (int i = 0; i < jsonAddresses.size(); i++) {
        JSONObject jsonAddress = jsonAddresses.getJSONObject(i);
        if (addresses.get(i).getContactType() != null) {
            jsonAddress.put("contactTypeId", addresses.get(i).getContactType().getId());
        }
    }
    List<Email> emails = school.getContactInfo().getEmails();
    JSONArray jsonEmails = new JSONArrayExtractor("id", "defaultAddress", "address").extract(emails);
    for (int i = 0; i < jsonEmails.size(); i++) {
        JSONObject jsonEmail = jsonEmails.getJSONObject(i);
        if (emails.get(i).getContactType() != null) {
            jsonEmail.put("contactTypeId", emails.get(i).getContactType().getId());
        }
    }
    List<PhoneNumber> phoneNumbers = school.getContactInfo().getPhoneNumbers();
    JSONArray jsonPhoneNumbers = new JSONArrayExtractor("id", "defaultNumber", "number").extract(phoneNumbers);
    for (int i = 0; i < jsonPhoneNumbers.size(); i++) {
        JSONObject jsonPhoneNumber = jsonPhoneNumbers.getJSONObject(i);
        if (phoneNumbers.get(i).getContactType() != null) {
            jsonPhoneNumber.put("contactTypeId", phoneNumbers.get(i).getContactType().getId());
        }
    }
    JSONArray jsonVariableKeys = new JSONArrayExtractor("variableKey", "variableName", "variableType").extract(schoolUserEditableVariableKeys);
    for (int i = 0; i < jsonVariableKeys.size(); i++) {
        JSONObject jsonVariableKey = jsonVariableKeys.getJSONObject(i);
        String key = jsonVariableKey.getString("variableKey");
        String value = schoolVariableDAO.findValueBySchoolAndKey(school, key);
        if (value != null)
            jsonVariableKey.put("variableValue", value);
    }
    this.setJsDataVariable(pageRequestContext, "addresses", jsonAddresses.toString());
    this.setJsDataVariable(pageRequestContext, "emails", jsonEmails.toString());
    this.setJsDataVariable(pageRequestContext, "phoneNumbers", jsonPhoneNumbers.toString());
    this.setJsDataVariable(pageRequestContext, "contactTypes", jsonContactTypes);
    this.setJsDataVariable(pageRequestContext, "variableKeys", jsonVariableKeys.toString());
    pageRequestContext.getRequest().setAttribute("tags", tagsBuilder.toString());
    pageRequestContext.getRequest().setAttribute("school", school);
    pageRequestContext.getRequest().setAttribute("variableKeys", schoolUserEditableVariableKeys);
    pageRequestContext.getRequest().setAttribute("schoolFields", schoolFieldDAO.listUnarchived());
    pageRequestContext.setIncludeJSP("/templates/settings/editschool.jsp");
}
Also used : ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) Email(fi.otavanopisto.pyramus.domainmodel.base.Email) Address(fi.otavanopisto.pyramus.domainmodel.base.Address) SchoolVariableKeyDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableKeyDAO) StringAttributeComparator(fi.otavanopisto.pyramus.util.StringAttributeComparator) JSONArrayExtractor(fi.otavanopisto.pyramus.util.JSONArrayExtractor) ContactURLTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactURLTypeDAO) School(fi.otavanopisto.pyramus.domainmodel.base.School) SchoolDAO(fi.otavanopisto.pyramus.dao.base.SchoolDAO) ContactTypeDAO(fi.otavanopisto.pyramus.dao.base.ContactTypeDAO) SchoolVariableDAO(fi.otavanopisto.pyramus.dao.base.SchoolVariableDAO) JSONArray(net.sf.json.JSONArray) SchoolVariableKey(fi.otavanopisto.pyramus.domainmodel.base.SchoolVariableKey) ContactURLType(fi.otavanopisto.pyramus.domainmodel.base.ContactURLType) JSONObject(net.sf.json.JSONObject) SchoolFieldDAO(fi.otavanopisto.pyramus.dao.base.SchoolFieldDAO) PhoneNumber(fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber) Tag(fi.otavanopisto.pyramus.domainmodel.base.Tag)

Example 4 with Address

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

the class StaffRESTService method deleteStaffMemberAddress.

@Path("/members/{STAFFMEMBERID:[0-9]*}/addresses/{ID:[0-9]*}")
@DELETE
@RESTPermit(handling = Handling.INLINE)
public Response deleteStaffMemberAddress(@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.DELETE_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();
    }
    commonController.deleteAddress(address);
    return Response.noContent().build();
}
Also used : Address(fi.otavanopisto.pyramus.domainmodel.base.Address) StaffMember(fi.otavanopisto.pyramus.domainmodel.users.StaffMember) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RESTPermit(fi.otavanopisto.pyramus.rest.annotation.RESTPermit)

Example 5 with Address

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

the class StudentAddressRESTService method updateStudentAddress.

@Path("/{ID:[0-9]*}")
@PUT
@RESTPermit(handling = Handling.INLINE)
public Response updateStudentAddress(@PathParam("STUDENTID") Long studentId, @PathParam("ID") Long id, fi.otavanopisto.pyramus.rest.model.Address body) {
    Student student = studentController.findStudentById(studentId);
    Status studentStatus = checkStudent(student);
    if (studentStatus != Status.OK) {
        return Response.status(studentStatus).build();
    }
    if (!restSecurity.hasPermission(new String[] { StudentPermissions.UPDATE_STUDENTADDRESS }, student) && !restSecurity.hasPermission(new String[] { StudentPermissions.STUDENT_OWNER }, student)) {
        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(student.getContactInfo().getId())) {
        return Response.status(Status.NOT_FOUND).build();
    }
    ContactType contactType = commonController.findContactTypeById(body.getContactTypeId());
    address = studentController.updateStudentAddress(address, contactType, body.getDefaultAddress(), body.getName(), body.getStreetAddress(), body.getPostalCode(), body.getCity(), body.getCountry());
    return Response.ok(objectFactory.createModel(address)).build();
}
Also used : Status(javax.ws.rs.core.Response.Status) ContactType(fi.otavanopisto.pyramus.domainmodel.base.ContactType) 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) PUT(javax.ws.rs.PUT)

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