/*
|
* 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;
|
|
import com.megatim.dynamicjsonparser.enums.TypeDonnee;
|
import com.megatim.dynamicjsonparser.extender.JsonDataValidator;
|
import com.megatim.dynamicjsonparser.pojo.JsonField;
|
import static com.megatim.dynamicjsonparser.utils.Utility.writeToFile;
|
import com.megatim.typefichier.validator.Validator;
|
import com.megatim.typefichier.validator.model.ConfigJsonValidator;
|
import com.megatim.typefichier.validator.utilities.Utilities;
|
import com.megatim.fdxconvert.dao.JsonStructureDAO;
|
import com.megatim.fdxconvert.dao.TypeFichierJsonDAO;
|
import com.megatim.fdxconvert.model.JsonStructure;
|
import com.megatim.fdxconvert.model.TypeFichier;
|
import com.megatim.fdxconvert.model.TypeFichierJson;
|
import com.megatim.fdxconvert.model.jaxb.TypeFichierJsonsList;
|
import com.megatim.fdxconvert.service.JsonStructureService;
|
import com.megatim.fdxconvert.service.TypeFichierJsonService;
|
import com.megatim.fdxconvert.util.TypeFichierJsonMarshaller;
|
import com.megatim.fdxconvert.util.TypeFichierJsonConverter;
|
import java.io.File;
|
import java.io.IOException;
|
import java.nio.file.Path;
|
import java.nio.file.Paths;
|
import java.text.SimpleDateFormat;
|
import java.time.LocalDateTime;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.logging.Level;
|
import java.util.logging.Logger;
|
import javax.xml.bind.JAXBException;
|
import org.apache.poi.ss.usermodel.DateUtil;
|
|
/**
|
*
|
* @author STEPHANIE
|
*/
|
public class Test {
|
|
public static void main(String[] args) throws Exception {
|
Date date = DateUtil.getJavaDate(Double.parseDouble("45112 "));
|
SimpleDateFormat sdf
|
= new SimpleDateFormat("dd/MM/yyyy");
|
System.out.println("" + sdf.format(date));
|
}
|
|
private static void unMarshall() {
|
String filePath = "C:\\Users\\ASUS\\Documents\\DATAS\\Export\\typefichierJsons.xml";
|
try {
|
TypeFichierJsonsList typeFichierJsonsList = TypeFichierJsonMarshaller.unMarshall(filePath);
|
TypeFichierJsonService service = TypeFichierJsonService.getInstance();
|
|
for (TypeFichierJson t : typeFichierJsonsList.getTypeFichierJson()) {
|
service.add(t);
|
}
|
} catch (JAXBException ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
} catch (Exception ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
}
|
}
|
|
private static void unMarshallOne(String filePath) {
|
try {
|
TypeFichierJson t = TypeFichierJsonMarshaller.unMarshallOne(filePath);
|
TypeFichierJsonService.getInstance().add(t);
|
|
} catch (JAXBException ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
} catch (Exception ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
}
|
}
|
|
private static void marshallOne(String codeTypeFichier) {
|
try {
|
TypeFichierJson typeFichierJson = TypeFichierJsonDAO.getByTypeFichier(codeTypeFichier);
|
TypeFichierJsonMarshaller.marshall("C:\\Users\\ASUS\\Documents\\DATAS\\Export", typeFichierJson);
|
} catch (Exception ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
|
}
|
}
|
|
private static void marshall() {
|
try {
|
List<TypeFichierJson> typefichierJsons = TypeFichierJsonService.getInstance().getAll();
|
for (TypeFichierJson t : typefichierJsons) {
|
JsonStructure jsonStructure = JsonStructureDAO.loadSubJsonStructure(t.getJsonStructure());
|
t.setJsonStructure(jsonStructure);
|
}
|
TypeFichierJsonMarshaller.marshall(typefichierJsons, "C:\\Users\\ASUS\\Documents\\DATAS\\Export");
|
} catch (Exception ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
|
}
|
}
|
|
private static void validateWithValidator() {
|
File file = new File("C:\\Users\\ASUS\\Documents\\DATAS\\DGBACT.json");
|
String validatorPath = "C:\\Users\\ASUS\\Documents\\DATAS\\Export\\DGBACT20250417151916.xml";
|
Validator validator = new Validator();
|
ConfigJsonValidator configJson = new ConfigJsonValidator(
|
"C:\\Users\\ASUS\\Documents\\ERROR",
|
"C:\\Users\\ASUS\\Documents\\OUT",
|
file
|
);
|
try {
|
boolean result = validator.validate(validatorPath, configJson, System.getProperty("user.dir") + "\\src\\main\\java", true, true, 1);
|
System.out.println("result = " + result);
|
} catch (IOException ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
} catch (JAXBException ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
}
|
}
|
|
private static void validate() {
|
try {
|
final String packageName = "com.megatim.dynamicjsonparser.generated";
|
File file = new File("C:\\Users\\ASUS\\Documents\\DATAS\\DGBACT.json");
|
|
List<JsonField> fields = new TypeFichierJsonConverter(dgbact()).convert();
|
JsonDataValidator jsonDataValidator = new JsonDataValidator();
|
|
boolean result = jsonDataValidator.validateDatas(fields, System.getProperty("user.dir") + "\\src\\main\\java", packageName, file, 1);
|
System.out.println("result = " + result + ", " + LocalDateTime.now());
|
|
if (!result) {
|
Path errorPath = Paths.get("C:\\Users\\ASUS\\Documents\\JSON_TEST\\DGBACT.txt.err");
|
writeToFile(jsonDataValidator.getParsedData().getErrors(), errorPath);
|
}
|
System.out.println("NbElts = " + jsonDataValidator.getParsedData().getVirtuals().size() + ", " + LocalDateTime.now());
|
// jsonDataValidator.getParsedData().getVirtuals().forEach(v -> System.out.println(v));
|
} catch (IOException ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
|
}
|
}
|
// private static String print(List<JsonDataType> jsonDataTypes) {
|
// if (jsonDataTypes != null && !jsonDataTypes.isEmpty()) {
|
// jsonDataTypes.stream().forEach(j -> {
|
// if (j.getTypeDonnee().equals(TypeDonnee.OBJET)) {
|
// System.out.println(j);
|
// System.out.println(" " + print(j.getJsonDataTypes()));
|
// } else {
|
// System.out.println(j);
|
// }
|
// });
|
// }
|
// return "";
|
// }
|
|
public static void save() {
|
TypeFichierJson t = typeFichierJson();
|
JsonStructure jsonStruct = t.getJsonStructure();
|
jsonStruct.setTypeFichierJson(null);
|
|
try {
|
TypeFichierJsonService tjService = TypeFichierJsonService.getInstance();
|
JsonStructureService jService = JsonStructureService.getInstance();
|
|
JsonStructure newJsonStruct = jService.add(t.getJsonStructure());
|
t.setJsonStructure(newJsonStruct);
|
TypeFichierJson newEntity = tjService.add(t);
|
|
} catch (Exception ex) {
|
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
|
}
|
}
|
|
public static TypeFichierJson typeFichierJson() {
|
TypeFichierJson typeFichierJson = new TypeFichierJson();
|
typeFichierJson.setTypeFichier(typeFichier());
|
|
JsonStructure parent = jsonStructure(null, typeFichierJson.getTypeFichier().getCode(), true, true, TypeDonnee.OBJET, 10);
|
parent.setFields(jsonStructures(parent));
|
parent.setTypeFichierJson(typeFichierJson);
|
|
typeFichierJson.setJsonStructure(parent);
|
|
return typeFichierJson;
|
}
|
|
private static TypeFichier typeFichier() {
|
TypeFichier typeFichier = new TypeFichier();
|
typeFichier.setCode("DGBACT");
|
|
return typeFichier;
|
}
|
|
private static TypeFichierJson dgbact() {
|
TypeFichierJson typeFichierJson = new TypeFichierJson();
|
typeFichierJson.setTypeFichier(typeFichier());
|
|
JsonStructure parent = jsonStructure(null, typeFichierJson.getTypeFichier().getCode(), true, true, TypeDonnee.OBJET, 10);
|
parent.setFields(jsonStructures(parent));
|
parent.setTypeFichierJson(typeFichierJson);
|
|
typeFichierJson.setJsonStructure(parent);
|
|
List<JsonStructure> jsonStructures = new ArrayList<>();
|
jsonStructures.add(jsonStructure(parent, "EXERCICE", true, false, TypeDonnee.ALPHANUMERIQUE, 2));
|
jsonStructures.add(jsonStructure(parent, "CHAPITRE", true, false, TypeDonnee.ALPHANUMERIQUE, 2));
|
jsonStructures.add(jsonStructure(parent, "CODEPROGRAMME", true, false, TypeDonnee.ALPHANUMERIQUE, 3));
|
jsonStructures.add(jsonStructure(parent, "CODEACTION", true, false, TypeDonnee.ALPHANUMERIQUE, 2));
|
jsonStructures.add(jsonStructure(parent, "LIBELLEF", true, false, TypeDonnee.ALPHANUMERIQUE, 255));
|
jsonStructures.add(jsonStructure(parent, "LIBELLEA", true, false, TypeDonnee.ALPHANUMERIQUE, 255));
|
|
parent.setFields(jsonStructures);
|
|
return typeFichierJson;
|
}
|
|
private static List<JsonStructure> jsonStructures(JsonStructure parent) {
|
List<JsonStructure> jsonStructures = new ArrayList<>();
|
jsonStructures.add(jsonStructure(parent, "numeros", true, true, TypeDonnee.NUMERIQUE, 8));
|
jsonStructures.add(jsonStructure(parent, "noms", true, false, TypeDonnee.ALPHANUMERIQUE, 100));
|
jsonStructures.add(jsonStructure(parent, "nbreEnfants", false, false, TypeDonnee.NUMERIQUE, 2));
|
jsonStructures.add(jsonStructure(parent, "salaire", true, false, TypeDonnee.DECIMAL, 14));
|
jsonStructures.add(jsonStructure(parent, "dateNaissance", true, false, "yyyyMMdd", "-", 10));
|
|
JsonStructure jsonStructure = jsonStructure(parent, "cptBanque", true, true, TypeDonnee.OBJET, 10);
|
jsonStructure.setFields(Arrays.asList(
|
jsonStructure(jsonStructure, "rib", true, false, TypeDonnee.NUMERIQUE, 23),
|
jsonStructure(jsonStructure, "solde", true, false, TypeDonnee.DECIMAL, 14),
|
jsonStructure(jsonStructure, "dateCreation", true, false, "yyyyMMdd", "-", 10)
|
));
|
jsonStructures.add(jsonStructure);
|
|
return jsonStructures;
|
}
|
|
private static JsonStructure jsonStructure(JsonStructure parent, String name, boolean required, boolean collection, TypeDonnee typeDonnee, int taille) {
|
JsonStructure jsonStructure = new JsonStructure();
|
jsonStructure.setName(name);
|
jsonStructure.setCollection(collection);
|
jsonStructure.setTypeDonnee(typeDonnee);
|
jsonStructure.setRequired(required);
|
jsonStructure.setParent(parent);
|
jsonStructure.setLengthh(taille);
|
|
return jsonStructure;
|
}
|
|
private static JsonStructure jsonStructure(JsonStructure parent, String name, boolean required, boolean collection, String formatDate, String delimiteurDate, int taille) {
|
JsonStructure jsonStructure = new JsonStructure();
|
jsonStructure.setName(name);
|
jsonStructure.setCollection(collection);
|
jsonStructure.setTypeDonnee(TypeDonnee.DATE);
|
jsonStructure.setRequired(required);
|
jsonStructure.setFormatDate(formatDate);
|
jsonStructure.setCodeDelimiteurDate(delimiteurDate);
|
jsonStructure.setParent(parent);
|
jsonStructure.setLengthh(taille);
|
|
return jsonStructure;
|
}
|
|
}
|