1
14
15 package com.liferay.portlet.journal.action;
16
17 import com.liferay.portal.kernel.servlet.SessionErrors;
18 import com.liferay.portal.kernel.util.ParamUtil;
19 import com.liferay.portal.security.auth.PrincipalException;
20 import com.liferay.portal.struts.PortletAction;
21 import com.liferay.portlet.journal.DuplicateStructureIdException;
22 import com.liferay.portlet.journal.NoSuchStructureException;
23 import com.liferay.portlet.journal.StructureIdException;
24 import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
25
26 import javax.portlet.ActionRequest;
27 import javax.portlet.ActionResponse;
28 import javax.portlet.PortletConfig;
29 import javax.portlet.RenderRequest;
30 import javax.portlet.RenderResponse;
31
32 import org.apache.struts.action.ActionForm;
33 import org.apache.struts.action.ActionForward;
34 import org.apache.struts.action.ActionMapping;
35
36
41 public class CopyStructureAction extends PortletAction {
42
43 public void processAction(
44 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
45 ActionRequest actionRequest, ActionResponse actionResponse)
46 throws Exception {
47
48 try {
49 copyStructure(actionRequest);
50
51 sendRedirect(actionRequest, actionResponse);
52 }
53 catch (Exception e) {
54 if (e instanceof NoSuchStructureException ||
55 e instanceof PrincipalException) {
56
57 SessionErrors.add(actionRequest, e.getClass().getName());
58
59 setForward(actionRequest, "portlet.journal.error");
60 }
61 else if (e instanceof DuplicateStructureIdException ||
62 e instanceof StructureIdException) {
63
64 SessionErrors.add(actionRequest, e.getClass().getName());
65 }
66 else {
67 throw e;
68 }
69 }
70 }
71
72 public ActionForward render(
73 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
74 RenderRequest renderRequest, RenderResponse renderResponse)
75 throws Exception {
76
77 return mapping.findForward(
78 getForward(renderRequest, "portlet.journal.copy_structure"));
79 }
80
81 protected void copyStructure(ActionRequest actionRequest) throws Exception {
82 long groupId = ParamUtil.getLong(actionRequest, "groupId");
83 String oldStructureId = ParamUtil.getString(
84 actionRequest, "oldStructureId");
85 String newStructureId = ParamUtil.getString(
86 actionRequest, "newStructureId");
87 boolean autoStructureId = ParamUtil.getBoolean(
88 actionRequest, "autoStructureId");
89
90 JournalStructureServiceUtil.copyStructure(
91 groupId, oldStructureId, newStructureId, autoStructureId);
92 }
93
94 }