1
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
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 }