| ... |
... |
@@ -37,12 +37,17 @@ import org.nuiton.eugene.models.object.ObjectModelClass; |
|
37
|
37
|
import org.nuiton.eugene.models.object.ObjectModelPackage;
|
|
38
|
38
|
import org.nuiton.eugene.models.object.xml.ObjectModelAttributeImpl;
|
|
39
|
39
|
|
|
|
40
|
+import java.io.BufferedWriter;
|
|
40
|
41
|
import java.io.File;
|
|
41
|
42
|
import java.io.IOException;
|
|
|
43
|
+import java.nio.charset.StandardCharsets;
|
|
|
44
|
+import java.nio.file.Path;
|
|
42
|
45
|
import java.util.Comparator;
|
|
43
|
46
|
import java.util.LinkedList;
|
|
44
|
47
|
import java.util.List;
|
|
|
48
|
+import java.util.Map;
|
|
45
|
49
|
import java.util.Objects;
|
|
|
50
|
+import java.util.TreeMap;
|
|
46
|
51
|
|
|
47
|
52
|
/**
|
|
48
|
53
|
* Created on 24/01/2021.
|
| ... |
... |
@@ -72,6 +77,7 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
72
|
77
|
augmentsTagValues(model, all, observeTagValues);
|
|
73
|
78
|
consolidateModel(model, all, observeTagValues, getLog());
|
|
74
|
79
|
augmentsTagValuesFinal(model, all, observeTagValues);
|
|
|
80
|
+ extractTagValues(allWithAbstract);
|
|
75
|
81
|
return true;
|
|
76
|
82
|
}
|
|
77
|
83
|
|
| ... |
... |
@@ -81,17 +87,18 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
81
|
87
|
String mainDtoTagValue = observeTagValues.getMainDtoTagValue(aClass);
|
|
82
|
88
|
if (observeTagValues.notSkip(mainDtoTagValue) != null) {
|
|
83
|
89
|
String newValue = aPackage.getName() + "." + mainDtoTagValue + "Dto";
|
|
84
|
|
- getLog().info(String.format("Augments tag value %s.mainDto=%s", aClass.getQualifiedName(), newValue));
|
|
|
90
|
+ getLog().debug(String.format("Augments tag value %s.mainDto=%s", aClass.getQualifiedName(), newValue));
|
|
85
|
91
|
aClass.getTagValues().put(ObserveTagValues.Store.mainDto.name(), newValue);
|
|
86
|
92
|
}
|
|
87
|
93
|
String formTagValue = observeTagValues.getFormTagValue(aClass, aPackage);
|
|
88
|
94
|
if (observeTagValues.notSkip(formTagValue) != null && !Objects.equals("self", formTagValue)) {
|
|
89
|
95
|
String newValue = aPackage.getName() + "." + formTagValue + "Dto";
|
|
90
|
|
- getLog().info(String.format("Augments tag value %s.form=%s", aClass.getQualifiedName(), newValue));
|
|
|
96
|
+ getLog().debug(String.format("Augments tag value %s.form=%s", aClass.getQualifiedName(), newValue));
|
|
91
|
97
|
aClass.getTagValues().put(ObserveTagValues.Store.form.name(), newValue);
|
|
92
|
98
|
}
|
|
93
|
99
|
}
|
|
94
|
100
|
}
|
|
|
101
|
+
|
|
95
|
102
|
protected void augmentsReferences(BeanTransformerContext all, String packageName) {
|
|
96
|
103
|
for (ObjectModelClass aClass : all.selectedClasses) {
|
|
97
|
104
|
for (ObjectModelAttribute attribute : aClass.getAttributes()) {
|
| ... |
... |
@@ -99,9 +106,8 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
99
|
106
|
if (!attributeType.startsWith(packageName) && attributeType.endsWith("Reference")) {
|
|
100
|
107
|
// add full package
|
|
101
|
108
|
String newValue = packageName + "." + attributeType;
|
|
102
|
|
- getLog().info(String.format("Augments reference attribute value %s.%s=%s", aClass.getQualifiedName(),attribute.getName(), newValue));
|
|
103
|
|
- ((ObjectModelAttributeImpl)attribute).setType(newValue);
|
|
104
|
|
-
|
|
|
109
|
+ getLog().debug(String.format("Augments reference attribute value %s.%s=%s", aClass.getQualifiedName(), attribute.getName(), newValue));
|
|
|
110
|
+ ((ObjectModelAttributeImpl) attribute).setType(newValue);
|
|
105
|
111
|
}
|
|
106
|
112
|
}
|
|
107
|
113
|
}
|
| ... |
... |
@@ -113,13 +119,13 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
113
|
119
|
String formTagValue = observeTagValues.getFormTagValue(aClass, aPackage);
|
|
114
|
120
|
if (Objects.equals("self", formTagValue)) {
|
|
115
|
121
|
String newValue = aClass.getQualifiedName() + "Dto";
|
|
116
|
|
- getLog().info(String.format("Augments tag value %s.form=%s", aClass.getQualifiedName(), newValue));
|
|
|
122
|
+ getLog().debug(String.format("Augments tag value %s.form=%s", aClass.getQualifiedName(), newValue));
|
|
117
|
123
|
aClass.getTagValues().put(ObserveTagValues.Store.form.name(), newValue);
|
|
118
|
124
|
}
|
|
119
|
125
|
String mainDtoTagValue = observeTagValues.getMainDtoTagValue(aClass);
|
|
120
|
126
|
if (mainDtoTagValue == null) {
|
|
121
|
127
|
String newValue = aClass.getQualifiedName() + "Dto";
|
|
122
|
|
- getLog().info(String.format("Augments tag value %s.mainDto=%s", aClass.getQualifiedName(), newValue));
|
|
|
128
|
+ getLog().debug(String.format("Augments tag value %s.mainDto=%s", aClass.getQualifiedName(), newValue));
|
|
123
|
129
|
aClass.getTagValues().put(ObserveTagValues.Store.mainDto.name(), newValue);
|
|
124
|
130
|
}
|
|
125
|
131
|
}
|
| ... |
... |
@@ -136,12 +142,11 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
136
|
142
|
String mainDtoTagValue = observeTagValues.getMainDtoTagValue(aClass);
|
|
137
|
143
|
String formTagValue = observeTagValues.getFormTagValue(aClass, aPackage);
|
|
138
|
144
|
if (mainDtoTagValue == null && (formTagValue == null || Objects.equals("self", formTagValue))) {
|
|
139
|
|
- log.info(String.format("found ContainerDto without any tagValues, add convention tagValues: %s", aClass.getQualifiedName()));
|
|
|
145
|
+ log.debug(String.format("found ContainerDto without any tagValues, add convention tagValues: %s", aClass.getQualifiedName()));
|
|
140
|
146
|
ObjectModelClass childType = guessChildType(all.selectedClasses, aClass);
|
|
141
|
|
- log.info(String.format("add tag value %s.form=%s", aClass.getQualifiedName(), childType.getQualifiedName()) + "Dto");
|
|
|
147
|
+ log.debug(String.format("add tag value %s.form=%s", aClass.getQualifiedName(), childType.getQualifiedName()) + "Dto");
|
|
142
|
148
|
ObjectModelClass mainType = guessMainType(all.selectedClasses, aClass, childType);
|
|
143
|
|
- log.info(String.format("add tag value %s.mainDto=%s", aClass.getQualifiedName(), mainType.getQualifiedName()) + "Dto");
|
|
144
|
|
-
|
|
|
149
|
+ log.debug(String.format("add tag value %s.mainDto=%s", aClass.getQualifiedName(), mainType.getQualifiedName()) + "Dto");
|
|
145
|
150
|
aClass.getTagValues().put(ObserveTagValues.Store.form.name(), childType.getQualifiedName() + "Dto");
|
|
146
|
151
|
aClass.getTagValues().put(ObserveTagValues.Store.mainDto.name(), mainType.getQualifiedName() + "Dto");
|
|
147
|
152
|
}
|
| ... |
... |
@@ -163,9 +168,7 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
163
|
168
|
continue;
|
|
164
|
169
|
}
|
|
165
|
170
|
if (name.endsWith(selectedClass.getName())) {
|
|
166
|
|
- if (candidates.isEmpty()) {
|
|
167
|
|
- candidates.add(selectedClass);
|
|
168
|
|
- } else {
|
|
|
171
|
+ if (!candidates.isEmpty()) {
|
|
169
|
172
|
ObjectModelClass objectModelClass = candidates.get(0);
|
|
170
|
173
|
if (selectedClass.getName().endsWith(objectModelClass.getName())) {
|
|
171
|
174
|
candidates.remove(0);
|
| ... |
... |
@@ -173,8 +176,8 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
173
|
176
|
// not keeping this one
|
|
174
|
177
|
continue;
|
|
175
|
178
|
}
|
|
176
|
|
- candidates.add(selectedClass);
|
|
177
|
179
|
}
|
|
|
180
|
+ candidates.add(selectedClass);
|
|
178
|
181
|
}
|
|
179
|
182
|
}
|
|
180
|
183
|
if (candidates.isEmpty()) {
|
| ... |
... |
@@ -184,8 +187,8 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
184
|
187
|
// only one candidate, found it!
|
|
185
|
188
|
return candidates.get(0);
|
|
186
|
189
|
}
|
|
187
|
|
- candidates.sort(Comparator.comparing(ObjectModelClass::getQualifiedName, Comparator.comparingInt(String::length)).reversed());
|
|
188
|
190
|
// should take the biggest matching candidate ?
|
|
|
191
|
+ candidates.sort(Comparator.comparing(ObjectModelClass::getQualifiedName, Comparator.comparingInt(String::length)).reversed());
|
|
189
|
192
|
return candidates.get(0);
|
|
190
|
193
|
}
|
|
191
|
194
|
|
| ... |
... |
@@ -215,6 +218,31 @@ public abstract class DtoMetaTransformer extends AbstractMetaTransformer<ObjectM |
|
215
|
218
|
return candidates.get(0);
|
|
216
|
219
|
}
|
|
217
|
220
|
// should take the smallest matching candidate ?
|
|
|
221
|
+ candidates.sort(Comparator.comparing(ObjectModelClass::getQualifiedName, Comparator.comparingInt(String::length)).reversed());
|
|
218
|
222
|
return candidates.get(0);
|
|
219
|
223
|
}
|
|
|
224
|
+
|
|
|
225
|
+
|
|
|
226
|
+ protected void extractTagValues(BeanTransformerContext all) {
|
|
|
227
|
+ Map<String, String> p = new TreeMap<>();
|
|
|
228
|
+ for (ObjectModelClass aClass : all.selectedClasses) {
|
|
|
229
|
+ String tagValuePrefix = aClass.getQualifiedName() + ".attribute.";
|
|
|
230
|
+ for (ObjectModelAttribute attribute : aClass.getAttributes()) {
|
|
|
231
|
+ String tagValuePrefix2 = tagValuePrefix + attribute.getName() + ".tagValue.";
|
|
|
232
|
+ Map<String, String> tagValues1 = attribute.getTagValues();
|
|
|
233
|
+ tagValues1.forEach((k, v) -> p.put(tagValuePrefix2 + k, v));
|
|
|
234
|
+ }
|
|
|
235
|
+ }
|
|
|
236
|
+ File outputDir = getConfiguration().getProperty(PROP_OUTPUT_DIRECTORY, File.class);
|
|
|
237
|
+ Path path = outputDir.toPath().resolve("extracted-tagValues.properties");
|
|
|
238
|
+ getLog().info(String.format("Generated all tag-values in %s", path));
|
|
|
239
|
+ try (BufferedWriter writer = java.nio.file.Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
|
|
|
240
|
+ for (String k : p.keySet()) {
|
|
|
241
|
+ writer.write(String.format("%s=%s", k, p.get(k)));
|
|
|
242
|
+ writer.newLine();
|
|
|
243
|
+ }
|
|
|
244
|
+ } catch (IOException e) {
|
|
|
245
|
+ throw new IllegalStateException("Can't write " + path, e);
|
|
|
246
|
+ }
|
|
|
247
|
+ }
|
|
220
|
248
|
}
|