/*
|
* 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;
|
}
|
}
|