001    /**
002     * Copyright (c) 2000-2010 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.upgrade.v6_0_0;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.upgrade.BaseUpgradePortletPreferences;
019    import com.liferay.portlet.PortletPreferencesImpl;
020    import com.liferay.portlet.PortletPreferencesSerializer;
021    
022    /**
023     * @author Julio Camarero
024     */
025    public class UpgradeAssetPublisher extends BaseUpgradePortletPreferences {
026    
027            protected String getUpdatePortletPreferencesWhereClause() {
028                    return "portletId like '101_INSTANCE_%'";
029            }
030    
031            protected String upgradePreferences(
032                            long companyId, long ownerId, int ownerType, long plid,
033                            String portletId, String xml)
034                    throws Exception {
035    
036                    PortletPreferencesImpl preferences =
037                            PortletPreferencesSerializer.fromXML(
038                                    companyId, ownerId, ownerType, plid, portletId, xml);
039    
040                    long layoutId = GetterUtil.getLong(
041                            preferences.getValue("lfr-scope-layout-id", null));
042    
043                    preferences.reset("lfr-scope-layout-id");
044    
045                    if (layoutId != 0) {
046                            preferences.setValues(
047                                    "scope-ids", new String[] {"Layout_" + layoutId});
048    
049                            preferences.setValue("default-scope", Boolean.FALSE.toString());
050                    }
051    
052                    long classNameId = GetterUtil.getLong(
053                            preferences.getValue("class-name-id", null));
054    
055                    preferences.reset("class-name-id");
056    
057                    if (classNameId != 0) {
058                            preferences.setValues(
059                                    "class-name-ids", new String[] {String.valueOf(classNameId)});
060    
061                            preferences.setValue("any-asset-type", Boolean.FALSE.toString());
062                    }
063    
064                    boolean andOperator = GetterUtil.getBoolean(
065                            preferences.getValue("and-operator", null));
066    
067                    preferences.reset("and-operator");
068    
069                    String[] assetTagNames = preferences.getValues("entries", null);
070                    String[] notAssetTagNames = preferences.getValues("not-entries", null);
071    
072                    int i = 0;
073    
074                    if (assetTagNames != null) {
075                            preferences.reset("entries");
076    
077                            preferences.setValue("queryContains" + i, Boolean.TRUE.toString());
078                            preferences.setValue(
079                                    "queryAndOperator" + i, String.valueOf(andOperator));
080                            preferences.setValue("queryName" + i, "assetTags");
081                            preferences.setValues("queryValues" + i, assetTagNames);
082    
083                            i++;
084                    }
085    
086                    if (notAssetTagNames != null) {
087                            preferences.reset("not-entries");
088    
089                            preferences.setValue("queryContains" + i, Boolean.FALSE.toString());
090                            preferences.setValue(
091                                    "queryAndOperator" + i, String.valueOf(andOperator));
092                            preferences.setValue("queryName" + i, "assetTags");
093                            preferences.setValues("queryValues" + i, notAssetTagNames);
094    
095                            i++;
096                    }
097    
098                    return PortletPreferencesSerializer.toXML(preferences);
099            }
100    
101    }