-
Notifications
You must be signed in to change notification settings - Fork 188
/
ItemValueWithOrigin.java
152 lines (133 loc) · 5.13 KB
/
ItemValueWithOrigin.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
/*
* 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.model.impl.lens;
import java.util.ArrayList;
import java.util.Collection;
import com.evolveum.midpoint.model.common.mapping.PrismValueDeltaSetTripleProducer;
import com.evolveum.midpoint.model.impl.lens.projector.ValueMatcher;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismPropertyValue;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.prism.delta.DeltaSetTriple;
import com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType;
import org.jetbrains.annotations.NotNull;
/**
* @author semancik
*
*/
public class ItemValueWithOrigin<V extends PrismValue, D extends ItemDefinition> implements DebugDumpable {
private V itemValue;
private PrismValueDeltaSetTripleProducer<V, D> mapping;
private Construction construction;
public ItemValueWithOrigin(V propertyValue,
PrismValueDeltaSetTripleProducer<V, D> mapping, Construction accountConstruction) {
super();
this.itemValue = propertyValue;
this.mapping = mapping;
this.construction = accountConstruction;
}
// the same as above, but with correct name
public V getItemValue() {
return itemValue;
}
// use with care
public void setItemValue(V value) {
this.itemValue = value;
}
public PrismValueDeltaSetTripleProducer<V, D> getMapping() {
return mapping;
}
public Construction getConstruction() {
return construction;
}
public ObjectType getSource() {
return construction != null ? construction.getSource() : null;
}
public boolean isValid() {
return construction == null || construction.isValid();
}
public boolean wasValid() {
return construction == null || construction.getWasValid();
}
public <T> boolean equalsRealValue(V pvalue, ValueMatcher<T> valueMatcher) throws SchemaException {
if (itemValue == null) {
return false;
}
if (valueMatcher == null) {
return itemValue.equalsRealValue(pvalue);
} else {
// this must be a property, otherwise there would be no matcher
return valueMatcher.match(((PrismPropertyValue<T>)itemValue).getValue(),
((PrismPropertyValue<T>)pvalue).getValue());
}
}
public ItemValueWithOrigin<V,D> clone() {
ItemValueWithOrigin<V,D> clone = new ItemValueWithOrigin<>(itemValue, mapping, construction);
copyValues(clone);
return clone;
}
protected void copyValues(ItemValueWithOrigin<V,D> clone) {
if (this.itemValue != null) {
clone.itemValue = (V) this.itemValue.clone();
}
if (this.mapping != null) {
clone.mapping = this.mapping.clone();
}
clone.construction = this.construction;
}
public static <V extends PrismValue, D extends ItemDefinition> DeltaSetTriple<ItemValueWithOrigin<V,D>> createOutputTriple(PrismValueDeltaSetTripleProducer<V, D> mapping) {
PrismValueDeltaSetTriple<V> outputTriple = mapping.getOutputTriple();
if (outputTriple == null) {
return null;
}
Collection<ItemValueWithOrigin<V,D>> zeroIvwoSet = convertSet(outputTriple.getZeroSet(), mapping);
Collection<ItemValueWithOrigin<V,D>> plusIvwoSet = convertSet(outputTriple.getPlusSet(), mapping);
Collection<ItemValueWithOrigin<V,D>> minusIvwoSet = convertSet(outputTriple.getMinusSet(), mapping);
DeltaSetTriple<ItemValueWithOrigin<V,D>> ivwoTriple = new DeltaSetTriple<>(zeroIvwoSet, plusIvwoSet, minusIvwoSet);
return ivwoTriple;
}
@NotNull
private static <V extends PrismValue, D extends ItemDefinition> Collection<ItemValueWithOrigin<V,D>> convertSet(
@NotNull Collection<V> valueSet, PrismValueDeltaSetTripleProducer<V, D> mapping) {
Collection<ItemValueWithOrigin<V,D>> ivwoSet = new ArrayList<>(valueSet.size());
for (V value: valueSet) {
ItemValueWithOrigin<V,D> ivwo = new ItemValueWithOrigin<>(value, mapping, null);
ivwoSet.add(ivwo);
}
return ivwoSet;
}
@Override
public String debugDump(int indent) {
StringBuilder sb = new StringBuilder();
DebugUtil.indentDebugDump(sb, indent);
sb.append("ItemValueWithOrigin:\n");
DebugUtil.debugDumpWithLabel(sb, "itemValue", itemValue, indent +1);
sb.append("\n");
DebugUtil.debugDumpWithLabelToString(sb, "mapping", mapping, indent +1);
sb.append("\n");
DebugUtil.debugDumpWithLabelToString(sb, "construction", construction, indent +1);
return sb.toString();
}
@Override
public String toString() {
return "ItemValueWithOrigin(" + itemValue + ", M="
+ mapping + ", C=" + construction + ")";
}
}