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.workflow.action;
022:
023: import com.liferay.portal.kernel.util.Constants;
024: import com.liferay.portal.kernel.util.ParamUtil;
025: import com.liferay.portal.security.auth.PrincipalException;
026: import com.liferay.portal.struts.PortletAction;
027: import com.liferay.portlet.workflow.model.WorkflowInstance;
028: import com.liferay.portlet.workflow.service.WorkflowInstanceServiceUtil;
029: import com.liferay.util.servlet.SessionErrors;
030:
031: import javax.portlet.ActionRequest;
032: import javax.portlet.ActionResponse;
033: import javax.portlet.PortletConfig;
034:
035: import org.apache.struts.action.ActionForm;
036: import org.apache.struts.action.ActionMapping;
037:
038: /**
039: * <a href="EditInstanceAction.java.html"><b><i>View Source</i></b></a>
040: *
041: * @author Brian Wing Shun Chan
042: *
043: */
044: public class EditInstanceAction extends PortletAction {
045:
046: public void processAction(ActionMapping mapping, ActionForm form,
047: PortletConfig config, ActionRequest req, ActionResponse res)
048: throws Exception {
049:
050: String cmd = ParamUtil.getString(req, Constants.CMD);
051:
052: try {
053: if (cmd.equals(Constants.ADD)) {
054: addInstance(req, res);
055: } else if (cmd.equals(Constants.SIGNAL)) {
056: signalInstance(req, res);
057: }
058: } catch (Exception e) {
059: if (e instanceof PrincipalException) {
060: SessionErrors.add(req, e.getClass().getName());
061:
062: setForward(req, "portlet.workflow.error");
063: } else {
064: throw e;
065: }
066: }
067: }
068:
069: protected void addInstance(ActionRequest req, ActionResponse res)
070: throws Exception {
071:
072: long definitionId = ParamUtil.getLong(req, "definitionId");
073:
074: WorkflowInstance instance = WorkflowInstanceServiceUtil
075: .addInstance(definitionId);
076:
077: String redirect = ParamUtil.getString(req, "redirect");
078:
079: redirect += "&instanceId=" + instance.getInstanceId();
080:
081: sendRedirect(req, res, redirect);
082: }
083:
084: protected void signalInstance(ActionRequest req, ActionResponse res)
085: throws Exception {
086:
087: long instanceId = ParamUtil.getLong(req, "instanceId");
088: long tokenId = ParamUtil.getLong(req, "tokenId");
089:
090: if (tokenId <= 0) {
091: WorkflowInstanceServiceUtil.signalInstance(instanceId);
092: } else {
093: WorkflowInstanceServiceUtil
094: .signalToken(instanceId, tokenId);
095: }
096:
097: sendRedirect(req, res);
098: }
099:
100: }
|