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.util.Constants;
28 import com.liferay.portal.kernel.util.ParamUtil;
29 import com.liferay.portal.security.auth.PrincipalException;
30 import com.liferay.portal.service.OrgLaborServiceUtil;
31 import com.liferay.portal.struts.PortletAction;
32 import com.liferay.util.servlet.SessionErrors;
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 config,
54 ActionRequest req, ActionResponse res)
55 throws Exception {
56
57 String cmd = ParamUtil.getString(req, Constants.CMD);
58
59 try {
60 if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
61 updateOrgLabor(req);
62 }
63 else if (cmd.equals(Constants.DELETE)) {
64 deleteOrgLabor(req);
65 }
66
67 sendRedirect(req, res);
68 }
69 catch (Exception e) {
70 if (e instanceof NoSuchOrgLaborException ||
71 e instanceof PrincipalException) {
72
73 SessionErrors.add(req, e.getClass().getName());
74
75 setForward(req, "portlet.enterprise_admin.error");
76 }
77 else if (e instanceof NoSuchListTypeException) {
78 SessionErrors.add(req, e.getClass().getName());
79 }
80 else {
81 throw e;
82 }
83 }
84 }
85
86 public ActionForward render(
87 ActionMapping mapping, ActionForm form, PortletConfig config,
88 RenderRequest req, RenderResponse res)
89 throws Exception {
90
91 try {
92 ActionUtil.getOrgLabor(req);
93 }
94 catch (Exception e) {
95 if (e instanceof NoSuchOrgLaborException ||
96 e instanceof PrincipalException) {
97
98 SessionErrors.add(req, 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(
108 getForward(req, "portlet.enterprise_admin.edit_org_labor"));
109 }
110
111 protected void deleteOrgLabor(ActionRequest req) throws Exception {
112 long orgLaborId = ParamUtil.getLong(req, "orgLaborId");
113
114 OrgLaborServiceUtil.deleteOrgLabor(orgLaborId);
115 }
116
117 protected void updateOrgLabor(ActionRequest req) throws Exception {
118 long orgLaborId = ParamUtil.getLong(req, "orgLaborId");
119
120 long organizationId = ParamUtil.getLong(req, "organizationId");
121 int typeId = ParamUtil.getInteger(req, "typeId");
122
123 int sunOpen = ParamUtil.getInteger(req, "sunOpen");
124 int sunClose = ParamUtil.getInteger(req, "sunClose");
125
126 int monOpen = ParamUtil.getInteger(req, "monOpen");
127 int monClose = ParamUtil.getInteger(req, "monClose");
128
129 int tueOpen = ParamUtil.getInteger(req, "tueOpen");
130 int tueClose = ParamUtil.getInteger(req, "tueClose");
131
132 int wedOpen = ParamUtil.getInteger(req, "wedOpen");
133 int wedClose = ParamUtil.getInteger(req, "wedClose");
134
135 int thuOpen = ParamUtil.getInteger(req, "thuOpen");
136 int thuClose = ParamUtil.getInteger(req, "thuClose");
137
138 int friOpen = ParamUtil.getInteger(req, "friOpen");
139 int friClose = ParamUtil.getInteger(req, "friClose");
140
141 int satOpen = ParamUtil.getInteger(req, "satOpen");
142 int satClose = ParamUtil.getInteger(req, "satClose");
143
144 if (orgLaborId <= 0) {
145
146
148 OrgLaborServiceUtil.addOrgLabor(
149 organizationId, typeId, sunOpen, sunClose, monOpen, monClose,
150 tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose,
151 friOpen, friClose, satOpen, satClose);
152 }
153 else {
154
155
157 OrgLaborServiceUtil.updateOrgLabor(
158 orgLaborId, sunOpen, sunClose, monOpen, monClose, tueOpen,
159 tueClose, wedOpen, wedClose, thuOpen, thuClose, friOpen,
160 friClose, satOpen, satClose);
161 }
162 }
163
164 }