| LayoutOwnerIdUpgradeColumnImpl.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 *
5 *
6 *
7 * The contents of this file are subject to the terms of the Liferay Enterprise
8 * Subscription License ("License"). You may not use this file except in
9 * compliance with the License. You can obtain a copy of the License by
10 * contacting Liferay, Inc. See the License for the specific language governing
11 * permissions and limitations under the License, including but not limited to
12 * distribution rights of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 package com.liferay.portal.upgrade.v4_3_0.util;
24
25 import com.liferay.portal.kernel.util.GetterUtil;
26 import com.liferay.portal.upgrade.StagnantRowException;
27 import com.liferay.portal.upgrade.util.BaseUpgradeColumnImpl;
28 import com.liferay.portal.upgrade.util.UpgradeColumn;
29 import com.liferay.portal.upgrade.util.ValueMapper;
30
31 /**
32 * <a href="LayoutOwnerIdUpgradeColumnImpl.java.html"><b><i>View Source</i></b>
33 * </a>
34 *
35 * @author Brian Wing Shun Chan
36 */
37 public class LayoutOwnerIdUpgradeColumnImpl extends BaseUpgradeColumnImpl {
38
39 public LayoutOwnerIdUpgradeColumnImpl(
40 String name, UpgradeColumn upgradeColumn, ValueMapper groupIdMapper) {
41
42 super(name);
43
44 _name = name;
45 _upgradeColumn = upgradeColumn;
46 _groupIdMapper = groupIdMapper;
47 }
48
49 public Object getNewValue(Object oldValue) throws Exception {
50 _groupId = null;
51 _privateLayout = null;
52
53 String ownerId = (String)_upgradeColumn.getOldValue();
54
55 if (_name.equals("groupId")) {
56 if (ownerId.startsWith("PUB.") || ownerId.startsWith("PRI.")) {
57 Long groupId = new Long(GetterUtil.getLong(
58 ownerId.substring(4, ownerId.length())));
59
60 _groupId = (Long)_groupIdMapper.getNewValue(groupId);
61
62 return _groupId;
63 }
64 else {
65 throw new StagnantRowException(ownerId);
66 }
67 }
68 else {
69 if (ownerId.startsWith("PUB.")) {
70 _privateLayout = Boolean.FALSE;
71
72 return _privateLayout;
73 }
74 else if (ownerId.startsWith("PRI.")) {
75 _privateLayout = Boolean.TRUE;
76
77 return _privateLayout;
78 }
79 else {
80 throw new StagnantRowException(ownerId);
81 }
82 }
83 }
84
85 public Long getGroupId() {
86 return _groupId;
87 }
88
89 public Boolean isPrivateLayout() {
90 return _privateLayout;
91 }
92
93 private String _name;
94 private UpgradeColumn _upgradeColumn;
95 private ValueMapper _groupIdMapper;
96 private Long _groupId;
97 private Boolean _privateLayout;
98
99 }