-
Notifications
You must be signed in to change notification settings - Fork 188
/
SearchItem.java
166 lines (131 loc) · 4.73 KB
/
SearchItem.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
/*
* Copyright (c) 2010-2015 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.web.component.search;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismReferenceDefinition;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.DisplayableValue;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.wicket.model.StringResourceModel;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
/**
* @author Viliam Repan (lazyman)
*/
public class SearchItem<T extends Serializable> implements Serializable {
public static final String F_VALUES = "values";
public enum Type {
TEXT, BOOLEAN, ENUM, BROWSER, REFERENCE
}
private Search search;
private ItemPath path;
private ItemDefinition definition;
private DisplayableValue<T> value;
//TODO: think about dividing searchItem to searchProperty, searchReference?
private List<QName> allowedRelations;
private boolean fixed;
private boolean editWhenVisible;
public SearchItem(Search search, ItemPath path, ItemDefinition definition, List<QName> allowedRelations) {
Validate.notNull(path, "Item path must not be null.");
Validate.notNull(definition, "Item definition must not be null.");
if (!(definition instanceof PrismPropertyDefinition)
&& !(definition instanceof PrismReferenceDefinition)) {
throw new IllegalArgumentException("Unknown item definition type '" + definition + "'");
}
this.search = search;
this.path = path;
this.definition = definition;
this.allowedRelations = allowedRelations;
}
public ItemPath getPath() {
return path;
}
public ItemDefinition getDefinition() {
return definition;
}
public String getName() {
String key = definition.getDisplayName();
if (StringUtils.isEmpty(key)) {
StringBuilder sb = new StringBuilder();
sb.append(search.getType().getSimpleName()).append('.').append(definition.getItemName().getLocalPart());
key = sb.toString();
}
StringResourceModel nameModel = PageBase.createStringResourceStatic(null, key);
if (nameModel != null){
if (StringUtils.isNotEmpty(nameModel.getString())) {
return nameModel.getString();
}
}
String name = definition.getDisplayName();
if (StringUtils.isNotEmpty(name)) {
return name;
}
return definition.getItemName().getLocalPart();
}
public Type getType() {
if (definition instanceof PrismReferenceDefinition) {
return Type.REFERENCE;
}
PrismPropertyDefinition def = (PrismPropertyDefinition) definition;
if (def.getAllowedValues() != null && !def.getAllowedValues().isEmpty()) {
return Type.ENUM;
}
if (DOMUtil.XSD_BOOLEAN.equals(def.getTypeName())) {
return Type.BOOLEAN;
}
return Type.TEXT;
}
public DisplayableValue<T> getValue() {
return value;
}
public void setValue(DisplayableValue<T> value) {
this.value = value;
}
public Search getSearch() {
return search;
}
public List<DisplayableValue<T>> getAllowedValues() {
List<DisplayableValue<T>> list = new ArrayList<>();
if (!(definition instanceof PrismPropertyDefinition)) {
return list;
}
PrismPropertyDefinition<T> def = (PrismPropertyDefinition<T>) definition;
list.addAll(def.getAllowedValues());
return list;
}
public boolean isFixed() {
return fixed;
}
public void setFixed(boolean fixed) {
this.fixed = fixed;
}
public boolean isEditWhenVisible() {
return editWhenVisible;
}
public void setEditWhenVisible(boolean editWhenVisible) {
this.editWhenVisible = editWhenVisible;
}
public List<QName> getAllowedRelations() {
return allowedRelations;
}
@Override
public String toString() {
return new ToStringBuilder(this)
.append("definition", definition)
.append("search", search)
.append("path", path)
.append("value", value)
.toString();
}
}