001    /**
002     * Copyright (c) 2000-2012 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.portal.service.impl;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.UnicodeProperties;
020    import com.liferay.portal.model.BaseModelListener;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.model.LayoutSet;
023    import com.liferay.portal.model.LayoutSetPrototype;
024    import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
025    import com.liferay.portal.service.persistence.LayoutSetPrototypeUtil;
026    
027    /**
028     * @author Raymond Augé
029     */
030    public class LayoutSetPrototypeLayoutSetListener
031            extends BaseModelListener<LayoutSet> {
032    
033            @Override
034            public void onAfterCreate(LayoutSet layoutSet) {
035                    updateLayoutSetPrototype(layoutSet);
036            }
037    
038            @Override
039            public void onAfterRemove(LayoutSet layoutSet) {
040                    updateLayoutSetPrototype(layoutSet);
041            }
042    
043            @Override
044            public void onAfterUpdate(LayoutSet layoutSet) {
045                    updateLayoutSetPrototype(layoutSet);
046            }
047    
048            protected void updateLayoutSetPrototype(LayoutSet layoutSet) {
049                    try {
050                            Group group = layoutSet.getGroup();
051    
052                            if (!group.isLayoutSetPrototype()) {
053                                    return;
054                            }
055    
056                            LayoutSetPrototype layoutSetPrototype =
057                                    LayoutSetPrototypeLocalServiceUtil.getLayoutSetPrototype(
058                                            group.getClassPK());
059    
060                            layoutSetPrototype.setModifiedDate(layoutSet.getModifiedDate());
061    
062                            UnicodeProperties settingsProperties =
063                                    layoutSet.getSettingsProperties();
064    
065                            settingsProperties.remove("merge-fail-count");
066    
067                            LayoutSetPrototypeUtil.update(layoutSetPrototype, false);
068                    }
069                    catch (Exception e) {
070                            _log.error(e, e);
071                    }
072            }
073    
074            private static Log _log = LogFactoryUtil.getLog(
075                    LayoutSetPrototypeLayoutListener.class);
076    
077    }