Kenmegne
6 days ago 908e81dd173f380879d5fabeb5794d5b7a76df0e
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
/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.megatim.fdxconvert.util;
 
import com.megatim.dynamicjsonparser.enums.TypeDonnee;
import com.megatim.dynamicjsonparser.pojo.JsonDataType;
import com.megatim.fdxconvert.model.JsonStructure;
import com.megatim.fdxconvert.model.ModeleJson;
import com.megatim.fdxconvert.model.StructureChampJson;
import com.megatim.fdxconvert.model.SubObject;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 *
 * @author ASUS
 */
public class JsonDataTypeUtil {
 
    public static List<JsonDataType> constructJsonDataType(ModeleJson modeleJson) {
        List<JsonDataType> jsonDataTypes = new ArrayList<>();
 
        modeleJson.getListeStructureJson().forEach(s -> {
 
            if (s.getTypeDonnee().equals(TypeDonnee.OBJET)) {
 
                jsonDataTypes.add(new JsonDataType(s.getLibelle(), contructSubJsonDataType(s.getTypeOfSubObject()), modeleJson.getObjectName(), s.isListe()));
 
            } else {
                JsonDataType json = new JsonDataType(s.getLibelle(), s.getTypeDonnee(), modeleJson.getObjectName(), s.isListe());
 
                if (s.getTypeDonnee().equals(TypeDonnee.DATE)) {
 
                    json.setFormatDate(s.getFormatDate());
                    json.setSeparateurDate(s.getCodeDelimiteurDate());
                }
 
                jsonDataTypes.add(json);
            }
 
        });
 
        return jsonDataTypes;
    }
 
    public static List<JsonDataType> constructJsonDataType(JsonStructure jsonStructure) {
        List<JsonDataType> jsonDataTypes = new ArrayList<>();
 
        jsonStructure.getFields().forEach(s -> {
 
            if (s.getTypeDonnee().equals(TypeDonnee.OBJET)) {
 
                jsonDataTypes.add(new JsonDataType(s.getName(), constructJsonDataType(s), s.getName(), s.isRequired(), s.isCollection()));
 
            } else {
                JsonDataType json = new JsonDataType(s.getName(), s.getTypeDonnee(), jsonStructure.getName(), s.isRequired(), s.isCollection());
 
                if (s.getTypeDonnee().equals(TypeDonnee.DATE)) {
 
                    json.setFormatDate(s.getFormatDate());
                    json.setSeparateurDate(s.getCodeDelimiteurDate());
                }
 
                jsonDataTypes.add(json);
            }
 
        });
 
        return jsonDataTypes;
    }
 
    private static List<JsonDataType> contructSubJsonDataType(SubObject subObject) {
        List<JsonDataType> liste = new ArrayList<>();
 
        //Filtrer afin de ne garder que les champs des sous-objets
        List<StructureChampJson> structures = subObject.getListeStructureJson().stream().filter(s -> s.getModeleJson() == null).collect(Collectors.toList());
 
        structures.forEach(c -> {
 
            if (c.getTypeDonnee().equals(TypeDonnee.OBJET)) {
 
                liste.add(new JsonDataType(c.getLibelle(), contructSubJsonDataType(c.getTypeOfSubObject()), c.getFieldOfSubObject().getSubObjectName(), c.isListe()));
 
            } else {
 
                JsonDataType json = new JsonDataType(c.getLibelle(), c.getTypeDonnee(), subObject.getSubObjectName(), c.isListe());
 
                if (c.getTypeDonnee().equals(TypeDonnee.DATE)) {
 
                    json.setFormatDate(c.getFormatDate());
                    json.setSeparateurDate(c.getCodeDelimiteurDate());
                }
                liste.add(json);
            }
        });
 
        return liste;
    }
}