001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
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    /**
025     * @author Eduardo Garcia
026     */
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    }