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.StagnantRowException;
18  import com.liferay.portal.kernel.upgrade.util.BaseUpgradeColumnImpl;
19  import com.liferay.portal.kernel.upgrade.util.UpgradeColumn;
20  import com.liferay.portal.kernel.upgrade.util.ValueMapper;
21  import com.liferay.portal.kernel.util.GetterUtil;
22  
23  /**
24   * <a href="LayoutOwnerIdUpgradeColumnImpl.java.html"><b><i>View Source</i></b>
25   * </a>
26   *
27   * @author Brian Wing Shun Chan
28   */
29  public class LayoutOwnerIdUpgradeColumnImpl extends BaseUpgradeColumnImpl {
30  
31      public LayoutOwnerIdUpgradeColumnImpl(
32          String name, UpgradeColumn upgradeColumn, ValueMapper groupIdMapper) {
33  
34          super(name);
35  
36          _name = name;
37          _upgradeColumn = upgradeColumn;
38          _groupIdMapper = groupIdMapper;
39      }
40  
41      public Object getNewValue(Object oldValue) throws Exception {
42          _groupId = null;
43          _privateLayout = null;
44  
45          String ownerId = (String)_upgradeColumn.getOldValue();
46  
47          if (_name.equals("groupId")) {
48              if (ownerId.startsWith("PUB.") || ownerId.startsWith("PRI.")) {
49                  Long groupId = new Long(GetterUtil.getLong(
50                      ownerId.substring(4, ownerId.length())));
51  
52                  _groupId = (Long)_groupIdMapper.getNewValue(groupId);
53  
54                  return _groupId;
55              }
56              else {
57                  throw new StagnantRowException(ownerId);
58              }
59          }
60          else {
61              if (ownerId.startsWith("PUB.")) {
62                  _privateLayout = Boolean.FALSE;
63  
64                  return _privateLayout;
65              }
66              else if (ownerId.startsWith("PRI.")) {
67                  _privateLayout = Boolean.TRUE;
68  
69                  return _privateLayout;
70              }
71              else {
72                  throw new StagnantRowException(ownerId);
73              }
74          }
75      }
76  
77      public Long getGroupId() {
78          return _groupId;
79      }
80  
81      public Boolean isPrivateLayout() {
82          return _privateLayout;
83      }
84  
85      private String _name;
86      private UpgradeColumn _upgradeColumn;
87      private ValueMapper _groupIdMapper;
88      private Long _groupId;
89      private Boolean _privateLayout;
90  
91  }