|
13 | 13 | import java.util.Map.Entry;
|
14 | 14 | import java.util.Optional;
|
15 | 15 | import java.util.function.Predicate;
|
16 |
| -import java.util.stream.Collectors; |
17 | 16 |
|
18 | 17 | import com.fasterxml.jackson.annotation.JsonIgnore;
|
19 | 18 | import com.fasterxml.jackson.databind.JsonMappingException;
|
@@ -62,25 +61,21 @@ public UiForm generate(Class<? extends Serializable> formDto) throws JsonMapping
|
62 | 61 |
|
63 | 62 | ArrayNode formDefinition = mapper.createArrayNode();
|
64 | 63 | tabbedFields.ifPresent(formDefinition::add);
|
65 |
| - sortedNodes.entrySet().stream().forEach(nodesElement -> formDefinition.add(nodesElement.getValue())); |
66 |
| - |
67 |
| - if (formDto.getDeclaredAnnotation(DisplayAllFields.class) != null) { |
68 |
| - // check if fields is not handled and haven't jackson json ignore annotation |
69 |
| - List<Field> unannotatedFiedls = Arrays.stream(declaredFields) |
70 |
| - .filter(field -> !nodes.containsKey(field) && !field.isAnnotationPresent(JsonIgnore.class)) |
71 |
| - .collect(Collectors.toList()); |
72 |
| - handleUnAnnotatedFields(formDefinition, unannotatedFiedls); |
73 |
| - } |
| 64 | + |
| 65 | + sortedNodes.entrySet().stream().forEach(nodesElement -> { |
| 66 | + if (nodesElement.getValue() != null) { |
| 67 | + formDefinition.add(nodesElement.getValue()); |
| 68 | + } else if (formDto.getDeclaredAnnotation(DisplayAllFields.class) != null) { |
| 69 | + // if no definition it must be added as key to the form definition |
| 70 | + formDefinition.add(nodesElement.getKey().getName()); |
| 71 | + } |
| 72 | + }); |
74 | 73 |
|
75 | 74 | handleActionsAnnotation(mapper, formDto, formDefinition);
|
76 | 75 |
|
77 | 76 | return new UiForm(schema, formDefinition);
|
78 | 77 | }
|
79 | 78 |
|
80 |
| - private void handleUnAnnotatedFields(ArrayNode formDefinition, List<Field> unannotatedFiedls) { |
81 |
| - unannotatedFiedls.stream().forEach(field -> formDefinition.add(field.getName())); |
82 |
| - } |
83 |
| - |
84 | 79 | private void handleActionsAnnotation(ObjectMapper mapper, Class<? extends Serializable> formDto,
|
85 | 80 | ArrayNode formDefinition) {
|
86 | 81 | ObjectNode groupedActionsNode = mapper.createObjectNode();
|
@@ -180,6 +175,12 @@ private Map<Field, JsonNode> initFieldsFormDefinition(ObjectMapper mapper, Field
|
180 | 175 |
|
181 | 176 | Arrays.stream(declaredFields).forEach(field -> buildFormDefinition(nodes, mapper, field));
|
182 | 177 |
|
| 178 | + // check if fields is not handled and haven't jackson json ignore annotation it |
| 179 | + // must be added |
| 180 | + Arrays.stream(declaredFields) |
| 181 | + .filter(field -> !nodes.containsKey(field) && !field.isAnnotationPresent(JsonIgnore.class)) |
| 182 | + .forEach(field -> nodes.put(field, null)); |
| 183 | + |
183 | 184 | return nodes;
|
184 | 185 | }
|
185 | 186 |
|
@@ -229,9 +230,9 @@ private Map<Field, JsonNode> reorderFieldsBasedOnIndex(Map<Field, JsonNode> node
|
229 | 230 | field2Index != null ? field2Index.value() : Integer.MAX_VALUE);
|
230 | 231 | };
|
231 | 232 |
|
232 |
| - return nodes.entrySet().stream().sorted(tabIndexComparator).collect(Collectors.toMap(Map.Entry::getKey, |
233 |
| - Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new)); |
234 |
| - |
| 233 | + return nodes.entrySet().stream().sorted(tabIndexComparator).collect(LinkedHashMap::new, |
| 234 | + (result, currentElement) -> result.put(currentElement.getKey(), currentElement.getValue()), |
| 235 | + Map::putAll); |
235 | 236 | }
|
236 | 237 |
|
237 | 238 | public static UiFormSchemaGenerator get() {
|
|
0 commit comments