/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.users.admin.web.portlet.action;
import com.liferay.portal.kernel.exception.NoSuchListTypeException;
import com.liferay.portal.kernel.exception.NoSuchOrgLaborException;
import com.liferay.portal.kernel.portlet.bridges.mvc.BaseMVCActionCommand;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCActionCommand;
import com.liferay.portal.kernel.security.auth.PrincipalException;
import com.liferay.portal.kernel.service.OrgLaborService;
import com.liferay.portal.kernel.servlet.SessionErrors;
import com.liferay.portal.kernel.util.Constants;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.users.admin.constants.UsersAdminPortletKeys;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Brian Wing Shun Chan
*/
@Component(
immediate = true,
property = {
"javax.portlet.name=" + UsersAdminPortletKeys.USERS_ADMIN,
"mvc.command.name=/users_admin/edit_org_labor"
},
service = MVCActionCommand.class
)
public class EditOrgLaborMVCActionCommand extends BaseMVCActionCommand {
protected void deleteOrgLabor(ActionRequest actionRequest)
throws Exception {
long orgLaborId = ParamUtil.getLong(actionRequest, "orgLaborId");
_orgLaborService.deleteOrgLabor(orgLaborId);
}
@Override
protected void doProcessAction(
ActionRequest actionRequest, ActionResponse actionResponse)
throws Exception {
String cmd = ParamUtil.getString(actionRequest, Constants.CMD);
try {
if (cmd.equals(Constants.ADD) || cmd.equals(Constants.UPDATE)) {
updateOrgLabor(actionRequest);
}
else if (cmd.equals(Constants.DELETE)) {
deleteOrgLabor(actionRequest);
}
}
catch (Exception e) {
if (e instanceof NoSuchOrgLaborException ||
e instanceof PrincipalException) {
SessionErrors.add(actionRequest, e.getClass());
actionResponse.setRenderParameter("mvcPath", "/error.jsp");
}
else if (e instanceof NoSuchListTypeException) {
SessionErrors.add(actionRequest, e.getClass());
}
else {
throw e;
}
}
}
@Reference(unbind = "-")
protected void setOrgLaborService(OrgLaborService orgLaborService) {
_orgLaborService = orgLaborService;
}
protected void updateOrgLabor(ActionRequest actionRequest)
throws Exception {
long orgLaborId = ParamUtil.getLong(actionRequest, "orgLaborId");
long organizationId = ParamUtil.getLong(
actionRequest, "organizationId");
long typeId = ParamUtil.getLong(actionRequest, "typeId");
int sunOpen = ParamUtil.getInteger(actionRequest, "sunOpen");
int sunClose = ParamUtil.getInteger(actionRequest, "sunClose");
int monOpen = ParamUtil.getInteger(actionRequest, "monOpen");
int monClose = ParamUtil.getInteger(actionRequest, "monClose");
int tueOpen = ParamUtil.getInteger(actionRequest, "tueOpen");
int tueClose = ParamUtil.getInteger(actionRequest, "tueClose");
int wedOpen = ParamUtil.getInteger(actionRequest, "wedOpen");
int wedClose = ParamUtil.getInteger(actionRequest, "wedClose");
int thuOpen = ParamUtil.getInteger(actionRequest, "thuOpen");
int thuClose = ParamUtil.getInteger(actionRequest, "thuClose");
int friOpen = ParamUtil.getInteger(actionRequest, "friOpen");
int friClose = ParamUtil.getInteger(actionRequest, "friClose");
int satOpen = ParamUtil.getInteger(actionRequest, "satOpen");
int satClose = ParamUtil.getInteger(actionRequest, "satClose");
if (orgLaborId <= 0) {
// Add organization labor
_orgLaborService.addOrgLabor(
organizationId, typeId, sunOpen, sunClose, monOpen, monClose,
tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose,
friOpen, friClose, satOpen, satClose);
}
else {
// Update organization labor
_orgLaborService.updateOrgLabor(
orgLaborId, typeId, sunOpen, sunClose, monOpen, monClose,
tueOpen, tueClose, wedOpen, wedClose, thuOpen, thuClose,
friOpen, friClose, satOpen, satClose);
}
}
private OrgLaborService _orgLaborService;
}