33
33
34
34
public final class UiFormSchemaGenerator {
35
35
36
+ private static final String KEY_FIELDSET = "fieldset" ;
37
+ private static final String KEY_ON_CLICK = "onClick" ;
38
+ private static final String KEY_ACTIONS = "actions" ;
39
+ private static final String KEY_TABS = "tabs" ;
40
+ private static final String KEY_TITLE = "title" ;
41
+ private static final String KEY_TYPE = "type" ;
42
+ private static final String KEY_ITEMS = "items" ;
36
43
private static UiFormSchemaGenerator instance ;
37
44
38
45
public UiForm generate (Class <? extends Serializable > formDto ) throws JsonMappingException {
@@ -78,23 +85,23 @@ private void buildGroupedActions(ObjectMapper mapper, Class<? extends Serializab
78
85
ArrayNode formDefinition ) {
79
86
Optional <ActionsGroup > actionsAnnotation = Optional .ofNullable (formDto .getAnnotation (ActionsGroup .class ));
80
87
actionsAnnotation .ifPresent (actions -> {
81
- actionsNode .put ("type" , "actions" );
88
+ actionsNode .put (KEY_TYPE , KEY_ACTIONS );
82
89
ArrayNode items = mapper .createArrayNode ();
83
90
Arrays .stream (actions .value ()).forEach (action -> {
84
91
ObjectNode node = buildActionNode (mapper , action );
85
92
items .add (node );
86
93
});
87
- actionsNode .set ("items" , items );
94
+ actionsNode .set (KEY_ITEMS , items );
88
95
89
96
formDefinition .add (actionsNode );
90
97
});
91
98
}
92
99
93
100
private ObjectNode buildActionNode (ObjectMapper mapper , Action action ) {
94
101
ObjectNode node = mapper .createObjectNode ();
95
- node .put ("type" , action .type ());
96
- node .put ("title" , action .title ());
97
- node .put ("onClick" , action .onClick ());
102
+ node .put (KEY_TYPE , action .type ());
103
+ node .put (KEY_TITLE , action .title ());
104
+ node .put (KEY_ON_CLICK , action .onClick ());
98
105
return node ;
99
106
}
100
107
@@ -110,8 +117,8 @@ private ObjectNode handlerGroupedFields(ObjectMapper mapper, Field[] declaredFie
110
117
ArrayNode groups = mapper .createArrayNode ();
111
118
112
119
ObjectNode tabsNode = mapper .createObjectNode ();
113
- tabsNode .put ("type" , "fieldset" );
114
- tabsNode .set ("items" , groups );
120
+ tabsNode .put (KEY_TYPE , KEY_FIELDSET );
121
+ tabsNode .set (KEY_ITEMS , groups );
115
122
return tabsNode ;
116
123
117
124
}
@@ -138,16 +145,16 @@ private ObjectNode handleTabbedFields(ObjectMapper mapper, Field[] declaredField
138
145
139
146
groupedFieldsByTab .entrySet ().stream ().forEachOrdered (tabElements -> {
140
147
ObjectNode tabNode = mapper .createObjectNode ();
141
- tabNode .put ("title" , tabElements .getKey ());
148
+ tabNode .put (KEY_TITLE , tabElements .getKey ());
142
149
ArrayNode tabItems = mapper .createArrayNode ();
143
150
tabElements .getValue ().stream ().forEach (tabItems ::add );
144
- tabNode .set ("items" , tabItems );
151
+ tabNode .set (KEY_ITEMS , tabItems );
145
152
tabs .add (tabNode );
146
153
});
147
154
if (tabs .size () > 0 ) {
148
155
ObjectNode tabsNode = mapper .createObjectNode ();
149
- tabsNode .put ("type" , "tabs" );
150
- tabsNode .set ("tabs" , tabs );
156
+ tabsNode .put (KEY_TYPE , KEY_TABS );
157
+ tabsNode .set (KEY_TABS , tabs );
151
158
return tabsNode ;
152
159
}
153
160
return null ;
0 commit comments