/
ResourceDetailsTabPanel.java
710 lines (566 loc) · 24.1 KB
/
ResourceDetailsTabPanel.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
/*
* Copyright (c) 2010-2017 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.resources;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.xml.namespace.QName;
import com.evolveum.midpoint.prism.path.ItemPath;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.util.ListModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import com.evolveum.midpoint.common.SynchronizationUtils;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchemaImpl;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.processor.ObjectClassComplexTypeDefinition;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.box.BasicInfoBoxPanel;
import com.evolveum.midpoint.web.component.box.InfoBoxPanel;
import com.evolveum.midpoint.web.component.box.InfoBoxType;
import com.evolveum.midpoint.web.component.data.BoxedTablePanel;
import com.evolveum.midpoint.web.component.data.column.ColumnTypeDto;
import com.evolveum.midpoint.web.component.data.column.ColumnUtils;
import com.evolveum.midpoint.web.component.data.column.LinkPanel;
import com.evolveum.midpoint.web.component.util.ListDataProvider;
import com.evolveum.midpoint.web.component.util.SelectableBean;
import com.evolveum.midpoint.web.page.admin.resources.dto.ResourceConfigurationDto;
import com.evolveum.midpoint.web.page.admin.server.PageTaskEdit;
import com.evolveum.midpoint.web.util.OnePageParameterEncoder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AvailabilityStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ConnectorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationalStateType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceActivationDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceAttributeDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourcePasswordDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;
public class ResourceDetailsTabPanel extends Panel {
private static final Trace LOGGER = TraceManager.getTrace(ResourceDetailsTabPanel.class);
private static final String DOT_CLASS = ResourceDetailsTabPanel.class.getName() + ".";
private static final String OPERATION_SEARCH_TASKS_FOR_RESOURCE = DOT_CLASS + "seachTasks";
public static final String ID_LAST_AVAILABILITY_STATUS = "lastStatus";
private static final String ID_SOURCE_TARGET = "sourceTarget";
private static final String ID_SCHEMA_STATUS = "schemaStatus";
private static final String PANEL_CAPABILITIES = "capabilities";
private static final long serialVersionUID = 1L;
LoadableModel<CapabilitiesDto> capabilitiesModel;
private PageBase parentPage;
public ResourceDetailsTabPanel(String id, final IModel<?> model, PageBase parentPage) {
super(id, model);
this.parentPage = parentPage;
capabilitiesModel = new LoadableModel<CapabilitiesDto>() {
private static final long serialVersionUID = 1L;
@Override
protected CapabilitiesDto load() {
PrismObject<ResourceType> resource = (PrismObject<ResourceType>) model.getObject();
return new CapabilitiesDto(resource.asObjectable());
}
};
initLayout(model, parentPage);
}
protected void initLayout(IModel model, PageBase parentPage) {
PrismObject<ResourceType> resourceObject = (PrismObject<ResourceType>) model.getObject();
ResourceType resource = resourceObject.asObjectable();
add(createLastAvailabilityStatusInfo(resource));
add(createSourceTargetInfo(resource));
add(createSchemaStatusInfo(resource));
CapabilitiesPanel capabilities = new CapabilitiesPanel(PANEL_CAPABILITIES, capabilitiesModel);
add(capabilities);
List<ResourceConfigurationDto> resourceConfigList = createResourceConfigList(resource);
ListDataProvider<ResourceConfigurationDto> resourceConfigProvider = new ListDataProvider<>(
ResourceDetailsTabPanel.this, new ListModel<>(resourceConfigList));
List<ColumnTypeDto<String>> columns = Arrays.asList(
new ColumnTypeDto<String>("ShadowType.kind", "objectTypeDefinition.kind",
ShadowType.F_KIND.getLocalPart()),
new ColumnTypeDto<String>("ShadowType.objectClass",
"objectTypeDefinition.objectClass.localPart",
ShadowType.F_OBJECT_CLASS.getLocalPart()),
new ColumnTypeDto<String>("ShadowType.intent", "objectTypeDefinition.intent",
ShadowType.F_INTENT.getLocalPart()),
new ColumnTypeDto<String>("ResourceType.isSync", "sync", null));
List<IColumn<SelectableBean<ResourceType>, String>> tableColumns = ColumnUtils.createColumns(columns);
PropertyColumn tasksColumn = new PropertyColumn(
PageBase.createStringResourceStatic(this, "ResourceType.tasks"), "definedTasks") {
@Override
public void populateItem(Item item, String componentId, final IModel rowModel) {
ResourceConfigurationDto conf = (ResourceConfigurationDto) rowModel.getObject();
RepeatingView repeater = new RepeatingView(componentId);
for (final TaskType task : conf.getDefinedTasks()) {
repeater.add(new LinkPanel(repeater.newChildId(),
new Model<>(task.getName().getOrig())) {
@Override
public void onClick(AjaxRequestTarget target) {
ResourceDetailsTabPanel.this.taskDetailsPerformed(target, task.getOid());
}
});
}
item.add(repeater);
}
};
tableColumns.add(tasksColumn);
BoxedTablePanel<ResourceConfigurationDto> resourceConfig = new BoxedTablePanel("resourceConfig",
resourceConfigProvider, tableColumns);
resourceConfig.setAdditionalBoxCssClasses("box-success");
add(resourceConfig);
}
private List<ResourceConfigurationDto> createResourceConfigList(ResourceType resource) {
OperationResult result = new OperationResult(OPERATION_SEARCH_TASKS_FOR_RESOURCE);
List<PrismObject<TaskType>> tasks = WebModelServiceUtils.searchObjects(TaskType.class,
parentPage.getPrismContext().queryFor(TaskType.class)
.item(TaskType.F_OBJECT_REF).ref(resource.getOid())
.and()
.item(TaskType.F_PARENT).isNull()
.build(),
result, parentPage);
List<ResourceConfigurationDto> configs = new ArrayList<>();
if (resource.getSchemaHandling() == null) {
return configs;
}
List<ResourceObjectTypeDefinitionType> objectTypes = resource.getSchemaHandling().getObjectType();
if (objectTypes == null) {
return configs;
}
try {
for (ResourceObjectTypeDefinitionType objectType : objectTypes) {
ObjectSynchronizationType obejctSynchronization = null;
if (resource.getSynchronization() != null
&& resource.getSynchronization().getObjectSynchronization() != null) {
obejctSynchronization = getSynchronizationFor(objectType,
resource.getSynchronization().getObjectSynchronization(),
resource.asPrismObject());
}
List<TaskType> syncTask = new ArrayList<>();
if (obejctSynchronization != null) {
syncTask = getTaskFor(tasks, obejctSynchronization, resource.asPrismObject());
}
ResourceConfigurationDto resourceConfig = new ResourceConfigurationDto(objectType,
obejctSynchronization != null, syncTask);
configs.add(resourceConfig);
}
} catch (SchemaException ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Could not determine resource configuration", ex);
}
return configs;
}
private void taskDetailsPerformed(AjaxRequestTarget target, String taskOid) {
PageParameters parameters = new PageParameters();
parameters.add(OnePageParameterEncoder.PARAMETER, taskOid);
((PageBase) getPage()).navigateToNext(PageTaskEdit.class, parameters);
}
private BasicInfoBoxPanel createSourceTargetInfo(ResourceType resource) {
String backgroundColor = "bg-aqua";
SourceTarget sourceTarget = determineIfSourceOrTarget(resource);
String numberKey = null;
switch (sourceTarget) {
case SOURCE:
numberKey = "PageResource.resource.source";
break;
case TARGET:
numberKey = "PageResource.resource.target";
break;
case SOURCE_TARGET:
numberKey = "PageResource.resource.sourceAndTarget";
break;
default:
backgroundColor = "bg-gray";
numberKey = "PageResource.resource.noMappings";
break;
}
InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, sourceTarget.getCssClass(),
parentPage.getString("PageResource.resource.mappings"));
infoBoxType.setNumber(parentPage.getString(numberKey));
if (isSynchronizationDefined(resource)) {
infoBoxType.setDescription(parentPage.getString("PageResource.resource.sync"));
}
Model<InfoBoxType> boxModel = new Model<>(infoBoxType);
return new BasicInfoBoxPanel(ID_SOURCE_TARGET, boxModel);
}
private InfoBoxPanel createLastAvailabilityStatusInfo(ResourceType resource) {
String messageKey = "PageResource.resource.availabilityUnknown";
String backgroundColor = "bg-gray";
String icon = "fa fa-question";
OperationalStateType operationalState = resource.getOperationalState();
if (operationalState != null) {
AvailabilityStatusType lastAvailabilityStatus = operationalState.getLastAvailabilityStatus();
if (lastAvailabilityStatus != null) {
if (lastAvailabilityStatus == AvailabilityStatusType.UP) {
messageKey = "PageResource.resource.up";
backgroundColor = "bg-green";
icon = "fa fa-power-off";
} else if (lastAvailabilityStatus == AvailabilityStatusType.DOWN) {
backgroundColor = "bg-red";
messageKey = "PageResource.resource.down";
icon = "fa fa-ban";
} else if (lastAvailabilityStatus == AvailabilityStatusType.BROKEN) {
backgroundColor = "bg-yellow";
messageKey = "PageResource.resource.broken";
icon = "fa fa-warning";
}
}
}
InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon, parentPage.getString(messageKey));
ConnectorType connectorType = resource.getConnector();
if (connectorType == null) {
// Connector not found. Probably bad connectorRef reference.
infoBoxType.setNumber("--");
infoBoxType.setDescription("--");
} else {
String connectorName = StringUtils.substringAfterLast(
WebComponentUtil.getEffectiveName(connectorType, ConnectorType.F_CONNECTOR_TYPE), ".");
String connectorVersion = connectorType.getConnectorVersion();
infoBoxType.setNumber(connectorName);
infoBoxType.setDescription(connectorVersion);
}
Model<InfoBoxType> boxModel = new Model<>(infoBoxType);
InfoBoxPanel lastAvailabilityStatus = new BasicInfoBoxPanel(ID_LAST_AVAILABILITY_STATUS, boxModel);
lastAvailabilityStatus.setOutputMarkupId(true);
return lastAvailabilityStatus;
}
private InfoBoxPanel createSchemaStatusInfo(ResourceType resource) {
String backgroundColor = "bg-gray";
String icon = "fa fa-times";
String numberMessage = null;
String description = null;
Integer progress = null;
RefinedResourceSchema refinedSchema = null;
try {
refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
if (refinedSchema != null) {
backgroundColor = "bg-purple";
icon = "fa fa-cubes";
int numObjectTypes = 0;
List<? extends RefinedObjectClassDefinition> refinedDefinitions = refinedSchema
.getRefinedDefinitions();
for (RefinedObjectClassDefinition refinedDefinition : refinedDefinitions) {
if (refinedDefinition.getKind() != null) {
numObjectTypes++;
}
}
int numAllDefinitions = refinedDefinitions.size();
numberMessage = numObjectTypes + " " + parentPage.getString("PageResource.resource.objectTypes");
if (numAllDefinitions != 0) {
progress = numObjectTypes * 100 / numAllDefinitions;
if (progress > 100) {
progress = 100;
}
}
description = numAllDefinitions + " " + parentPage.getString("PageResource.resource.schemaDefinitions");
} else {
numberMessage = parentPage.getString("PageResource.resource.noSchema");
}
} catch (SchemaException e) {
backgroundColor = "bg-danger";
icon = "fa fa-warning";
numberMessage = parentPage.getString("PageResource.resource.schemaError");
}
InfoBoxType infoBoxType = new InfoBoxType(backgroundColor, icon,
parentPage.getString("PageResource.resource.schema"));
infoBoxType.setNumber(numberMessage);
infoBoxType.setProgress(progress);
infoBoxType.setDescription(description);
Model<InfoBoxType> boxModel = new Model<>(infoBoxType);
return new BasicInfoBoxPanel(ID_SCHEMA_STATUS, boxModel);
}
private ObjectSynchronizationType getSynchronizationFor(
ResourceObjectTypeDefinitionType obejctTypesDefinition,
List<ObjectSynchronizationType> synchronizationPolicies, PrismObject<ResourceType> resource)
throws SchemaException {
for (ObjectSynchronizationType synchronizationPolicy : synchronizationPolicies) {
if (SynchronizationUtils.isPolicyApplicable(obejctTypesDefinition.getObjectClass(),
obejctTypesDefinition.getKind(), obejctTypesDefinition.getIntent(), synchronizationPolicy,
resource)) {
if (synchronizationPolicy.getObjectClass().isEmpty()) {
synchronizationPolicy.getObjectClass().add(obejctTypesDefinition.getObjectClass());
}
return synchronizationPolicy;
}
}
return null;
}
private List<TaskType> getTaskFor(List<PrismObject<TaskType>> tasks,
ObjectSynchronizationType synchronizationPolicy, PrismObject<ResourceType> resource)
throws SchemaException {
List<TaskType> syncTasks = new ArrayList<>();
for (PrismObject<TaskType> task : tasks) {
PrismProperty<ShadowKindType> taskKind = task
.findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_KIND));
ShadowKindType taskKindValue = null;
if (taskKind != null) {
taskKindValue = taskKind.getRealValue();
}
PrismProperty<String> taskIntent = task
.findProperty(ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_INTENT));
String taskIntentValue = null;
if (taskIntent != null) {
taskIntentValue = taskIntent.getRealValue();
}
PrismProperty<QName> taskObjectClass = task.findProperty(
ItemPath.create(TaskType.F_EXTENSION, SchemaConstants.MODEL_EXTENSION_OBJECTCLASS));
QName taskObjectClassValue = null;
if (taskObjectClass != null) {
taskObjectClassValue = taskObjectClass.getRealValue();
}
// TODO: unify with determineObjectClass in Utils (model-impl, which
// is not accessible in admin-gui)
if (taskObjectClassValue == null) {
ObjectClassComplexTypeDefinition taskObjectClassDef = null;
RefinedResourceSchema schema = RefinedResourceSchemaImpl.getRefinedSchema(resource);
if (schema == null) {
throw new SchemaException(
"No schema defined in resource. Possible configuration problem?");
}
if (taskKindValue == null && taskIntentValue == null) {
taskObjectClassDef = schema.findDefaultObjectClassDefinition(ShadowKindType.ACCOUNT);
}
if (taskKindValue != null) {
if (StringUtils.isEmpty(taskIntentValue)) {
taskObjectClassDef = schema.findDefaultObjectClassDefinition(taskKindValue);
} else {
taskObjectClassDef = schema.findObjectClassDefinition(taskKindValue, taskIntentValue);
}
}
if (taskObjectClassDef != null) {
taskObjectClassValue = taskObjectClassDef.getTypeName();
}
}
if (SynchronizationUtils.isPolicyApplicable(taskObjectClassValue, taskKindValue, taskIntentValue,
synchronizationPolicy, resource, true)) {
syncTasks.add(task.asObjectable());
}
}
return syncTasks;
}
// TODO: ####### start of move to ResourceTypeUtil ###########
private boolean isOutboundDefined(ResourceAttributeDefinitionType attr) {
return attr.getOutbound() != null
&& (attr.getOutbound().getSource() != null || attr.getOutbound().getExpression() != null);
}
private boolean isInboundDefined(ResourceAttributeDefinitionType attr) {
return attr.getInbound() != null && CollectionUtils.isNotEmpty(attr.getInbound())
&& (attr.getInbound().get(0).getTarget() != null
|| attr.getInbound().get(0).getExpression() != null);
}
private boolean isSynchronizationDefined(ResourceType resource) {
if (resource.getSynchronization() == null) {
return false;
}
if (resource.getSynchronization().getObjectSynchronization().isEmpty()) {
return false;
}
for (ObjectSynchronizationType syncType : resource.getSynchronization().getObjectSynchronization()) {
if (syncType.isEnabled() != null && !syncType.isEnabled()) {
continue;
}
if (CollectionUtils.isEmpty(syncType.getReaction())) {
continue;
}
return true;
}
return false;
}
private SourceTarget determineCredentialsMappings(ResourceType resource) {
if (resource.getSchemaHandling() != null
&& CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) {
boolean hasOutbound = false;
boolean hasInbound = false;
for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling()
.getObjectType()) {
if (hasInbound && hasOutbound) {
return SourceTarget.SOURCE_TARGET;
}
if (resourceObjectTypeDefinition.getCredentials() == null) {
continue;
}
if (resourceObjectTypeDefinition.getCredentials().getPassword() == null) {
continue;
}
ResourcePasswordDefinitionType passwordDef = resourceObjectTypeDefinition.getCredentials()
.getPassword();
if (!hasOutbound) {
hasOutbound = passwordDef.getOutbound() != null;
}
if (!hasInbound) {
hasInbound = CollectionUtils.isNotEmpty(passwordDef.getInbound());
}
}
if (hasInbound) {
return SourceTarget.SOURCE;
}
if (hasOutbound) {
return SourceTarget.TARGET;
}
}
return SourceTarget.NOT_DEFINED;
}
private SourceTarget determineActivationMappings(ResourceType resource) {
if (resource.getSchemaHandling() != null
&& CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) {
boolean hasOutbound = false;
boolean hasInbound = false;
for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling()
.getObjectType()) {
if (hasInbound && hasOutbound) {
return SourceTarget.SOURCE_TARGET;
}
if (resourceObjectTypeDefinition.getActivation() == null) {
continue;
}
if (!hasOutbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getAdministrativeStatus() != null && CollectionUtils
.isNotEmpty(activationDef.getAdministrativeStatus().getOutbound())) {
hasOutbound = true;
}
}
if (!hasOutbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getValidFrom() != null
&& CollectionUtils.isNotEmpty(activationDef.getValidFrom().getOutbound())) {
hasOutbound = true;
}
}
if (!hasOutbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getValidTo() != null
&& CollectionUtils.isNotEmpty(activationDef.getValidTo().getOutbound())) {
hasOutbound = true;
}
}
if (!hasOutbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getExistence() != null
&& CollectionUtils.isNotEmpty(activationDef.getExistence().getOutbound())) {
hasOutbound = true;
}
}
if (!hasInbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getAdministrativeStatus() != null && CollectionUtils
.isNotEmpty(activationDef.getAdministrativeStatus().getInbound())) {
hasInbound = true;
}
}
if (!hasInbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getValidFrom() != null
&& CollectionUtils.isNotEmpty(activationDef.getValidFrom().getInbound())) {
hasInbound = true;
}
}
if (!hasInbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getValidTo() != null
&& CollectionUtils.isNotEmpty(activationDef.getValidTo().getInbound())) {
hasInbound = true;
}
}
if (!hasInbound) {
ResourceActivationDefinitionType activationDef = resourceObjectTypeDefinition
.getActivation();
if (activationDef.getExistence() != null
&& CollectionUtils.isNotEmpty(activationDef.getExistence().getInbound())) {
hasInbound = true;
}
}
}
if (hasInbound) {
return SourceTarget.SOURCE;
}
if (hasOutbound) {
return SourceTarget.TARGET;
}
}
return SourceTarget.NOT_DEFINED;
}
private SourceTarget determineIfSourceOrTarget(ResourceType resource) {
if (resource.getSchemaHandling() != null
&& CollectionUtils.isNotEmpty(resource.getSchemaHandling().getObjectType())) {
boolean hasOutbound = false;
boolean hasInbound = false;
for (ResourceObjectTypeDefinitionType resourceObjectTypeDefinition : resource.getSchemaHandling()
.getObjectType()) {
if (CollectionUtils.isEmpty(resourceObjectTypeDefinition.getAttribute())) {
continue;
}
if (hasInbound && hasOutbound) {
return SourceTarget.SOURCE_TARGET;
}
for (ResourceAttributeDefinitionType attr : resourceObjectTypeDefinition.getAttribute()) {
if (hasInbound && hasOutbound) {
return SourceTarget.SOURCE_TARGET;
}
if (!hasOutbound) {
hasOutbound = isOutboundDefined(attr);
}
if (!hasInbound) {
hasInbound = isInboundDefined(attr);
}
}
// TODO: what about situation that we have only
}
if (hasOutbound) {
return SourceTarget.TARGET;
}
if (hasInbound) {
return SourceTarget.SOURCE;
}
}
return SourceTarget.NOT_DEFINED;
}
// TODO: ####### end of move to ResourceTypeUtil ###########
private enum SourceTarget {
NOT_DEFINED("fa fa-square-o"), SOURCE("fa fa-sign-in"), TARGET("fa fa-sign-out"), SOURCE_TARGET("fa fa-exchange");
private String cssClass;
SourceTarget(String cssClass) {
this.cssClass = cssClass;
}
public String getCssClass() {
return cssClass;
}
}
}