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.exception.ModelListenerException;
018    import com.liferay.portal.kernel.comment.CommentManagerUtil;
019    import com.liferay.portal.model.BaseModelListener;
020    import com.liferay.portal.model.Layout;
021    import com.liferay.portal.util.PropsValues;
022    
023    /**
024     * @author Eduardo Garcia
025     */
026    public class LayoutModelListener extends BaseModelListener<Layout> {
027    
028            @Override
029            public void onAfterCreate(Layout layout) throws ModelListenerException {
030                    if (PropsValues.LAYOUT_COMMENTS_ENABLED) {
031                            try {
032                                    CommentManagerUtil.addDiscussion(
033                                            layout.getUserId(), layout.getGroupId(),
034                                            Layout.class.getName(), layout.getPlid(),
035                                            layout.getUserName());
036                            }
037                            catch (Exception e) {
038                                    throw new ModelListenerException(e);
039                            }
040                    }
041            }
042    
043            @Override
044            public void onBeforeRemove(Layout layout) throws ModelListenerException {
045                    try {
046                            CommentManagerUtil.deleteDiscussion(
047                                    Layout.class.getName(), layout.getPlid());
048                    }
049                    catch (Exception e) {
050                            throw new ModelListenerException(e);
051                    }
052            }
053    
054    }