1
14
15 package com.liferay.portlet.enterpriseadmin.action;
16
17 import com.liferay.portal.NoSuchListTypeException;
18 import com.liferay.portal.NoSuchOrgLaborException;
19 import com.liferay.portal.kernel.servlet.SessionErrors;
20 import com.liferay.portal.kernel.util.Constants;
21 import com.liferay.portal.kernel.util.ParamUtil;
22 import com.liferay.portal.security.auth.PrincipalException;
23 import com.liferay.portal.service.OrgLaborServiceUtil;
24 import com.liferay.portal.struts.PortletAction;
25
26 import javax.portlet.ActionRequest;
27 import javax.portlet.ActionResponse;
28 import javax.portlet.PortletConfig;
29 import javax.portlet.RenderRequest;
30 import javax.portlet.RenderResponse;
31
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35
36
41 public class EditOrgLaborAction extends PortletAction {
42
43 public void processAction(
44 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
45 ActionRequest actionRequest, ActionResponse actionResponse)
46 throws Exception {
47
48 String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
49
50 try {
51 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
52 updateOrgLabor(actionRequest);
53 }
54 else if (cmd.equals(Constants.DELETE)) {
55 deleteOrgLabor(actionRequest);
56 }
57
58 sendRedirect(actionRequest, actionResponse);
59 }
60 catch (Exception e) {
61 if (e instanceof NoSuchOrgLaborException ||
62 e instanceof PrincipalException) {
63
64 SessionErrors.add(actionRequest, e.getClass().getName());
65
66 setForward(actionRequest, "portlet.enterprise_admin.error");
67 }
68 else if (e instanceof NoSuchListTypeException) {
69 SessionErrors.add(actionRequest, e.getClass().getName());
70 }
71 else {
72 throw e;
73 }
74 }
75 }
76
77 public ActionForward render(
78 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
79 RenderRequest renderRequest, RenderResponse renderResponse)
80 throws Exception {
81
82 try {
83 ActionUtil.getOrgLabor(renderRequest);
84 }
85 catch (Exception e) {
86 if (e instanceof NoSuchOrgLaborException ||
87 e instanceof PrincipalException) {
88
89 SessionErrors.add(renderRequest, e.getClass().getName());
90
91 return mapping.findForward("portlet.enterprise_admin.error");
92 }
93 else {
94 throw e;
95 }
96 }
97
98 return mapping.findForward(getForward(
99 renderRequest, "portlet.enterprise_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
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
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 }