-
Notifications
You must be signed in to change notification settings - Fork 188
/
ExpressionWrapper.java
157 lines (139 loc) · 7.41 KB
/
ExpressionWrapper.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
/*
* Copyright (c) 2010-2019 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.gui.impl.prism;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.Nullable;
import javax.xml.namespace.QName;
/**
* Created by honchar
*/
public class ExpressionWrapper extends PrismPropertyWrapperImpl<ExpressionType> {
private QName customQName = new QName("com.evolveum.midpoint.gui","customExtenstionType");
private static final Trace LOGGER = TraceManager.getTrace(ExpressionWrapper.class);
private ConstructionType construction;
public ExpressionWrapper(@Nullable PrismContainerValueWrapper parent, PrismProperty<ExpressionType> property, ItemStatus status) {
super(parent, property, status);
PrismContainerWrapperImpl outboundContainer = (PrismContainerWrapperImpl)parent.getParent();
if (outboundContainer != null) {
PrismContainerValueWrapperImpl outboundValue = (PrismContainerValueWrapperImpl) outboundContainer.getParent();
if (outboundValue != null) {
PrismContainerWrapperImpl associationContainer = (PrismContainerWrapperImpl) outboundValue.getParent();
if (associationContainer != null) {
PrismContainerValueWrapperImpl constructionContainer = (PrismContainerValueWrapperImpl) associationContainer.getParent();
if (constructionContainer != null && constructionContainer.getRealValue() instanceof ConstructionType) {
construction = (ConstructionType) constructionContainer.getRealValue();
}
}
}
}
}
public boolean isConstructionExpression(){
PrismContainerWrapperImpl outboundContainer = getParent() != null ? (PrismContainerWrapperImpl)getParent().getParent() : null;
if (outboundContainer != null && MappingType.class.equals(outboundContainer.getCompileTimeClass())) {
PrismContainerValueWrapperImpl outboundValue = (PrismContainerValueWrapperImpl) outboundContainer.getParent();
if (outboundValue != null) {
PrismContainerWrapperImpl associationContainer = (PrismContainerWrapperImpl) outboundValue.getParent();
if (associationContainer != null &&
(ResourceObjectAssociationType.class.equals(associationContainer.getCompileTimeClass()) ||
ResourceAttributeDefinitionType.class.equals(associationContainer.getCompileTimeClass()))) {
PrismContainerValueWrapperImpl constructionContainer = (PrismContainerValueWrapperImpl) associationContainer.getParent();
if (constructionContainer != null && constructionContainer.getRealValue() instanceof ConstructionType) {
return true;
}
}
}
}
return false;
}
public boolean isAssociationExpression(){
if (!getPath().last().equals(MappingType.F_EXPRESSION.last())){
return false;
}
PrismContainerWrapperImpl outboundContainer = getParent() != null ? (PrismContainerWrapperImpl)getParent().getParent() : null;
if (outboundContainer != null && MappingType.class.equals(outboundContainer.getCompileTimeClass())) {
PrismContainerValueWrapperImpl outboundValue = (PrismContainerValueWrapperImpl) outboundContainer.getParent();
if (outboundValue != null) {
PrismContainerWrapperImpl associationContainer = (PrismContainerWrapperImpl) outboundValue.getParent();
if (associationContainer != null &&
ResourceObjectAssociationType.class.equals(associationContainer.getCompileTimeClass())) {
return true;
}
}
}
return false;
}
public boolean isAttributeExpression() {
if (!getPath().last().equals(MappingType.F_EXPRESSION.last())){
return false;
}
PrismContainerWrapperImpl outboundContainer = getParent() != null ? (PrismContainerWrapperImpl) getParent().getParent() : null;
if (outboundContainer != null && MappingType.class.equals(outboundContainer.getCompileTimeClass())) {
PrismContainerValueWrapperImpl outboundValue = (PrismContainerValueWrapperImpl) outboundContainer.getParent();
if (outboundValue != null) {
PrismContainerWrapperImpl attributeContainer = (PrismContainerWrapperImpl) outboundValue.getParent();
if (attributeContainer != null &&
ResourceAttributeDefinitionType.class.equals(attributeContainer.getCompileTimeClass())) {
return true;
}
}
}
return false;
}
public ConstructionType getConstruction() {
return construction;
}
public void setConstruction(ConstructionType construction) {
this.construction = construction;
}
@Override
public Integer getDisplayOrder() {
if (isAssociationExpression() || isAttributeExpression()) {
//todo MAX_VALUE doesn't guarantee that expression property
//will be displayed the last, as further there will be properties
//without any displayOrder displayed
return Integer.MAX_VALUE;
} else {
return super.getDisplayOrder();
}
}
@Override
public QName getTypeName() {
return customQName;
}
// @Override
// public boolean hasChanged() {
// for (ValueWrapperOld valueWrapper : getValues()) {
// ExpressionType expression = (ExpressionType) ((PrismPropertyValue) valueWrapper.getValue()).getValue();
// ExpressionType oldExpressionValue = (ExpressionType)((PrismPropertyValue)valueWrapper.getOldValue()).getValue();
// try {
// switch (valueWrapper.getStatus()) {
// case DELETED:
// return true;
// case ADDED:
// case NOT_CHANGED:
// if (ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue, prismContext) && ExpressionUtil.areAllExpressionValuesEmpty(expression, prismContext)) {
// return false;
// } else if (!ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue, prismContext) && ExpressionUtil.areAllExpressionValuesEmpty(expression, prismContext)) {
// return true;
// } else if (ExpressionUtil.areAllExpressionValuesEmpty(oldExpressionValue, prismContext) && !ExpressionUtil.areAllExpressionValuesEmpty(expression, prismContext)) {
// return true;
// } else if (valueWrapper.hasValueChanged()) {
// return true;
// }
// }
// } catch (SchemaException e) {
// LoggingUtils.logException(LOGGER, "Cannot check changes of the expression value" + expression, e);
// return false;
// }
// }
// return false;
// }
}