Skip to content

Commit 1b77be4

Browse files
authored
Merge pull request #1238 from DenverCoder544/myfeatures_attributes
handle attributes in myfeatures
2 parents 7807eae + 6626ca1 commit 1b77be4

4 files changed

Lines changed: 65 additions & 4 deletions

File tree

control-myfeatures/src/main/java/org/oskari/control/myfeatures/MyFeaturesLayerHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ public void handlePut(ActionParameters params) throws ActionException {
136136

137137
layer.setLocale(new JSONObject(updateLayer.getLocale()));
138138
layer.getLayerOptions().setDefaultFeatureStyle(new JSONObject(updateLayer.getStyle()));
139+
layer.setAttributes(new JSONObject(updateLayer.getAttributes()));
139140

140141
service.updateLayer(layer);
141142

control-myfeatures/src/main/java/org/oskari/control/myfeatures/MyFeaturesWFSHelper.java

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.oskari.control.myfeatures;
22

33
import fi.nls.oskari.annotation.Oskari;
4+
import org.json.JSONArray;
45
import org.oskari.user.User;
56

67
import fi.nls.oskari.domain.map.OskariLayer;
@@ -38,6 +39,8 @@
3839
import java.util.Collections;
3940
import java.util.Date;
4041
import java.util.List;
42+
import java.util.Map;
43+
import java.util.Optional;
4144
import java.util.UUID;
4245
import java.util.stream.Collectors;
4346

@@ -218,19 +221,60 @@ private List<FeatureProperties> getProperties(MyFeaturesLayer layer, String lang
218221
List<FeatureProperties> props = new ArrayList<>();
219222

220223
int i = 0;
224+
JSONObject attributes = layer.getAttributes();
225+
221226
for (MyFeaturesFieldInfo field : layer.getLayerFields()) {
222227
FeatureProperties p = new FeatureProperties();
223228
p.name = field.getName();
224229
p.type = field.getType().getSimpleType();
225230
p.rawType = field.getType().getOutputBinding().getName();
226-
p.label = field.getName();
227-
p.hidden = false;
228-
p.format = null;
229-
p.order = i++;
231+
p.label = getLocalizedName(field, attributes, lang);
232+
p.hidden = getHidden(field, attributes);
233+
p.format = getFieldFormat(field, attributes);
234+
p.order = getFieldOrder(field, attributes, i);
230235
props.add(p);
231236
}
232237

233238
return props;
234239
}
235240

241+
private String getLocalizedName(MyFeaturesFieldInfo field, JSONObject attributes, String lang) {
242+
JSONObject locale = Optional.ofNullable(attributes.optJSONObject("data"))
243+
.map(o -> o.optJSONObject("locale"))
244+
.map(o -> o.optJSONObject(lang, null)).orElse(null);
245+
return locale == null ? field.getName() : locale.optString(field.getName(), field.getName());
246+
}
247+
248+
private Boolean getHidden(MyFeaturesFieldInfo field, JSONObject attributes) {
249+
List<String> list = getFilter(attributes);
250+
return !list.contains(field.getName());
251+
}
252+
253+
private Map<String, Object> getFieldFormat(MyFeaturesFieldInfo field, JSONObject attributes) {
254+
JSONObject formatJSON = Optional.ofNullable(attributes.optJSONObject("data"))
255+
.map(o -> o.optJSONObject("format"))
256+
.map(o -> o.optJSONObject(field.getName())).orElse(null);
257+
return formatJSON != null ? formatJSON.toMap() : null;
258+
}
259+
260+
private List<String> getFilter(JSONObject attributes) {
261+
JSONArray filter = Optional.ofNullable(attributes.optJSONObject("data"))
262+
.map(o -> o.optJSONObject("filter"))
263+
.map(o -> o.optJSONArray("default")).orElse(null);
264+
List<String> list = filter == null
265+
? Collections.emptyList()
266+
: filter.toList().stream()
267+
.map(Object::toString)
268+
.toList();
269+
return list;
270+
}
271+
272+
private int getFieldOrder(MyFeaturesFieldInfo field, JSONObject attributes, int index) {
273+
List<String> list = getFilter(attributes);
274+
if (!list.contains(field.getName())) {
275+
return index;
276+
}
277+
278+
return list.indexOf(field.getName());
279+
}
236280
}

control-myfeatures/src/main/java/org/oskari/control/myfeatures/dto/CreateMyFeaturesLayer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class CreateMyFeaturesLayer {
1313
private List<MyFeaturesFieldInfo> layerFields;
1414
private Map<String, Map<String, Object>> locale;
1515
private Map<String, Object> style;
16+
private Map<String, Map<String, Object>> attributes;
1617

1718
public List<MyFeaturesFieldInfo> getLayerFields() {
1819
return layerFields;
@@ -52,4 +53,11 @@ public List<String> validate() {
5253
return errors;
5354
}
5455

56+
public Map<String, Map<String, Object>> getAttributes() {
57+
return attributes;
58+
}
59+
60+
public void setAttributes(Map<String, Map<String, Object>> attributes) {
61+
this.attributes = attributes;
62+
}
5563
}

control-myfeatures/src/main/java/org/oskari/control/myfeatures/dto/UpdateMyFeaturesLayer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class UpdateMyFeaturesLayer {
1414
private String id;
1515
private Map<String, Map<String, Object>> locale;
1616
private Map<String, Object> style;
17+
private Map<String, Map<String, Object>> attributes;
1718

1819
public String getId() {
1920
return id;
@@ -55,4 +56,11 @@ public List<String> validate() {
5556
return errors;
5657
}
5758

59+
public Map<String, Map<String, Object>> getAttributes() {
60+
return attributes;
61+
}
62+
63+
public void setAttributes(Map<String, Map<String, Object>> attributes) {
64+
this.attributes = attributes;
65+
}
5866
}

0 commit comments

Comments
 (0)