1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.upgrade.v4_3_0.util;
16  
17  import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
18  import com.liferay.portal.kernel.upgrade.util.ValueMapper;
19  import com.liferay.portal.kernel.upgrade.util.ValueMapperFactoryUtil;
20  import com.liferay.portal.upgrade.util.PKUpgradeColumnImpl;
21  import com.liferay.portlet.wiki.service.WikiPageResourceLocalServiceUtil;
22  
23  /**
24   * <a href="WikiPageIdUpgradeColumnImpl.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class WikiPageIdUpgradeColumnImpl extends PKUpgradeColumnImpl {
29  
30      public WikiPageIdUpgradeColumnImpl(
31          UpgradeColumn nodeIdColumn, UpgradeColumn titleColumn) {
32  
33          super("pageId", false);
34  
35          _nodeIdColumn = nodeIdColumn;
36          _titleColumn = titleColumn;
37          _wikiPageIdMapper = ValueMapperFactoryUtil.getValueMapper();
38      }
39  
40      public Object getNewValue(Object oldValue) throws Exception {
41          _resourcePrimKey = null;
42  
43          Object newValue = super.getNewValue(oldValue);
44  
45          Long oldNodeId = (Long)_nodeIdColumn.getOldValue();
46          Long newNodeId = (Long)_nodeIdColumn.getNewValue();
47          String title = (String)_titleColumn.getOldValue();
48  
49          String oldPageIdValue =
50              "{nodeId=" + oldNodeId + ", title=" + title + ", version=1.0}";
51  
52          _resourcePrimKey = new Long(WikiPageResourceLocalServiceUtil.
53              getPageResourcePrimKey(newNodeId.longValue(), title));
54  
55          _wikiPageIdMapper.mapValue(oldPageIdValue, _resourcePrimKey);
56  
57          return newValue;
58      }
59  
60      public ValueMapper getValueMapper() {
61          return _wikiPageIdMapper;
62      }
63  
64      public Long getResourcePrimKey() {
65          return _resourcePrimKey;
66      }
67  
68      private UpgradeColumn _nodeIdColumn;
69      private UpgradeColumn _titleColumn;
70      private ValueMapper _wikiPageIdMapper;
71      private Long _resourcePrimKey;
72  
73  }