package net.sourceforge.fenixedu.presentationTier.Action.person; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sourceforge.fenixedu.applicationTier.Filtro.exception.FenixFilterException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.FenixServiceException; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.contacts.EmailAddress; import net.sourceforge.fenixedu.domain.contacts.MobilePhone; import net.sourceforge.fenixedu.domain.contacts.PartyContact; import net.sourceforge.fenixedu.domain.contacts.Phone; import net.sourceforge.fenixedu.domain.contacts.PhysicalAddress; import net.sourceforge.fenixedu.domain.contacts.PhysicalDeliveryOfficeContact; import net.sourceforge.fenixedu.domain.contacts.PostBoxContact; import net.sourceforge.fenixedu.domain.contacts.WebAddress; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.injectionCode.AccessControl; import net.sourceforge.fenixedu.presentationTier.Action.base.FenixDispatchAction; import net.sourceforge.fenixedu.tools.enrollment.VerifyINDEGStudents; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import pt.iscte.ci.metadata.ISCTE; import pt.ist.fenixWebFramework.renderers.utils.RenderUtils; public class PartyContactsManagementDispatchAction extends FenixDispatchAction { @ISCTE(author="pmmsa") public ActionForward prepareCreatePhysicalAddress(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { Person person = getPerson(request); request.setAttribute("physicalAddressBean", new PhysicalAddressBean(person)); return mapping.findForward("createPhysicalAddress"); } @ISCTE(author="pmmsa") public ActionForward createPhysicalAddress(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { PhysicalAddressBean physicalAddressBean = (PhysicalAddressBean) getRenderedObject("physicalAddressBean"); try { PhysicalAddress.create(physicalAddressBean); } catch (DomainException ex) { addActionMessage(request, ex.getKey(), ex.getArgs()); request.setAttribute("physicalAddressBean", physicalAddressBean); return mapping.findForward("createPhysicalAddress"); } return backToShowInformation(mapping, actionForm, request, response); } @ISCTE(author="pmmsa") public ActionForward chooseCountryOfResidencePostBack(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { PhysicalAddressBean physicalAddressBean = (PhysicalAddressBean) getRenderedObject("physicalAddressBean"); request.setAttribute("physicalAddressBean", physicalAddressBean); request.setAttribute("student", getPerson(request).getStudent()); RenderUtils.invalidateViewState("physicalAddressBean"); return mapping.findForward(request.getParameter("forward").toString()); } public ActionForward prepareCreatePhone(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return prepareCreatePartyContact(mapping, actionForm, request, response, Phone.class); } public ActionForward prepareCreateMobilePhone(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return prepareCreatePartyContact(mapping, actionForm, request, response, MobilePhone.class); } public ActionForward prepareCreateEmailAddress(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return prepareCreatePartyContact(mapping, actionForm, request, response, EmailAddress.class); } public ActionForward prepareCreateWebAddress(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return prepareCreatePartyContact(mapping, actionForm, request, response, WebAddress.class); } public ActionForward prepareCreatePostBox(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return prepareCreatePartyContact(mapping, actionForm, request, response, PostBoxContact.class); } public ActionForward prepareCreatePhysicalDeliveryOfficeContact(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return prepareCreatePartyContact(mapping, actionForm, request, response, PhysicalDeliveryOfficeContact.class); } private ActionForward prepareCreatePartyContact(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response, Class clazz) { request.setAttribute("person", getPerson(request)); request.setAttribute("partyContactName", clazz.getSimpleName()); return mapping.findForward("createPartyContact"); } public ActionForward createPartyContact(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return backToShowInformation(mapping, actionForm, request, response); } public ActionForward prepareEditPartyContact(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { Person person = getPerson(request); if (person.getStudent() != null && VerifyINDEGStudents.IsIndegStudent(person.getStudent())) { return mapping.findForward("showIndegStudentsMessage"); } else { request.setAttribute("person", person); request.setAttribute("partyContact", getPartyContact(person, request)); return mapping.findForward("editPartyContact"); } } @ISCTE(author="pmmsa") public ActionForward prepareEditPhysicalAddress(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { Person person = getPerson(request); if (person.getStudent() != null && VerifyINDEGStudents.IsIndegStudent(person.getStudent())) { return mapping.findForward("showIndegStudentsMessage"); } else { request.setAttribute("person", person); request.setAttribute("physicalAddressBean", new PhysicalAddressBean(getPhysicalAddress(person, request))); return mapping.findForward("editPhysicalAddress"); } } @ISCTE(author="pmmsa") public ActionForward editPhysicalAddress(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { PhysicalAddressBean physicalAddressBean = (PhysicalAddressBean) getRenderedObject("physicalAddressBean"); PhysicalAddress physicalAddress = physicalAddressBean.getPhysicalAddress(); try { physicalAddress.edit(physicalAddressBean); } catch (DomainException ex) { addActionMessage(request, ex.getKey(), ex.getArgs()); request.setAttribute("physicalAddressBean", physicalAddressBean); return mapping.findForward("editPhysicalAddress"); } return backToShowInformation(mapping, actionForm, request, response); } protected PartyContact getPartyContact(final Person person, final HttpServletRequest request) { final Integer contactId = getIntegerFromRequest(request, "contactId"); for (final PartyContact contact : person.getPartyContacts()) { if (contact.getIdInternal().equals(contactId)) { return contact; } } return null; } protected PhysicalAddress getPhysicalAddress(final Person person, final HttpServletRequest request) { final Integer contactId = getIntegerFromRequest(request, "contactId"); for (final PhysicalAddress physicalAddress : person.getPhysicalAddresses()) { if (physicalAddress.getIdInternal().equals(contactId)) { return physicalAddress; } } return null; } public ActionForward editPartyContact(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { return backToShowInformation(mapping, actionForm, request, response); } public ActionForward deletePartyContact(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws FenixFilterException, FenixServiceException { try { executeService("DeletePartyContact", new Object[] { getPartyContact(getPerson(request), request) }); } catch (DomainException e) { addActionMessage("contacts", request, e.getMessage(), e.getArgs()); } return backToShowInformation(mapping, actionForm, request, response); } protected Person getPerson(final HttpServletRequest request) { return AccessControl.getPerson(); } public ActionForward backToShowInformation(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) { Person person = getPerson(request); if (person.getStudent() != null && VerifyINDEGStudents.IsIndegStudent(person.getStudent())) { return mapping.findForward("showIndegStudentsMessage"); } return mapping.findForward("visualizePersonalInformation"); } }