use of fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber 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");
}
use of fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber in project pyramus by otavanopisto.
the class StudentPhoneNumberRESTService method listStudentPhoneNumbers.
@Path("/")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listStudentPhoneNumbers(@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_STUDENTPHONENUMBERS }, student) && !restSecurity.hasPermission(new String[] { PersonPermissions.PERSON_OWNER }, student.getPerson())) {
return Response.status(Status.FORBIDDEN).build();
}
List<PhoneNumber> phoneNumbers = student.getContactInfo().getPhoneNumbers();
if (phoneNumbers.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(objectFactory.createModel(phoneNumbers)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber in project pyramus by otavanopisto.
the class StudentPhoneNumberRESTService method deleteStudentPhoneNumber.
@Path("/{ID:[0-9]*}")
@DELETE
@RESTPermit(StudentPermissions.DELETE_STUDENTPHONENUMBER)
public Response deleteStudentPhoneNumber(@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();
}
PhoneNumber phoneNumber = commonController.findPhoneNumberById(id);
if (phoneNumber == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!phoneNumber.getContactInfo().getId().equals(student.getContactInfo().getId())) {
return Response.status(Status.NOT_FOUND).build();
}
commonController.deletePhoneNumber(phoneNumber);
return Response.noContent().build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber in project pyramus by otavanopisto.
the class StaffRESTService method listStaffMemberPhoneNumbers.
@Path("/members/{STAFFMEMBERID:[0-9]*}/phoneNumbers")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response listStaffMemberPhoneNumbers(@PathParam("STAFFMEMBERID") Long staffMemberId) {
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.LIST_STAFFMEMBERPHONENUMBERS }, staffMember) && !restSecurity.hasPermission(new String[] { PersonPermissions.PERSON_OWNER }, staffMember.getPerson())) {
return Response.status(Status.FORBIDDEN).build();
}
List<PhoneNumber> phoneNumbers = staffMember.getContactInfo().getPhoneNumbers();
if (phoneNumbers.isEmpty()) {
return Response.noContent().build();
}
return Response.ok(objectFactory.createModel(phoneNumbers)).build();
}
use of fi.otavanopisto.pyramus.domainmodel.base.PhoneNumber in project pyramus by otavanopisto.
the class StaffRESTService method findStaffMemberPhoneNumber.
@Path("/members/{STAFFMEMBERID:[0-9]*}/phoneNumbers/{ID:[0-9]*}")
@GET
@RESTPermit(handling = Handling.INLINE)
public Response findStaffMemberPhoneNumber(@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_STAFFMEMBERPHONENUMBER }, staffMember) && !restSecurity.hasPermission(new String[] { PersonPermissions.PERSON_OWNER }, staffMember.getPerson())) {
return Response.status(Status.FORBIDDEN).build();
}
PhoneNumber phoneNumber = commonController.findPhoneNumberById(id);
if (phoneNumber == null) {
return Response.status(Status.NOT_FOUND).build();
}
if (!phoneNumber.getContactInfo().getId().equals(staffMember.getContactInfo().getId())) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(objectFactory.createModel(phoneNumber)).build();
}
Aggregations