9074
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.artifacts.states; |
|
11 |
|
12 import java.util.ArrayList; |
|
13 import java.util.HashMap; |
|
14 import java.util.List; |
|
15 import java.util.Map; |
|
16 import java.util.Map.Entry; |
|
17 |
|
18 import org.dive4elements.artifacts.CallMeta; |
|
19 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; |
|
20 import org.dive4elements.river.artifacts.resources.Resources; |
|
21 import org.w3c.dom.Element; |
|
22 |
|
23 /** |
|
24 * @author Domenico Nardi Tironi |
|
25 * |
|
26 */ |
|
27 public class AddTableDataHelper { |
|
28 |
|
29 private final ElementCreator creator; |
|
30 private final Element select; |
|
31 private final CallMeta callmeta; |
|
32 // Create Metadata: |
|
33 final Map<String, Map<String, String>> meta = new HashMap<>(); |
|
34 final List<String> columnValidList = new ArrayList<>(); |
|
35 |
|
36 public AddTableDataHelper(final ElementCreator creator, final Element select, final String pinKeyColumn, final CallMeta callMeta) { |
|
37 this.creator = creator; |
|
38 this.select = select; |
|
39 this.callmeta = callMeta; |
|
40 creator.addAttr(select, "type", "multiattribute", true); |
|
41 |
|
42 final Map<String, String> metaTableInfo = new HashMap<>(); |
|
43 metaTableInfo.put("keycol", pinKeyColumn); |
|
44 this.meta.put("meta_tableinfo", metaTableInfo); |
|
45 |
|
46 } |
|
47 |
|
48 public void submitMapToXml() { |
|
49 |
|
50 final Element meta = this.creator.create("meta"); |
|
51 |
|
52 for (final Entry<String, Map<String, String>> entry : this.meta.entrySet()) { |
|
53 final String name = entry.getKey(); // z.B. Spaltenname |
|
54 final Map<String, String> keyValueMap = entry.getValue(); |
|
55 final Element element = this.creator.create(name); |
|
56 |
|
57 for (final Entry<String, String> kventry : keyValueMap.entrySet()) { |
|
58 this.creator.addAttr(element, kventry.getKey(), kventry.getValue()); |
|
59 } |
|
60 meta.appendChild(element); |
|
61 } |
|
62 |
|
63 this.select.appendChild(meta); |
|
64 |
|
65 } |
|
66 |
|
67 public void addRow(final Map<String, String> colValMap) throws Exception { |
|
68 |
|
69 final Element item = this.creator.create("item"); |
|
70 |
|
71 for (final Entry<String, String> entry : colValMap.entrySet()) { |
|
72 if (this.meta.containsKey(entry.getKey())) { |
|
73 this.creator.addAttr(item, entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : ""); |
|
74 } else { |
|
75 throw new Exception("Error: No such column " + entry.getKey()); |
|
76 } |
|
77 } |
|
78 this.select.appendChild(item); |
|
79 } |
|
80 |
|
81 public void addColumn(final int order, final String rootHashmapKey, final String colWidth, final String translationKeyFromMessages, final String type, |
|
82 final String alignment, final String pinType) { |
|
83 |
|
84 final Map<String, String> map = new HashMap<>(); |
|
85 map.put("colwidth", colWidth); |
|
86 final String translation = Resources.getMsg(this.callmeta, translationKeyFromMessages); |
|
87 map.put("translation", translation); |
|
88 map.put("type", type); |
|
89 map.put("alignment", alignment); |
|
90 map.put("order", Integer.toString(order)); |
|
91 map.put("pin", pinType); |
|
92 this.meta.put(rootHashmapKey, map); |
|
93 |
|
94 } |
|
95 |
|
96 } |