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.layoutsadmin.lar;
016    
017    import com.liferay.portal.kernel.spring.osgi.OSGiBeanProperties;
018    import com.liferay.portal.kernel.util.MapUtil;
019    import com.liferay.portal.kernel.xml.Element;
020    import com.liferay.portal.model.Theme;
021    import com.liferay.portal.model.adapter.StagedTheme;
022    import com.liferay.portal.service.ThemeLocalServiceUtil;
023    import com.liferay.portlet.exportimport.lar.BaseStagedModelDataHandler;
024    import com.liferay.portlet.exportimport.lar.PortletDataContext;
025    import com.liferay.portlet.exportimport.lar.PortletDataHandlerKeys;
026    
027    import java.util.Collections;
028    import java.util.List;
029    
030    /**
031     * @author Mate Thurzo
032     */
033    @OSGiBeanProperties
034    public class StagedThemeStagedModelDataHandler
035            extends BaseStagedModelDataHandler<StagedTheme> {
036    
037            public static final String[] CLASS_NAMES = {StagedTheme.class.getName()};
038    
039            @Override
040            public void deleteStagedModel(StagedTheme stagedTheme) {
041            }
042    
043            @Override
044            public void deleteStagedModel(
045                    String uuid, long groupId, String className, String extraData) {
046            }
047    
048            @Override
049            public List<StagedTheme> fetchStagedModelsByUuidAndCompanyId(
050                    String uuid, long companyId) {
051    
052                    return Collections.emptyList();
053            }
054    
055            @Override
056            public String[] getClassNames() {
057                    return CLASS_NAMES;
058            }
059    
060            @Override
061            public String getDisplayName(StagedTheme stagedTheme) {
062                    return stagedTheme.getThemeId();
063            }
064    
065            @Override
066            public boolean validateReference(
067                    PortletDataContext portletDataContext, Element referenceElement) {
068    
069                    boolean importThemeSettings = MapUtil.getBoolean(
070                            portletDataContext.getParameterMap(),
071                            PortletDataHandlerKeys.THEME_REFERENCE);
072    
073                    if (!importThemeSettings) {
074                            return true;
075                    }
076    
077                    String classPK = referenceElement.attributeValue("class-pk");
078    
079                    List<Theme> themes = ThemeLocalServiceUtil.getThemes(
080                            portletDataContext.getCompanyId());
081    
082                    for (Theme theme : themes) {
083                            String themeId = theme.getThemeId();
084    
085                            if (themeId.equals(classPK)) {
086                                    return true;
087                            }
088                    }
089    
090                    return false;
091            }
092    
093            @Override
094            protected void doExportStagedModel(
095                    PortletDataContext portletDataContext, StagedTheme stagedTheme) {
096            }
097    
098            @Override
099            protected void doImportStagedModel(
100                    PortletDataContext portletDataContext, StagedTheme stagedTheme) {
101            }
102    
103    }