1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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  }