Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🐛 Patch 1.0.1 #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
SaifJerbi merged 3 commits into master from patch-1.0.1
Mar 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Inherited Form Fields #78
expected behavior : The form definition contains the inherited fields
fix #78 
  • Loading branch information
Saif Eddine Jerbi committed Mar 12, 2018
commit 370e60973ed23814c4133e6c0abd0e48b1a19fdc
19 changes: 12 additions & 7 deletions src/main/java/io/asfjava/ui/core/schema/UiFormSchemaGenerator.java
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
Expand All @@ -12,9 +13,12 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import org.reflections.ReflectionUtils;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -43,7 +47,8 @@ public final class UiFormSchemaGenerator {
private static UiFormSchemaGenerator instance;

public UiForm generate(Class<? extends Serializable> formDto) throws JsonMappingException {
Field[] declaredFields = formDto.getDeclaredFields();
Set<Field> declaredFields = ReflectionUtils.getAllFields(formDto,
field -> !Modifier.isStatic(field.getModifiers()));
ObjectMapper mapper = new ObjectMapper();

JsonSchemaGenerator schemaGen = initSchemaGen(mapper);
Expand Down Expand Up @@ -105,13 +110,13 @@ private ObjectNode buildActionNode(ObjectMapper mapper, Action action) {
return node;
}

private ObjectNode handlerGroupedFields(ObjectMapper mapper, Field[] declaredFields,
private ObjectNode handlerGroupedFields(ObjectMapper mapper, Set<Field> declaredFields,
Map<Field, JsonNode> sortedNodes) {
Predicate<? super Field> checkFieldSetAnnotation = field -> field.isAnnotationPresent(FieldSet.class);

Map<String, List<JsonNode>> groupedFields = new LinkedHashMap<>();

Arrays.stream(declaredFields).filter(checkFieldSetAnnotation)
declaredFields.stream().filter(checkFieldSetAnnotation)
.forEach(field -> groupFieldsByTab(sortedNodes, field, groupedFields));

ArrayNode groups = mapper.createArrayNode();
Expand All @@ -123,7 +128,7 @@ private ObjectNode handlerGroupedFields(ObjectMapper mapper, Field[] declaredFie

}

private ObjectNode handleTabbedFields(ObjectMapper mapper, Field[] declaredFields, Map<Field, JsonNode> nodes) {
private ObjectNode handleTabbedFields(ObjectMapper mapper, Set<Field> declaredFields, Map<Field, JsonNode> nodes) {
Predicate<? super Field> checkTabAnnotation = field -> field.isAnnotationPresent(Tab.class);

Comparator<? super Field> tabIndexComparator = (field1, field2) -> Integer
Expand All @@ -138,7 +143,7 @@ private ObjectNode handleTabbedFields(ObjectMapper mapper, Field[] declaredField

Map<String, List<JsonNode>> groupedFieldsByTab = new LinkedHashMap<>();

Arrays.stream(declaredFields).filter(checkTabAnnotation).sorted(fieldIndexComparator).sorted(tabIndexComparator)
declaredFields.stream().filter(checkTabAnnotation).sorted(fieldIndexComparator).sorted(tabIndexComparator)
.forEach(field -> groupFieldsByTab(nodes, field, groupedFieldsByTab));

ArrayNode tabs = mapper.createArrayNode();
Expand All @@ -161,10 +166,10 @@ private ObjectNode handleTabbedFields(ObjectMapper mapper, Field[] declaredField

}

private Map<Field, JsonNode> initFieldsFormDefinition(ObjectMapper mapper, Field[] declaredFields) {
private Map<Field, JsonNode> initFieldsFormDefinition(ObjectMapper mapper, Set<Field> declaredFields) {
Map<Field, JsonNode> nodes = new HashMap<>();

Arrays.stream(declaredFields).forEach(field -> buildFormDefinition(nodes, mapper, field));
declaredFields.forEach(field -> buildFormDefinition(nodes, mapper, field));

return nodes;
}
Expand Down

AltStyle によって変換されたページ (->オリジナル) /