1
14
15 package com.liferay.portlet.workflowdefinitionlinks.action;
16
17 import com.liferay.portal.kernel.servlet.SessionErrors;
18 import com.liferay.portal.kernel.util.GetterUtil;
19 import com.liferay.portal.kernel.util.ParamUtil;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.util.StringUtil;
22 import com.liferay.portal.kernel.util.Validator;
23 import com.liferay.portal.kernel.workflow.WorkflowException;
24 import com.liferay.portal.service.WorkflowDefinitionLinkLocalServiceUtil;
25 import com.liferay.portal.struts.PortletAction;
26 import com.liferay.portal.theme.ThemeDisplay;
27 import com.liferay.portal.util.WebKeys;
28
29 import java.util.Enumeration;
30
31 import javax.portlet.ActionRequest;
32 import javax.portlet.ActionResponse;
33 import javax.portlet.PortletConfig;
34 import javax.portlet.RenderRequest;
35 import javax.portlet.RenderResponse;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40
41
49 public class EditWorkflowDefinitionLinkAction extends PortletAction {
50
51 public void processAction(
52 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
53 ActionRequest actionRequest, ActionResponse actionResponse)
54 throws Exception {
55
56 try {
57 updateWorkflowDefinitionLinks(actionRequest);
58
59 sendRedirect(actionRequest, actionResponse);
60 }
61 catch (Exception e) {
62 if (e instanceof WorkflowException) {
63 SessionErrors.add(actionRequest, e.getClass().getName());
64
65 setForward(
66 actionRequest, "portlet.workflow_definition_links.error");
67 }
68 else {
69 throw e;
70 }
71 }
72 }
73
74 public ActionForward render(
75 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
76 RenderRequest renderRequest, RenderResponse renderResponse)
77 throws Exception {
78
79 return mapping.findForward(getForward(
80 renderRequest, "portlet.workflow_definition_links.view"));
81 }
82
83 protected void updateWorkflowDefinitionLink(
84 ThemeDisplay themeDisplay, String className, String value)
85 throws Exception {
86
87 if (Validator.isNull(value)) {
88 WorkflowDefinitionLinkLocalServiceUtil.deleteWorkflowDefinitionLink(
89 themeDisplay.getCompanyId(), themeDisplay.getScopeGroupId(),
90 className);
91 }
92 else {
93 String[] values = StringUtil.split(value, StringPool.AT);
94
95 String workflowDefinitionName = values[0];
96 int workflowDefinitionVersion = GetterUtil.getInteger(
97 values[1]);
98
99 WorkflowDefinitionLinkLocalServiceUtil.updateWorkflowDefinitionLink(
100 themeDisplay.getUserId(), themeDisplay.getCompanyId(),
101 themeDisplay.getScopeGroupId(), className,
102 workflowDefinitionName, workflowDefinitionVersion);
103 }
104 }
105
106 protected void updateWorkflowDefinitionLinks(ActionRequest actionRequest)
107 throws Exception {
108
109 ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(
110 WebKeys.THEME_DISPLAY);
111
112 Enumeration<String> enu = actionRequest.getParameterNames();
113
114 while (enu.hasMoreElements()) {
115 String name = enu.nextElement();
116
117 if (!name.startsWith(_PREFIX)) {
118 continue;
119 }
120
121 String className = name.substring(_PREFIX.length(), name.length());
122 String value = ParamUtil.getString(actionRequest, name);
123
124 updateWorkflowDefinitionLink(themeDisplay, className, value);
125 }
126 }
127
128 private static final String _PREFIX = "workflowDefinitionName@";
129
130 }