001
014
015 package com.liferay.portlet.messageboards.model;
016
017 import com.liferay.portal.ModelListenerException;
018 import com.liferay.portal.kernel.workflow.WorkflowConstants;
019 import com.liferay.portal.model.BaseModelListener;
020 import com.liferay.portal.model.Layout;
021 import com.liferay.portal.util.PropsValues;
022 import com.liferay.portlet.messageboards.service.MBMessageLocalServiceUtil;
023
024
027 public class LayoutModelListener extends BaseModelListener<Layout> {
028
029 @Override
030 public void onAfterCreate(Layout layout) throws ModelListenerException {
031 if (PropsValues.LAYOUT_COMMENTS_ENABLED) {
032 try {
033 MBMessageLocalServiceUtil.addDiscussionMessage(
034 layout.getUserId(), layout.getUserName(),
035 layout.getGroupId(), Layout.class.getName(),
036 layout.getPlid(), WorkflowConstants.ACTION_PUBLISH);
037 }
038 catch (Exception e) {
039 throw new ModelListenerException(e);
040 }
041 }
042 }
043
044 @Override
045 public void onBeforeRemove(Layout layout) throws ModelListenerException {
046 try {
047 MBMessageLocalServiceUtil.deleteDiscussionMessages(
048 Layout.class.getName(), layout.getPlid());
049 }
050 catch (Exception e) {
051 throw new ModelListenerException(e);
052 }
053 }
054
055 }