001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.upgrade.v4_3_0.util;
016    
017    import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
018    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
019    import com.liferay.portal.kernel.upgrade.util.ValueMapper;
020    import com.liferay.portal.util.PortletKeys;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class PrefsPlidUpgradeColumnImpl extends BaseUpgradeColumnImpl {
026    
027            public PrefsPlidUpgradeColumnImpl(
028                    PrefsOwnerIdUpgradeColumnImpl ownerIdColumn,
029                    UpgradeColumn layoutIdColumn, ValueMapper layoutPlidMapper) {
030    
031                    super("plid");
032    
033                    _ownerIdColumn = ownerIdColumn;
034                    _layoutIdColumn = layoutIdColumn;
035                    _layoutPlidMapper = layoutPlidMapper;
036            }
037    
038            public Object getNewValue(Object oldValue) throws Exception {
039                    Long oldGroupId = _ownerIdColumn.getOldGroupId();
040                    Long newGroupId = _ownerIdColumn.getNewGroupId();
041                    Boolean privateLayout = _ownerIdColumn.isPrivateLayout();
042                    String layoutId = (String)_layoutIdColumn.getOldValue();
043    
044                    if ((!layoutId.equals("SHARED")) && (oldGroupId != null) &&
045                            (newGroupId != null) && (privateLayout != null)) {
046    
047                            String oldOwnerId = null;
048    
049                            if (privateLayout.booleanValue()) {
050                                    oldOwnerId = "PRI.";
051                            }
052                            else {
053                                    oldOwnerId = "PUB.";
054                            }
055    
056                            oldOwnerId += oldGroupId.longValue();
057    
058                            String oldPlidValue =
059                                    "{layoutId=" + layoutId + ", ownerId=" + oldOwnerId + "}";
060    
061                            return _layoutPlidMapper.getNewValue(oldPlidValue);
062                    }
063                    else {
064                            return new Long(PortletKeys.PREFS_PLID_SHARED);
065                    }
066            }
067    
068            private PrefsOwnerIdUpgradeColumnImpl _ownerIdColumn;
069            private UpgradeColumn _layoutIdColumn;
070            private ValueMapper _layoutPlidMapper;
071    
072    }