/
AssignmentInfoDto.java
281 lines (236 loc) · 8.57 KB
/
AssignmentInfoDto.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
/*
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.page.admin.users.component;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.context.AssignmentPath;
import com.evolveum.midpoint.web.component.util.Selectable;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.wicket.Component;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.Objects;
/**
* Not to be confused with AssignmentDto. This one is used in assignment dialog (preview, selecting for delegation limitations, ...).
*
* @author mederly
*/
@SuppressWarnings("unused")
public class AssignmentInfoDto extends Selectable<AssignmentInfoDto> implements Serializable, Comparable<AssignmentInfoDto> {
public static final String F_TARGET_OID = "targetOid";
public static final String F_TARGET_NAME = "targetName";
public static final String F_TARGET_DESCRIPTION = "targetDescription";
public static final String F_TARGET_TYPE = "targetType";
public static final String F_DIRECT = "direct";
public static final String F_KIND = "kind";
public static final String F_INTENT = "intent";
public static final String F_TENANT_NAME = "tenantName";
public static final String F_ORG_REF_NAME = "orgRefName";
public static final String F_REMARK = "remark";
public static final String F_RELATION = "relation";
// target = role, org or resource
private String targetOid;
private String targetName;
private String targetDescription;
private Class<? extends ObjectType> targetClass;
private boolean direct; // true if directly assigned; used only in some contexts
private ObjectType assignmentParent;
private QName targetType;
// for resource assignments
private ShadowKindType kind;
private String intent;
// for role/org assignments
private String tenantName;
private String orgRefName;
private ObjectReferenceType tenantRef;
private ObjectReferenceType orgRef;
// generic
private String remark;
private QName relation;
public String getTargetOid() {
return targetOid;
}
public void setTargetOid(String targetOid) {
this.targetOid = targetOid;
}
public String getTargetName() {
return targetName;
}
public void setTargetName(String targetName) {
this.targetName = targetName;
}
public String getTargetDescription() {
return targetDescription;
}
public void setTargetDescription(String targetDescription) {
this.targetDescription = targetDescription;
}
public Class<? extends ObjectType> getTargetClass() {
return targetClass;
}
public void setTargetClass(Class<? extends ObjectType> targetClass) {
this.targetClass = targetClass;
}
public boolean isDirect() {
return direct;
}
public void setDirect(boolean direct) {
this.direct = direct;
}
public void setAssignmentParent(AssignmentPath assignmentPath) {
if (assignmentPath.size() > 1 ) {
assignmentParent = assignmentPath.last().getSource();
}
}
public ObjectType getAssignmentParent() {
return assignmentParent;
}
public ShadowKindType getKind() {
return kind;
}
public void setKind(ShadowKindType kind) {
this.kind = kind;
}
public String getIntent() {
return intent;
}
public void setIntent(String intent) {
this.intent = intent;
}
public String getTenantName() {
return tenantName;
}
public void setTenantName(String tenantName) {
this.tenantName = tenantName;
}
public String getOrgRefName() {
return orgRefName;
}
public void setOrgRefName(String orgRefName) {
this.orgRefName = orgRefName;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public ObjectReferenceType getTenantRef() {
return tenantRef;
}
public void setTenantRef(ObjectReferenceType tenantRef) {
this.tenantRef = tenantRef;
}
public ObjectReferenceType getOrgRef() {
return orgRef;
}
public void setOrgRef(ObjectReferenceType orgRef) {
this.orgRef = orgRef;
}
public QName getTargetType() {
return targetType;
}
public void setTargetType(QName targetType) {
this.targetType = targetType;
}
public QName getRelation() {
return relation;
}
public void setRelation(QName relation) {
this.relation = relation;
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof AssignmentInfoDto))
return false;
AssignmentInfoDto that = (AssignmentInfoDto) o;
return direct == that.direct &&
Objects.equals(targetOid, that.targetOid) &&
Objects.equals(targetName, that.targetName) &&
Objects.equals(targetDescription, that.targetDescription) &&
Objects.equals(targetClass, that.targetClass) &&
Objects.equals(targetType, that.targetType) &&
kind == that.kind &&
Objects.equals(intent, that.intent) &&
Objects.equals(tenantName, that.tenantName) &&
Objects.equals(orgRefName, that.orgRefName) &&
Objects.equals(tenantRef, that.tenantRef) &&
Objects.equals(orgRef, that.orgRef) &&
Objects.equals(remark, that.remark) &&
Objects.equals(relation, that.relation);
}
@Override
public int hashCode() {
return Objects
.hash(targetOid, targetName, targetDescription, targetClass, direct, targetType, kind, intent, tenantName,
orgRefName, tenantRef, orgRef, remark, relation);
}
@Override
public int compareTo(AssignmentInfoDto other) {
if (this.equals(other)) {
return 0;
}
// firstly sorting by type: orgs -> roles -> resources -> all the other (in the future)
int co1 = getClassOrder(this.getTargetClass());
int co2 = getClassOrder(other.getTargetClass());
if (co1 != co2) {
return co1 - co2;
}
// then by name
if (this.getTargetName() != null && other.getTargetName() != null) {
int order = this.getTargetName().compareToIgnoreCase(other.getTargetName());
if (order != 0) {
return order;
}
} else if (this.getTargetName() != null && other.getTargetName() == null) {
return -1; // named are before unnamed
} else if (this.getTargetName() == null && other.getTargetName() != null) {
return 1; // unnamed are after named
} else {
// both unnamed - no decision
}
// if class and names are equal, the order can be arbitrary
if (this.hashCode() <= other.hashCode()) {
return -1;
} else {
return 1;
}
}
private int getClassOrder(Class targetClass) {
if (OrgType.class.equals(targetClass)) {
return 0;
} else if (RoleType.class.equals(targetClass)) {
return 1;
} else if (ResourceType.class.equals(targetClass)) {
return 2;
} else {
return 3;
}
}
public IModel<String> getRelationDisplayNameModel(Component component) {
String localizationKey;
if (WebComponentUtil.isDefaultRelation(relation)) {
localizationKey = null;
} else {
localizationKey = WebComponentUtil.getRelationHeaderLabelKey(relation);
}
return localizationKey != null ? PageBase.createStringResourceStatic(component, localizationKey) : Model.of("");
}
}