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.dataTransferObject.person.MacAddressRegistryBean; import net.sourceforge.fenixedu.domain.MacAddress; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.presentationTier.Action.base.FenixDispatchAction; import net.sourceforge.fenixedu.presentationTier.Action.resourceAllocationManager.utils.ServiceUtils; 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; @ISCTE(author = "Paulo Zenida") public class MacAddressRegistryDA extends FenixDispatchAction { public ActionForward prepare(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Integer integerFromRequest = getIntegerFromRequest(request, "personID"); final Person person = (Person) rootDomainObject.readPartyByOID(integerFromRequest); request.setAttribute("person", person); return mapping.findForward("prepare"); } public ActionForward prepareAdd(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { final Person person = (Person) rootDomainObject.readPartyByOID(getIntegerFromRequest(request, "personID")); RenderUtils.invalidateViewState(); final MacAddressRegistryBean bean = new MacAddressRegistryBean(person); request.setAttribute("macAddressRegistry", bean); return prepare(mapping, form, request, response); } public ActionForward prepareEdit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { final MacAddress macAddress = rootDomainObject.readMacAddressByOID(getIntegerFromRequest(request, "macAddressId")); RenderUtils.invalidateViewState(); final MacAddressRegistryBean bean = new MacAddressRegistryBean(macAddress); request.setAttribute("macAddressRegistry", bean); return prepare(mapping, form, request, response); } public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixFilterException, FenixServiceException { final MacAddressRegistryBean bean = (MacAddressRegistryBean) RenderUtils.getViewState("macAddressRegistryBean") .getMetaObject().getObject(); request.setAttribute("personID", bean.getPerson().getIdInternal()); try { ServiceUtils.executeService( "CreateMacAddressRegistry", bean); } catch (DomainException e) { addActionMessage("error", request, e.getMessage()); request.setAttribute("macAddressRegistry", bean); return prepare(mapping, form, request, response); } RenderUtils.invalidateViewState(); return prepare(mapping, form, request, response); } public ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixFilterException, FenixServiceException { final MacAddressRegistryBean bean = (MacAddressRegistryBean) RenderUtils.getViewState("macAddressRegistryBean") .getMetaObject().getObject(); request.setAttribute("personID", bean.getPerson().getIdInternal()); try { ServiceUtils.executeService( "EditMacAddressRegistry", bean.getMacAddress(), bean); } catch (DomainException e) { addActionMessage("error", request, e.getMessage()); request.setAttribute("macAddressRegistry", bean); return prepare(mapping, form, request, response); } RenderUtils.invalidateViewState(); addActionMessage("success", request, "label.generic.success"); return prepare(mapping, form, request, response); } public ActionForward activate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixFilterException, FenixServiceException { final MacAddress macAddress = rootDomainObject.readMacAddressByOID(getIntegerFromRequest(request, "macAddressId")); request.setAttribute("personID", macAddress.getPerson().getIdInternal()); ServiceUtils.executeService( "ActivateMacAddressRegistry", macAddress); RenderUtils.invalidateViewState(); addActionMessage("success", request, "label.generic.success"); return prepare(mapping, form, request, response); } public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixFilterException, FenixServiceException { final MacAddress macAddress = rootDomainObject.readMacAddressByOID(getIntegerFromRequest(request, "macAddressId")); request.setAttribute("personID", macAddress.getPerson().getIdInternal()); ServiceUtils.executeService( "RemoveMacAddressRegistry", macAddress); RenderUtils.invalidateViewState(); return prepare(mapping, form, request, response); } }