001
014
015 package com.liferay.portlet.journal.action;
016
017 import com.liferay.portal.kernel.servlet.SessionErrors;
018 import com.liferay.portal.kernel.util.ParamUtil;
019 import com.liferay.portal.security.auth.PrincipalException;
020 import com.liferay.portal.struts.PortletAction;
021 import com.liferay.portlet.journal.DuplicateStructureIdException;
022 import com.liferay.portlet.journal.NoSuchStructureException;
023 import com.liferay.portlet.journal.StructureIdException;
024 import com.liferay.portlet.journal.service.JournalStructureServiceUtil;
025
026 import javax.portlet.ActionRequest;
027 import javax.portlet.ActionResponse;
028 import javax.portlet.PortletConfig;
029 import javax.portlet.RenderRequest;
030 import javax.portlet.RenderResponse;
031
032 import org.apache.struts.action.ActionForm;
033 import org.apache.struts.action.ActionForward;
034 import org.apache.struts.action.ActionMapping;
035
036
039 public class CopyStructureAction extends PortletAction {
040
041 @Override
042 public void processAction(
043 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
044 ActionRequest actionRequest, ActionResponse actionResponse)
045 throws Exception {
046
047 try {
048 copyStructure(actionRequest);
049
050 sendRedirect(actionRequest, actionResponse);
051 }
052 catch (Exception e) {
053 if (e instanceof NoSuchStructureException ||
054 e instanceof PrincipalException) {
055
056 SessionErrors.add(actionRequest, e.getClass().getName());
057
058 setForward(actionRequest, "portlet.journal.error");
059 }
060 else if (e instanceof DuplicateStructureIdException ||
061 e instanceof StructureIdException) {
062
063 SessionErrors.add(actionRequest, e.getClass().getName());
064 }
065 else {
066 throw e;
067 }
068 }
069 }
070
071 @Override
072 public ActionForward render(
073 ActionMapping mapping, ActionForm form, PortletConfig portletConfig,
074 RenderRequest renderRequest, RenderResponse renderResponse)
075 throws Exception {
076
077 return mapping.findForward(
078 getForward(renderRequest, "portlet.journal.copy_structure"));
079 }
080
081 protected void copyStructure(ActionRequest actionRequest) throws Exception {
082 long groupId = ParamUtil.getLong(actionRequest, "groupId");
083 String oldStructureId = ParamUtil.getString(
084 actionRequest, "oldStructureId");
085 String newStructureId = ParamUtil.getString(
086 actionRequest, "newStructureId");
087 boolean autoStructureId = ParamUtil.getBoolean(
088 actionRequest, "autoStructureId");
089
090 JournalStructureServiceUtil.copyStructure(
091 groupId, oldStructureId, newStructureId, autoStructureId);
092 }
093
094 }