001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.enterpriseadmin.action;
022:
023: import com.liferay.portal.NoSuchListTypeException;
024: import com.liferay.portal.NoSuchOrgLaborException;
025: import com.liferay.portal.kernel.util.Constants;
026: import com.liferay.portal.kernel.util.ParamUtil;
027: import com.liferay.portal.security.auth.PrincipalException;
028: import com.liferay.portal.service.OrgLaborServiceUtil;
029: import com.liferay.portal.struts.PortletAction;
030: import com.liferay.util.servlet.SessionErrors;
031:
032: import javax.portlet.ActionRequest;
033: import javax.portlet.ActionResponse;
034: import javax.portlet.PortletConfig;
035: import javax.portlet.RenderRequest;
036: import javax.portlet.RenderResponse;
037:
038: import org.apache.struts.action.ActionForm;
039: import org.apache.struts.action.ActionForward;
040: import org.apache.struts.action.ActionMapping;
041:
042: /**
043: * <a href="EditOrgLaborAction.java.html"><b><i>View Source</i></b></a>
044: *
045: * @author Brian Wing Shun Chan
046: *
047: */
048: public class EditOrgLaborAction extends PortletAction {
049:
050: public void processAction(ActionMapping mapping, ActionForm form,
051: PortletConfig config, ActionRequest req, ActionResponse res)
052: throws Exception {
053:
054: String cmd = ParamUtil.getString(req, Constants.CMD);
055:
056: try {
057: if (cmd.equals(Constants.ADD)
058: || cmd.equals(Constants.UPDATE)) {
059: updateOrgLabor(req);
060: } else if (cmd.equals(Constants.DELETE)) {
061: deleteOrgLabor(req);
062: }
063:
064: sendRedirect(req, res);
065: } catch (Exception e) {
066: if (e instanceof NoSuchOrgLaborException
067: || e instanceof PrincipalException) {
068:
069: SessionErrors.add(req, e.getClass().getName());
070:
071: setForward(req, "portlet.enterprise_admin.error");
072: } else if (e instanceof NoSuchListTypeException) {
073: SessionErrors.add(req, e.getClass().getName());
074: } else {
075: throw e;
076: }
077: }
078: }
079:
080: public ActionForward render(ActionMapping mapping, ActionForm form,
081: PortletConfig config, RenderRequest req, RenderResponse res)
082: throws Exception {
083:
084: try {
085: ActionUtil.getOrgLabor(req);
086: } catch (Exception e) {
087: if (e instanceof NoSuchOrgLaborException
088: || e instanceof PrincipalException) {
089:
090: SessionErrors.add(req, e.getClass().getName());
091:
092: return mapping
093: .findForward("portlet.enterprise_admin.error");
094: } else {
095: throw e;
096: }
097: }
098:
099: return mapping.findForward(getForward(req,
100: "portlet.enterprise_admin.edit_org_labor"));
101: }
102:
103: protected void deleteOrgLabor(ActionRequest req) throws Exception {
104: long orgLaborId = ParamUtil.getLong(req, "orgLaborId");
105:
106: OrgLaborServiceUtil.deleteOrgLabor(orgLaborId);
107: }
108:
109: protected void updateOrgLabor(ActionRequest req) throws Exception {
110: long orgLaborId = ParamUtil.getLong(req, "orgLaborId");
111:
112: long organizationId = ParamUtil.getLong(req, "organizationId");
113: int typeId = ParamUtil.getInteger(req, "typeId");
114:
115: int sunOpen = ParamUtil.getInteger(req, "sunOpen");
116: int sunClose = ParamUtil.getInteger(req, "sunClose");
117:
118: int monOpen = ParamUtil.getInteger(req, "monOpen");
119: int monClose = ParamUtil.getInteger(req, "monClose");
120:
121: int tueOpen = ParamUtil.getInteger(req, "tueOpen");
122: int tueClose = ParamUtil.getInteger(req, "tueClose");
123:
124: int wedOpen = ParamUtil.getInteger(req, "wedOpen");
125: int wedClose = ParamUtil.getInteger(req, "wedClose");
126:
127: int thuOpen = ParamUtil.getInteger(req, "thuOpen");
128: int thuClose = ParamUtil.getInteger(req, "thuClose");
129:
130: int friOpen = ParamUtil.getInteger(req, "friOpen");
131: int friClose = ParamUtil.getInteger(req, "friClose");
132:
133: int satOpen = ParamUtil.getInteger(req, "satOpen");
134: int satClose = ParamUtil.getInteger(req, "satClose");
135:
136: if (orgLaborId <= 0) {
137:
138: // Add organization labor
139:
140: OrgLaborServiceUtil.addOrgLabor(organizationId, typeId,
141: sunOpen, sunClose, monOpen, monClose, tueOpen,
142: tueClose, wedOpen, wedClose, thuOpen, thuClose,
143: friOpen, friClose, satOpen, satClose);
144: } else {
145:
146: // Update organization labor
147:
148: OrgLaborServiceUtil.updateOrgLabor(orgLaborId, sunOpen,
149: sunClose, monOpen, monClose, tueOpen, tueClose,
150: wedOpen, wedClose, thuOpen, thuClose, friOpen,
151: friClose, satOpen, satClose);
152: }
153: }
154:
155: }
|