| ResourceCodeIdUpgradeColumnImpl.java |
1 /**
2 * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions 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.model.ResourceCode;
26 import com.liferay.portal.model.ResourceConstants;
27 import com.liferay.portal.service.ResourceCodeLocalServiceUtil;
28 import com.liferay.portal.upgrade.UpgradeException;
29 import com.liferay.portal.upgrade.util.BaseUpgradeColumnImpl;
30 import com.liferay.portal.upgrade.util.UpgradeColumn;
31
32 /**
33 * <a href="ResourceCodeIdUpgradeColumnImpl.java.html"><b><i>View Source</i></b>
34 * </a>
35 *
36 * @author Alexander Chow
37 * @author Brian Wing Shun Chan
38 *
39 */
40 public class ResourceCodeIdUpgradeColumnImpl extends BaseUpgradeColumnImpl {
41
42 public ResourceCodeIdUpgradeColumnImpl(
43 UpgradeColumn companyIdColumn, UpgradeColumn nameColumn,
44 UpgradeColumn scopeColumn) {
45
46 super("codeId");
47
48 _companyIdColumn = companyIdColumn;
49 _nameColumn = nameColumn;
50 _scopeColumn = scopeColumn;
51 }
52
53 public Object getNewValue(Object oldValue) throws Exception {
54 _scope = 0;
55
56 Long companyId = (Long)_companyIdColumn.getOldValue();
57 String name = (String)_nameColumn.getOldValue();
58 String scope = (String)_scopeColumn.getOldValue();
59
60 if (scope.equals("company")) {
61 _scope = ResourceConstants.SCOPE_COMPANY;
62 }
63 else if (scope.equals("group")) {
64 _scope = ResourceConstants.SCOPE_GROUP;
65 }
66 else if (scope.equals("groupTemplate")) {
67 _scope = ResourceConstants.SCOPE_GROUP_TEMPLATE;
68 }
69 else if (scope.equals("individual")) {
70 _scope = ResourceConstants.SCOPE_INDIVIDUAL;
71 }
72 else {
73 throw new UpgradeException("Scope " + _scope + " is invalid");
74 }
75
76 ResourceCode resourceCode =
77 ResourceCodeLocalServiceUtil.getResourceCode(
78 companyId.longValue(), name, _scope);
79
80 return new Long(resourceCode.getCodeId());
81 }
82
83 public int getScope() {
84 return _scope;
85 }
86
87 private UpgradeColumn _companyIdColumn;
88 private UpgradeColumn _nameColumn;
89 private UpgradeColumn _scopeColumn;
90 private int _scope;
91
92 }