1
22
23 package com.liferay.portlet.journal.action;
24
25 import com.liferay.portal.kernel.servlet.SessionErrors;
26 import com.liferay.portal.kernel.util.ParamUtil;
27 import com.liferay.portal.security.auth.PrincipalException;
28 import com.liferay.portal.struts.PortletAction;
29 import com.liferay.portlet.journal.DuplicateStructureIdException;
30 import com.liferay.portlet.journal.NoSuchStructureException;
31 import com.liferay.portlet.journal.StructureIdException;
32 import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
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 CopyStructureAction extends PortletAction {
51
52 public void processAction(
53 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
54 ActionRequest actionRequest, ActionResponse actionResponse)
55 throws Exception {
56
57 try {
58 copyStructure(actionRequest);
59
60 sendRedirect(actionRequest, actionResponse);
61 }
62 catch (Exception e) {
63 if (e instanceof NoSuchStructureException ||
64 e instanceof PrincipalException) {
65
66 SessionErrors.add(actionRequest, e.getClass().getName());
67
68 setForward(actionRequest, "portlet.journal.error");
69 }
70 else if (e instanceof DuplicateStructureIdException ||
71 e instanceof StructureIdException) {
72
73 SessionErrors.add(actionRequest, e.getClass().getName());
74 }
75 else {
76 throw e;
77 }
78 }
79 }
80
81 public ActionForward render(
82 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
83 RenderRequest renderRequest, RenderResponse renderResponse)
84 throws Exception {
85
86 return mapping.findForward(
87 getForward(renderRequest, "portlet.journal.copy_structure"));
88 }
89
90 protected void copyStructure(ActionRequest actionRequest) throws Exception {
91 long groupId = ParamUtil.getLong(actionRequest, "groupId");
92 String oldStructureId = ParamUtil.getString(
93 actionRequest, "oldStructureId");
94 String newStructureId = ParamUtil.getString(
95 actionRequest, "newStructureId");
96 boolean autoStructureId = ParamUtil.getBoolean(
97 actionRequest, "autoStructureId");
98
99 JournalStructureServiceUtil.copyStructure(
100 groupId, oldStructureId, newStructureId, autoStructureId);
101 }
102
103 }