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_3;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.StringPool;
019    import com.liferay.portal.upgrade.BaseUpgradePortletPreferences;
020    import com.liferay.portlet.PortletPreferencesImpl;
021    import com.liferay.portlet.PortletPreferencesSerializer;
022    
023    /**
024     * @author Julio Camarero
025     */
026    public class UpgradeSitemap extends BaseUpgradePortletPreferences {
027    
028            protected String getUpdatePortletPreferencesWhereClause() {
029                    return "portletId like '85_%'";
030            }
031    
032            protected String upgradePreferences(
033                            long companyId, long ownerId, int ownerType, long plid,
034                            String portletId, String xml)
035                    throws Exception {
036    
037                    PortletPreferencesImpl preferences =
038                            PortletPreferencesSerializer.fromXML(
039                                    companyId, ownerId, ownerType, plid, portletId, xml);
040    
041                    long rootLayoutId = GetterUtil.getLong(
042                            preferences.getValue("root-layout-id", StringPool.BLANK));
043    
044                    if (rootLayoutId > 0) {
045                            String uuid = getLayoutUuid(plid, rootLayoutId);
046    
047                            if (uuid != null) {
048                                    preferences.setValue("root-layout-uuid", uuid);
049                            }
050    
051                            preferences.reset("root-layout-id");
052                    }
053    
054                    return PortletPreferencesSerializer.toXML(preferences);
055            }
056    
057    }