001
014
015 package com.liferay.portlet.usersadmin.action;
016
017 import com.liferay.portal.NoSuchListTypeException;
018 import com.liferay.portal.NoSuchOrgLaborException;
019 import com.liferay.portal.kernel.servlet.SessionErrors;
020 import com.liferay.portal.kernel.util.Constants;
021 import com.liferay.portal.kernel.util.ParamUtil;
022 import com.liferay.portal.security.auth.PrincipalException;
023 import com.liferay.portal.service.OrgLaborServiceUtil;
024 import com.liferay.portal.struts.PortletAction;
025
026 import javax.portlet.ActionRequest;
027 import javax.portlet.ActionResponse;
028 import javax.portlet.PortletConfig;
029 import javax.portlet.RenderRequest;
030 import javax.portlet.RenderResponse;
031
032 import org.apache.struts.action.ActionForm;
033 import org.apache.struts.action.ActionForward;
034 import org.apache.struts.action.ActionMapping;
035
036
039 public class EditOrgLaborAction extends PortletAction {
040
041 @Override
042 public void processAction(
043 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
044 ActionRequest actionRequest, ActionResponse actionResponse)
045 throws Exception {
046
047 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
048
049 try {
050 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
051 updateOrgLabor(actionRequest);
052 }
053 else if (cmd.equals(Constants.DELETE)) {
054 deleteOrgLabor(actionRequest);
055 }
056
057 sendRedirect(actionRequest, actionResponse);
058 }
059 catch (Exception e) {
060 if (e instanceof NoSuchOrgLaborException ||
061 e instanceof PrincipalException) {
062
063 SessionErrors.add(actionRequest, e.getClass().getName());
064
065 setForward(actionRequest, "portlet.users_admin.error");
066 }
067 else if (e instanceof NoSuchListTypeException) {
068 SessionErrors.add(actionRequest, e.getClass().getName());
069 }
070 else {
071 throw e;
072 }
073 }
074 }
075
076 @Override
077 public ActionForward render(
078 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
079 RenderRequest renderRequest, RenderResponse renderResponse)
080 throws Exception {
081
082 try {
083 ActionUtil.getOrgLabor(renderRequest);
084 }
085 catch (Exception e) {
086 if (e instanceof NoSuchOrgLaborException ||
087 e instanceof PrincipalException) {
088
089 SessionErrors.add(renderRequest, e.getClass().getName());
090
091 return mapping.findForward("portlet.users_admin.error");
092 }
093 else {
094 throw e;
095 }
096 }
097
098 return mapping.findForward(getForward(
099 renderRequest, "portlet.users_admin.edit_org_labor"));
100 }
101
102 protected void deleteOrgLabor(ActionRequest actionRequest)
103 throws Exception {
104
105 long orgLaborId = ParamUtil.getLong(actionRequest, "orgLaborId");
106
107 OrgLaborServiceUtil.deleteOrgLabor(orgLaborId);
108 }
109
110 protected void updateOrgLabor(ActionRequest actionRequest)
111 throws Exception {
112
113 long orgLaborId = ParamUtil.getLong(actionRequest, "orgLaborId");
114
115 long organizationId = ParamUtil.getLong(
116 actionRequest, "organizationId");
117 int typeId = ParamUtil.getInteger(actionRequest, "typeId");
118
119 int sunOpen = ParamUtil.getInteger(actionRequest, "sunOpen");
120 int sunClose = ParamUtil.getInteger(actionRequest, "sunClose");
121
122 int monOpen = ParamUtil.getInteger(actionRequest, "monOpen");
123 int monClose = ParamUtil.getInteger(actionRequest, "monClose");
124
125 int tueOpen = ParamUtil.getInteger(actionRequest, "tueOpen");
126 int tueClose = ParamUtil.getInteger(actionRequest, "tueClose");
127
128 int wedOpen = ParamUtil.getInteger(actionRequest, "wedOpen");
129 int wedClose = ParamUtil.getInteger(actionRequest, "wedClose");
130
131 int thuOpen = ParamUtil.getInteger(actionRequest, "thuOpen");
132 int thuClose = ParamUtil.getInteger(actionRequest, "thuClose");
133
134 int friOpen = ParamUtil.getInteger(actionRequest, "friOpen");
135 int friClose = ParamUtil.getInteger(actionRequest, "friClose");
136
137 int satOpen = ParamUtil.getInteger(actionRequest, "satOpen");
138 int satClose = ParamUtil.getInteger(actionRequest, "satClose");
139
140 if (orgLaborId <= 0) {
141
142
143
144 OrgLaborServiceUtil.addOrgLabor(
145 organizationId, typeId, sunOpen, sunClose, monOpen, monClose,
146 tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose,
147 friOpen, friClose, satOpen, satClose);
148 }
149 else {
150
151
152
153 OrgLaborServiceUtil.updateOrgLabor(
154 orgLaborId, typeId, sunOpen, sunClose, monOpen, monClose,
155 tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose,
156 friOpen, friClose, satOpen, satClose);
157 }
158 }
159
160 }