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