1
22
23 package com.liferay.portlet.enterpriseadmin.action;
24
25 import com.liferay.portal.NoSuchListTypeException;
26 import com.liferay.portal.NoSuchOrgLaborException;
27 import com.liferay.portal.kernel.servlet.SessionErrors;
28 import com.liferay.portal.kernel.util.Constants;
29 import com.liferay.portal.kernel.util.ParamUtil;
30 import com.liferay.portal.security.auth.PrincipalException;
31 import com.liferay.portal.service.OrgLaborServiceUtil;
32 import com.liferay.portal.struts.PortletAction;
33
34 import javax.portlet.ActionRequest;
35 import javax.portlet.ActionResponse;
36 import javax.portlet.PortletConfig;
37 import javax.portlet.RenderRequest;
38 import javax.portlet.RenderResponse;
39
40 import org.apache.struts.action.ActionForm;
41 import org.apache.struts.action.ActionForward;
42 import org.apache.struts.action.ActionMapping;
43
44
49 public class EditOrgLaborAction extends PortletAction {
50
51 public void processAction(
52 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
53 ActionRequest actionRequest, ActionResponse actionResponse)
54 throws Exception {
55
56 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
57
58 try {
59 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
60 updateOrgLabor(actionRequest);
61 }
62 else if (cmd.equals(Constants.DELETE)) {
63 deleteOrgLabor(actionRequest);
64 }
65
66 sendRedirect(actionRequest, actionResponse);
67 }
68 catch (Exception e) {
69 if (e instanceof NoSuchOrgLaborException ||
70 e instanceof PrincipalException) {
71
72 SessionErrors.add(actionRequest, e.getClass().getName());
73
74 setForward(actionRequest, "portlet.enterprise_admin.error");
75 }
76 else if (e instanceof NoSuchListTypeException) {
77 SessionErrors.add(actionRequest, e.getClass().getName());
78 }
79 else {
80 throw e;
81 }
82 }
83 }
84
85 public ActionForward render(
86 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
87 RenderRequest renderRequest, RenderResponse renderResponse)
88 throws Exception {
89
90 try {
91 ActionUtil.getOrgLabor(renderRequest);
92 }
93 catch (Exception e) {
94 if (e instanceof NoSuchOrgLaborException ||
95 e instanceof PrincipalException) {
96
97 SessionErrors.add(renderRequest, e.getClass().getName());
98
99 return mapping.findForward("portlet.enterprise_admin.error");
100 }
101 else {
102 throw e;
103 }
104 }
105
106 return mapping.findForward(getForward(
107 renderRequest, "portlet.enterprise_admin.edit_org_labor"));
108 }
109
110 protected void deleteOrgLabor(ActionRequest actionRequest)
111 throws Exception {
112
113 long orgLaborId = ParamUtil.getLong(actionRequest, "orgLaborId");
114
115 OrgLaborServiceUtil.deleteOrgLabor(orgLaborId);
116 }
117
118 protected void updateOrgLabor(ActionRequest actionRequest)
119 throws Exception {
120
121 long orgLaborId = ParamUtil.getLong(actionRequest, "orgLaborId");
122
123 long organizationId = ParamUtil.getLong(
124 actionRequest, "organizationId");
125 int typeId = ParamUtil.getInteger(actionRequest, "typeId");
126
127 int sunOpen = ParamUtil.getInteger(actionRequest, "sunOpen");
128 int sunClose = ParamUtil.getInteger(actionRequest, "sunClose");
129
130 int monOpen = ParamUtil.getInteger(actionRequest, "monOpen");
131 int monClose = ParamUtil.getInteger(actionRequest, "monClose");
132
133 int tueOpen = ParamUtil.getInteger(actionRequest, "tueOpen");
134 int tueClose = ParamUtil.getInteger(actionRequest, "tueClose");
135
136 int wedOpen = ParamUtil.getInteger(actionRequest, "wedOpen");
137 int wedClose = ParamUtil.getInteger(actionRequest, "wedClose");
138
139 int thuOpen = ParamUtil.getInteger(actionRequest, "thuOpen");
140 int thuClose = ParamUtil.getInteger(actionRequest, "thuClose");
141
142 int friOpen = ParamUtil.getInteger(actionRequest, "friOpen");
143 int friClose = ParamUtil.getInteger(actionRequest, "friClose");
144
145 int satOpen = ParamUtil.getInteger(actionRequest, "satOpen");
146 int satClose = ParamUtil.getInteger(actionRequest, "satClose");
147
148 if (orgLaborId <= 0) {
149
150
152 OrgLaborServiceUtil.addOrgLabor(
153 organizationId, typeId, sunOpen, sunClose, monOpen, monClose,
154 tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose,
155 friOpen, friClose, satOpen, satClose);
156 }
157 else {
158
159
161 OrgLaborServiceUtil.updateOrgLabor(
162 orgLaborId, typeId, sunOpen, sunClose, monOpen, monClose,
163 tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose,
164 friOpen, friClose, satOpen, satClose);
165 }
166 }
167
168 }