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 actionMapping, ActionForm actionForm,
044 PortletConfig portletConfig, ActionRequest actionRequest,
045 ActionResponse actionResponse)
046 throws Exception {
047
048 try {
049 copyStructure(actionRequest);
050
051 sendRedirect(actionRequest, actionResponse);
052 }
053 catch (Exception e) {
054 if (e instanceof NoSuchStructureException ||
055 e instanceof PrincipalException) {
056
057 SessionErrors.add(actionRequest, e.getClass());
058
059 setForward(actionRequest, "portlet.journal.error");
060 }
061 else if (e instanceof DuplicateStructureIdException ||
062 e instanceof StructureIdException) {
063
064 SessionErrors.add(actionRequest, e.getClass());
065 }
066 else {
067 throw e;
068 }
069 }
070 }
071
072 @Override
073 public ActionForward render(
074 ActionMapping actionMapping, ActionForm actionForm,
075 PortletConfig portletConfig, RenderRequest renderRequest,
076 RenderResponse renderResponse)
077 throws Exception {
078
079 return actionMapping.findForward(
080 getForward(renderRequest, "portlet.journal.copy_structure"));
081 }
082
083 protected void copyStructure(ActionRequest actionRequest) throws Exception {
084 long groupId = ParamUtil.getLong(actionRequest, "groupId");
085 String oldStructureId = ParamUtil.getString(
086 actionRequest, "oldStructureId");
087 String newStructureId = ParamUtil.getString(
088 actionRequest, "newStructureId");
089 boolean autoStructureId = ParamUtil.getBoolean(
090 actionRequest, "autoStructureId");
091
092 JournalStructureServiceUtil.copyStructure(
093 groupId, oldStructureId, newStructureId, autoStructureId);
094 }
095
096 }