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.v4_3_0.util;
016    
017    import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
018    import com.liferay.portal.kernel.upgrade.util.ValueMapper;
019    import com.liferay.portal.kernel.upgrade.util.ValueMapperFactoryUtil;
020    import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
021    import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class WikiPageIdUpgradeColumnImpl extends PKUpgradeColumnImpl {
027    
028            public WikiPageIdUpgradeColumnImpl(
029                    UpgradeColumn nodeIdColumn, UpgradeColumn titleColumn) {
030    
031                    super("pageId", false);
032    
033                    _nodeIdColumn = nodeIdColumn;
034                    _titleColumn = titleColumn;
035                    _wikiPageIdMapper = ValueMapperFactoryUtil.getValueMapper();
036            }
037    
038            public Object getNewValue(Object oldValue) throws Exception {
039                    _resourcePrimKey = null;
040    
041                    Object newValue = super.getNewValue(oldValue);
042    
043                    Long oldNodeId = (Long)_nodeIdColumn.getOldValue();
044                    Long newNodeId = (Long)_nodeIdColumn.getNewValue();
045                    String title = (String)_titleColumn.getOldValue();
046    
047                    String oldPageIdValue =
048                            "{nodeId=" + oldNodeId + ", title=" + title + ", version=1.0}";
049    
050                    _resourcePrimKey = new Long(WikiPageResourceLocalServiceUtil.
051                            getPageResourcePrimKey(newNodeId.longValue(), title));
052    
053                    _wikiPageIdMapper.mapValue(oldPageIdValue, _resourcePrimKey);
054    
055                    return newValue;
056            }
057    
058            public ValueMapper getValueMapper() {
059                    return _wikiPageIdMapper;
060            }
061    
062            public Long getResourcePrimKey() {
063                    return _resourcePrimKey;
064            }
065    
066            private UpgradeColumn _nodeIdColumn;
067            private UpgradeColumn _titleColumn;
068            private ValueMapper _wikiPageIdMapper;
069            private Long _resourcePrimKey;
070    
071    }