3333
3434public final class UiFormSchemaGenerator {
3535
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" ;
3643 private static UiFormSchemaGenerator instance ;
3744
3845 public UiForm generate (Class <? extends Serializable > formDto ) throws JsonMappingException {
@@ -78,23 +85,23 @@ private void buildGroupedActions(ObjectMapper mapper, Class<? extends Serializab
7885 ArrayNode formDefinition ) {
7986 Optional <ActionsGroup > actionsAnnotation = Optional .ofNullable (formDto .getAnnotation (ActionsGroup .class ));
8087 actionsAnnotation .ifPresent (actions -> {
81- actionsNode .put ("type" , "actions" );
88+ actionsNode .put (KEY_TYPE , KEY_ACTIONS );
8289 ArrayNode items = mapper .createArrayNode ();
8390 Arrays .stream (actions .value ()).forEach (action -> {
8491 ObjectNode node = buildActionNode (mapper , action );
8592 items .add (node );
8693 });
87- actionsNode .set ("items" , items );
94+ actionsNode .set (KEY_ITEMS , items );
8895
8996 formDefinition .add (actionsNode );
9097 });
9198 }
9299
93100 private ObjectNode buildActionNode (ObjectMapper mapper , Action action ) {
94101 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 ());
98105 return node ;
99106 }
100107
@@ -110,8 +117,8 @@ private ObjectNode handlerGroupedFields(ObjectMapper mapper, Field[] declaredFie
110117 ArrayNode groups = mapper .createArrayNode ();
111118
112119 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 );
115122 return tabsNode ;
116123
117124 }
@@ -138,16 +145,16 @@ private ObjectNode handleTabbedFields(ObjectMapper mapper, Field[] declaredField
138145
139146 groupedFieldsByTab .entrySet ().stream ().forEachOrdered (tabElements -> {
140147 ObjectNode tabNode = mapper .createObjectNode ();
141- tabNode .put ("title" , tabElements .getKey ());
148+ tabNode .put (KEY_TITLE , tabElements .getKey ());
142149 ArrayNode tabItems = mapper .createArrayNode ();
143150 tabElements .getValue ().stream ().forEach (tabItems ::add );
144- tabNode .set ("items" , tabItems );
151+ tabNode .set (KEY_ITEMS , tabItems );
145152 tabs .add (tabNode );
146153 });
147154 if (tabs .size () > 0 ) {
148155 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 );
151158 return tabsNode ;
152159 }
153160 return null ;
0 commit comments