aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/clamp/clds/tosca/ToscaYamlToJsonConvertor.java
blob: 232db48c40601e40af3f4777ddbd994f02b95ef7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
/*-
 * ============LICENSE_START=======================================================
 * ONAP CLAMP
 * ================================================================================
 * Copyright (C) 2018 AT&T Intellectual Property. All rights
 *                             reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END============================================
 * ===================================================================
 *
 */

package org.onap.clamp.clds.tosca;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;
import org.yaml.snakeyaml.Yaml;

/**
 * Tosca Model Yaml parser and convertor to JSON Schema consumable for JSON
 * Editor.
 *
 */
public class ToscaYamlToJsonConvertor {

    private int simpleTypeOrder = 1000;
    private int complexTypeOrder = 10000;
    private int complexSimpleTypeOrder = 1;

    private int incrementSimpleTypeOrder() {
        return simpleTypeOrder++;
    }

    private int incrementComplexTypeOrder() {
        return complexTypeOrder = complexTypeOrder + 10000;
    }

    private int incrementComplexSimpleTypeOrder() {
        complexSimpleTypeOrder++;
        return complexTypeOrder + complexSimpleTypeOrder;
    }

    /**
     * Parses Tosca YAML string.
     *
     * @param yamlString     YAML string
     * @param modelTypeToUse The model type that must be used to obtain the Json
     *                       Schema
     * @return JSON string
     */
    public String parseToscaYaml(String yamlString, String modelTypeToUse) {

        Yaml yaml = new Yaml();
        LinkedHashMap<String, Object> loadedYaml = yaml.load(yamlString);
        if (loadedYaml == null) {
            return "";
        }
        LinkedHashMap<String, Object> nodeTypes = new LinkedHashMap<>();
        LinkedHashMap<String, Object> dataNodes = new LinkedHashMap<>();
        JSONObject jsonParentObject = new JSONObject();
        JSONObject jsonTempObject = new JSONObject();
        parseNodeAndDataType(loadedYaml, nodeTypes, dataNodes);
        populateJsonEditorObject(loadedYaml, nodeTypes, dataNodes, jsonParentObject, jsonTempObject, modelTypeToUse);
        if (jsonTempObject.length() > 0) {
            jsonParentObject = jsonTempObject;
        }
        JSONObject jsonEditorObject = new JSONObject();
        jsonEditorObject.put(JsonEditorSchemaConstants.SCHEMA, jsonParentObject);
        return jsonEditorObject.toString();
    }

    // Parse node_type and data_type
    @SuppressWarnings("unchecked")
    private void parseNodeAndDataType(LinkedHashMap<String, Object> map, LinkedHashMap<String, Object> nodeTypes,
            LinkedHashMap<String, Object> dataNodes) {
        map.entrySet().stream().forEach(n -> {
            if (n.getKey().contains(ToscaSchemaConstants.NODE_TYPES) && n.getValue() instanceof Map) {
                parseNodeAndDataType((LinkedHashMap<String, Object>) n.getValue(), nodeTypes, dataNodes);
            } else if (n.getKey().contains(ToscaSchemaConstants.DATA_TYPES) && n.getValue() instanceof Map) {
                parseNodeAndDataType((LinkedHashMap<String, Object>) n.getValue(), nodeTypes, dataNodes);
            } else if (n.getKey().contains(ToscaSchemaConstants.POLICY_NODE)) {
                nodeTypes.put(n.getKey(), n.getValue());
            } else if (n.getKey().contains(ToscaSchemaConstants.POLICY_DATA)) {
                dataNodes.put(n.getKey(), n.getValue());
            }
        });
    }

    @SuppressWarnings("unchecked")
    private void populateJsonEditorObject(LinkedHashMap<String, Object> map, LinkedHashMap<String, Object> nodeTypes,
            LinkedHashMap<String, Object> dataNodes, JSONObject jsonParentObject, JSONObject jsonTempObject,
            String modelTypeToUse) {

        Map<String, JSONObject> jsonEntrySchema = new HashMap<>();
        jsonParentObject.put(JsonEditorSchemaConstants.TYPE, JsonEditorSchemaConstants.TYPE_OBJECT);
        if (nodeTypes.get(modelTypeToUse) instanceof Map) {
            ((LinkedHashMap<String, Object>) nodeTypes.get(modelTypeToUse)).entrySet().forEach(ntElement -> {
                if (ntElement.getKey().equalsIgnoreCase(ToscaSchemaConstants.PROPERTIES)) {
                    JSONArray rootNodeArray = new JSONArray();
                    if (ntElement.getValue() instanceof Map) {
                        ((LinkedHashMap<String, Object>) ntElement.getValue()).entrySet()
                                .forEach((ntPropertiesElement) -> {
                                    boolean isListNode = false;
                                    parseDescription((LinkedHashMap<String, Object>) ntPropertiesElement.getValue(),
                                            jsonParentObject);
                                    LinkedHashMap<String, Object> parentPropertiesMap = (LinkedHashMap<String, Object>) ntPropertiesElement
                                            .getValue();
                                    if (parentPropertiesMap.containsKey(ToscaSchemaConstants.TYPE)
                                            && ((String) parentPropertiesMap.get(ToscaSchemaConstants.TYPE))
                                                    .contains(ToscaSchemaConstants.TYPE_MAP)
                                            && parentPropertiesMap.containsKey(ToscaSchemaConstants.ENTRY_SCHEMA)) {
                                        parentPropertiesMap = (LinkedHashMap<String, Object>) parentPropertiesMap
                                                .get(ToscaSchemaConstants.ENTRY_SCHEMA);
                                        isListNode = true;
                                    }
                                    if (parentPropertiesMap.containsKey(ToscaSchemaConstants.TYPE)
                                            && ((String) parentPropertiesMap.get(ToscaSchemaConstants.TYPE))
                                                    .contains(ToscaSchemaConstants.POLICY_DATA)) {
                                        ((LinkedHashMap<String, Object>) dataNodes
                                                .get(parentPropertiesMap.get(ToscaSchemaConstants.TYPE))).entrySet()
                                                        .stream().forEach(pmap -> {
                                                            if (pmap.getKey().equalsIgnoreCase(
                                                                    ToscaSchemaConstants.PROPERTIES)) {
                                                                parseToscaProperties(ToscaSchemaConstants.POLICY_NODE,
                                                                        (LinkedHashMap<String, Object>) pmap.getValue(),
                                                                        jsonParentObject, rootNodeArray,
                                                                        jsonEntrySchema, dataNodes,
                                                                        incrementSimpleTypeOrder());
                                                            }
                                                        });
                                    }
                                    if (isListNode) {
                                        jsonTempObject.put(JsonEditorSchemaConstants.TYPE,
                                                JsonEditorSchemaConstants.TYPE_ARRAY);
                                        parseDescription((LinkedHashMap<String, Object>) ntPropertiesElement.getValue(),
                                                jsonTempObject);
                                        jsonTempObject.put(JsonEditorSchemaConstants.ITEMS, jsonParentObject);
                                        jsonTempObject.put(JsonEditorSchemaConstants.FORMAT,
                                                JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS_TOP);
                                        jsonTempObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS,
                                                JsonEditorSchemaConstants.TRUE);
                                    }
                                });
                    }
                }
            });
        }
    }

    @SuppressWarnings("unchecked")
    private void parseToscaProperties(String parentKey, LinkedHashMap<String, Object> propertiesMap,
            JSONObject jsonDataNode, JSONArray array, Map<String, JSONObject> jsonEntrySchema,
            LinkedHashMap<String, Object> dataNodes, final int order) {
        JSONObject jsonPropertyNode = new JSONObject();
        propertiesMap.entrySet().stream().forEach(p -> {
            // Populate JSON Array for "required" key

            if (p.getValue() instanceof Map) {
                LinkedHashMap<String, Object> nodeMap = (LinkedHashMap<String, Object>) p.getValue();
                if (nodeMap.containsKey(ToscaSchemaConstants.REQUIRED)
                        && ((boolean) nodeMap.get(ToscaSchemaConstants.REQUIRED))) {
                    array.put(p.getKey());
                }
                // if(nodeMap.containsKey(ToscaSchemaConstants.CONSTRAINTS))
                parseToscaChildNodeMap(p.getKey(), nodeMap, jsonPropertyNode, jsonEntrySchema, dataNodes, array,
                        incrementSimpleTypeOrder());
            }
        });
        jsonDataNode.put(JsonEditorSchemaConstants.REQUIRED, array);
        jsonDataNode.put(JsonEditorSchemaConstants.PROPERTIES, jsonPropertyNode);
    }

    @SuppressWarnings("unchecked")
    private void parseToscaPropertiesForType(String parentKey, LinkedHashMap<String, Object> propertiesMap,
            JSONObject jsonDataNode, JSONArray array, Map<String, JSONObject> jsonEntrySchema,
            LinkedHashMap<String, Object> dataNodes, boolean isType, int order) {
        JSONObject jsonPropertyNode = new JSONObject();

        propertiesMap.entrySet().stream().forEach(p -> {
            // array.put(p.getKey());
            boolean overWriteArray = false;
            if (p.getValue() instanceof Map) {
                LinkedHashMap<String, Object> nodeMap = (LinkedHashMap<String, Object>) p.getValue();
                if (!(parentKey.contains(ToscaSchemaConstants.ENTRY_SCHEMA)
                        || parentKey.contains(ToscaSchemaConstants.POLICY_NODE))
                        && nodeMap.containsKey(ToscaSchemaConstants.TYPE)
                        && (((String) nodeMap.get(ToscaSchemaConstants.TYPE))
                                .contains(ToscaSchemaConstants.POLICY_DATA))) {
                    overWriteArray = true;
                }
                if (nodeMap.containsKey(ToscaSchemaConstants.REQUIRED)
                        && ((boolean) nodeMap.get(ToscaSchemaConstants.REQUIRED))) {
                    array.put(p.getKey());
                }
                parseToscaChildNodeMap(p.getKey(), nodeMap, jsonPropertyNode, jsonEntrySchema, dataNodes, array, order);
            }
        });
        jsonDataNode.put(JsonEditorSchemaConstants.REQUIRED, array);
        jsonDataNode.put(JsonEditorSchemaConstants.PROPERTIES, jsonPropertyNode);
    }

    private void parseToscaChildNodeMap(String childObjectKey, LinkedHashMap<String, Object> childNodeMap,
            JSONObject jsonPropertyNode, Map<String, JSONObject> jsonEntrySchema,
            LinkedHashMap<String, Object> dataNodes, JSONArray array, int order) {
        JSONObject childObject = new JSONObject();
        // JSONArray childArray = new JSONArray();
        parseDescription(childNodeMap, childObject);
        parseTypes(childObjectKey, childNodeMap, childObject, jsonEntrySchema, dataNodes, array, order);
        parseConstraints(childNodeMap, childObject);
        parseEntrySchema(childNodeMap, childObject, jsonPropertyNode, jsonEntrySchema, dataNodes);

        jsonPropertyNode.put(childObjectKey, childObject);
        order++;

    }

    private void parseEntrySchema(LinkedHashMap<String, Object> childNodeMap, JSONObject childObject,
            JSONObject jsonPropertyNode, Map<String, JSONObject> jsonEntrySchema,
            LinkedHashMap<String, Object> dataNodes) {
        if (childNodeMap.get(ToscaSchemaConstants.ENTRY_SCHEMA) != null) {
            if (childNodeMap.get(ToscaSchemaConstants.ENTRY_SCHEMA) instanceof Map) {
                LinkedHashMap<String, Object> entrySchemaMap = (LinkedHashMap<String, Object>) childNodeMap
                        .get(ToscaSchemaConstants.ENTRY_SCHEMA);
                entrySchemaMap.entrySet().stream().forEach(entry -> {
                    if (entry.getKey().equalsIgnoreCase(ToscaSchemaConstants.TYPE) && entry.getValue() != null) {
                        String entrySchemaType = (String) entry.getValue();
                        if (entrySchemaType.contains(ToscaSchemaConstants.POLICY_DATA)) {
                            JSONArray array = new JSONArray();
                            if (jsonEntrySchema.get(entrySchemaType) != null) {
                                // Already traversed
                                JSONObject entrySchemaObject = jsonEntrySchema.get(entrySchemaType);
                                attachEntrySchemaJsonObject(childObject, entrySchemaObject,
                                        JsonEditorSchemaConstants.TYPE_OBJECT);
                            } else if (dataNodes.containsKey(entrySchemaType)) {

                                JSONObject entrySchemaObject = new JSONObject();
                                // Need to traverse
                                ((LinkedHashMap<String, Object>) dataNodes.get(entrySchemaType)).entrySet().stream()
                                        .forEach(pmap -> {
                                            if (pmap.getKey().equalsIgnoreCase(ToscaSchemaConstants.PROPERTIES)) {
                                                parseToscaProperties(ToscaSchemaConstants.ENTRY_SCHEMA,
                                                        (LinkedHashMap<String, Object>) pmap.getValue(),
                                                        entrySchemaObject, array, jsonEntrySchema, dataNodes,
                                                        incrementComplexTypeOrder());
                                                jsonEntrySchema.put(entrySchemaType, entrySchemaObject);
                                                dataNodes.remove(entrySchemaType);
                                                attachEntrySchemaJsonObject(childObject, entrySchemaObject,
                                                        JsonEditorSchemaConstants.TYPE_OBJECT);
                                            }

                                        });
                            }
                        } else if (entrySchemaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)
                                || entrySchemaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)
                                || entrySchemaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_FLOAT)) {
                            JSONObject entrySchemaObject = new JSONObject();
                            parseConstraints(entrySchemaMap, entrySchemaObject);
                            String jsontype = JsonEditorSchemaConstants.TYPE_STRING;
                            if (entrySchemaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)
                                    || entrySchemaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_FLOAT)) {
                                jsontype = JsonEditorSchemaConstants.TYPE_INTEGER;
                            }
                            if (childNodeMap.get(ToscaSchemaConstants.TYPE) != null) {
                                // Only known value of type is String for now
                                if (childNodeMap.get(ToscaSchemaConstants.TYPE) instanceof String) {
                                    String typeValue = (String) childNodeMap.get(ToscaSchemaConstants.TYPE);
                                    if (typeValue.equalsIgnoreCase(ToscaSchemaConstants.TYPE_LIST)) {
                                        // Custom key for JSON Editor and UI rendering
                                        childObject.put(JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT,
                                                JsonEditorSchemaConstants.FORMAT_SELECT);
                                        // childObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS,
                                        // JsonEditorSchemaConstants.TRUE);
                                    }
                                }
                            }
                            attachEntrySchemaJsonObject(childObject, entrySchemaObject, jsontype);
                        }
                    }
                });
            }
        }
    }

    private void attachEntrySchemaJsonObject(JSONObject childObject, JSONObject entrySchemaObject, String dataType) {

        entrySchemaObject.put(JsonEditorSchemaConstants.TYPE, dataType);
        childObject.put(JsonEditorSchemaConstants.ITEMS, entrySchemaObject);
    }

    @SuppressWarnings("unchecked")
    private void attachTypeJsonObject(JSONObject childObject, JSONObject typeObject) {
        Iterator<String> keys = typeObject.keys();
        while (keys.hasNext()) {
            String key = keys.next();
            childObject.put(key, typeObject.get(key));
        }
    }

    /*
     * private String parseKey(String toscaKey, String lookupString) { return
     * toscaKey.substring(toscaKey.indexOf(lookupString) + lookupString.length(),
     * toscaKey.length()); }
     */

    private void parseDescription(LinkedHashMap<String, Object> childNodeMap, JSONObject childObject) {
        if (childNodeMap.get(ToscaSchemaConstants.DESCRIPTION) != null) {
            childObject.put(JsonEditorSchemaConstants.TITLE, childNodeMap.get(ToscaSchemaConstants.DESCRIPTION));
        }
    }

    private void parseTypes(String childObjectKey, LinkedHashMap<String, Object> childNodeMap, JSONObject childObject,
            Map<String, JSONObject> jsonEntrySchema, LinkedHashMap<String, Object> dataNodes, JSONArray array,
            int order) {
        if (childNodeMap.get(ToscaSchemaConstants.TYPE) != null) {
            // Only known value of type is String for now
            if (childNodeMap.get(ToscaSchemaConstants.TYPE) instanceof String) {
                childObject.put(JsonEditorSchemaConstants.PROPERTY_ORDER, order);
                String typeValue = (String) childNodeMap.get(ToscaSchemaConstants.TYPE);
                if (typeValue.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)) {
                    childObject.put(JsonEditorSchemaConstants.TYPE, JsonEditorSchemaConstants.TYPE_INTEGER);

                } else if (typeValue.equalsIgnoreCase(ToscaSchemaConstants.TYPE_FLOAT)) {
                    childObject.put(JsonEditorSchemaConstants.TYPE, JsonEditorSchemaConstants.TYPE_INTEGER);
                } else if (typeValue.equalsIgnoreCase(ToscaSchemaConstants.TYPE_LIST)) {
                    childObject.put(JsonEditorSchemaConstants.TYPE, JsonEditorSchemaConstants.TYPE_ARRAY);
                    // Custom key for JSON Editor and UI rendering
                    childObject.put(JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT,
                            JsonEditorSchemaConstants.CUSTOM_KEY_FORMAT_TABS_TOP);
                    childObject.put(JsonEditorSchemaConstants.UNIQUE_ITEMS, JsonEditorSchemaConstants.TRUE);
                } else if (typeValue.equalsIgnoreCase(ToscaSchemaConstants.TYPE_MAP)) {
                    childObject.put(JsonEditorSchemaConstants.TYPE, JsonEditorSchemaConstants.TYPE_OBJECT);
                } else if (typeValue.contains(ToscaSchemaConstants.POLICY_DATA)) {
                    JSONArray childArray = new JSONArray();

                    if (jsonEntrySchema.get(typeValue) != null) {
                        // Already traversed
                        JSONObject entrySchemaObject = jsonEntrySchema.get(typeValue);
                        attachTypeJsonObject(childObject, entrySchemaObject);
                    } else if (dataNodes.containsKey(typeValue)) {
                        JSONObject entrySchemaObject = new JSONObject();
                        // Need to traverse
                        JSONArray jsonArray = new JSONArray();
                        ((LinkedHashMap<String, Object>) dataNodes.get(typeValue)).entrySet().stream().forEach(pmap -> {
                            if (pmap.getKey().equalsIgnoreCase(ToscaSchemaConstants.PROPERTIES)) {
                                parseToscaPropertiesForType(childObjectKey,
                                        (LinkedHashMap<String, Object>) pmap.getValue(), entrySchemaObject, childArray,
                                        jsonEntrySchema, dataNodes, true, incrementComplexSimpleTypeOrder());
                                jsonEntrySchema.put(typeValue, entrySchemaObject);
                                dataNodes.remove(typeValue);
                                attachTypeJsonObject(childObject, entrySchemaObject);
                            }
                        });
                    }
                } else {
                    childObject.put(JsonEditorSchemaConstants.TYPE, JsonEditorSchemaConstants.TYPE_STRING);
                }
            }
            if (childNodeMap.get(ToscaSchemaConstants.DEFAULT) != null) {
                childObject.put(JsonEditorSchemaConstants.DEFAULT, childNodeMap.get(ToscaSchemaConstants.DEFAULT));
            }
        }
    }

    private void parseConstraints(LinkedHashMap<String, Object> childNodeMap, JSONObject childObject) {
        if (childNodeMap.containsKey(ToscaSchemaConstants.CONSTRAINTS)
                && childNodeMap.get(ToscaSchemaConstants.CONSTRAINTS) != null) {
            List<LinkedHashMap<String, Object>> constraintsList = (List<LinkedHashMap<String, Object>>) childNodeMap
                    .get(ToscaSchemaConstants.CONSTRAINTS);
            constraintsList.stream().forEach(c -> {
                if (c instanceof Map) {
                    c.entrySet().stream().forEach(constraint -> {
                        if (constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.MIN_LENGTH)
                                || constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.GREATER_OR_EQUAL)) {
                            // For String min_lenghth is minimum length whereas for number, it will be
                            // minimum or greater than to the defined value
                            if (childNodeMap.containsKey(ToscaSchemaConstants.TYPE)
                                    && (childNodeMap.get(ToscaSchemaConstants.TYPE) instanceof String)
                                    && ((String) childNodeMap.get(ToscaSchemaConstants.TYPE))
                                            .equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)) {
                                childObject.put(JsonEditorSchemaConstants.MIN_LENGTH, constraint.getValue());
                            } else {
                                childObject.put(JsonEditorSchemaConstants.MINIMUM, constraint.getValue());
                            }
                        } else if (constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.MAX_LENGTH)
                                || constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.LESS_OR_EQUAL)) {
                            // For String max_lenghth is maximum length whereas for number, it will be
                            // maximum or less than the defined value
                            if (childNodeMap.containsKey(ToscaSchemaConstants.TYPE)
                                    && (childNodeMap.get(ToscaSchemaConstants.TYPE) instanceof String)
                                    && ((String) childNodeMap.get(ToscaSchemaConstants.TYPE))
                                            .equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)) {
                                childObject.put(JsonEditorSchemaConstants.MAX_LENGTH, constraint.getValue());
                            } else {
                                childObject.put(JsonEditorSchemaConstants.MAXIMUM, constraint.getValue());
                            }
                        } else if (constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.LESS_THAN)) {
                            childObject.put(JsonEditorSchemaConstants.EXCLUSIVE_MAXIMUM, constraint.getValue());
                        } else if (constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.GREATER_THAN)) {
                            childObject.put(JsonEditorSchemaConstants.EXCLUSIVE_MINIMUM, constraint.getValue());
                        } else if (constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.IN_RANGE)) {
                            if (constraint.getValue() instanceof ArrayList<?>) {
                                if (childNodeMap.containsKey(ToscaSchemaConstants.TYPE)
                                        && (childNodeMap.get(ToscaSchemaConstants.TYPE) instanceof String)
                                        && ((String) childNodeMap.get(ToscaSchemaConstants.TYPE))
                                                .equalsIgnoreCase(ToscaSchemaConstants.TYPE_STRING)) {
                                    childObject.put(JsonEditorSchemaConstants.MIN_LENGTH,
                                            ((ArrayList) constraint.getValue()).get(0));
                                    childObject.put(JsonEditorSchemaConstants.MAX_LENGTH,
                                            ((ArrayList) constraint.getValue()).get(1));
                                } else {
                                    childObject.put(JsonEditorSchemaConstants.MINIMUM,
                                            ((ArrayList) constraint.getValue()).get(0));
                                    childObject.put(JsonEditorSchemaConstants.MAXIMUM,
                                            ((ArrayList) constraint.getValue()).get(1));
                                }

                            }
                        } else if (constraint.getKey().equalsIgnoreCase(ToscaSchemaConstants.VALID_VALUES)) {
                            JSONArray validValuesArray = new JSONArray();

                            if (constraint.getValue() instanceof ArrayList<?>) {
                                boolean processDictionary = ((ArrayList<?>) constraint.getValue()).stream()
                                        .anyMatch(value -> (value instanceof String
                                                && ((String) value).contains(ToscaSchemaConstants.DICTIONARY)));
                                if (!processDictionary) {
                                    ((ArrayList<?>) constraint.getValue()).stream().forEach(value -> {
                                        validValuesArray.put(value);
                                    });
                                    childObject.put(JsonEditorSchemaConstants.ENUM, validValuesArray);
                                } else {
                                    ((ArrayList<?>) constraint.getValue()).stream().forEach(value -> {
                                        if ((value instanceof String
                                                && ((String) value).contains(ToscaSchemaConstants.DICTIONARY))) {
                                            processDictionaryElements(childObject, (String) value);
                                        }

                                    });

                                }
                            }

                        }
                    });
                }
            });
        }
    }

    private void processDictionaryElements(JSONObject childObject, String dictionaryReference) {

    }

    private String getJsonType(String toscaType) {
        String jsonType = null;
        if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_INTEGER)) {
            jsonType = JsonEditorSchemaConstants.TYPE_INTEGER;
        } else if (toscaType.equalsIgnoreCase(ToscaSchemaConstants.TYPE_LIST)) {
            jsonType = JsonEditorSchemaConstants.TYPE_ARRAY;
        } else {
            jsonType = JsonEditorSchemaConstants.TYPE_STRING;
        }
        return jsonType;
    }

}