11package fr .insee .genesis .controller .services ;
22
33import fr .insee .bpm .exceptions .MetadataParserException ;
4+ import fr .insee .bpm .metadata .model .MetadataModel ;
5+ import fr .insee .bpm .metadata .model .Variable ;
6+ import fr .insee .bpm .metadata .model .VariableType ;
47import fr .insee .bpm .metadata .model .VariablesMap ;
58import fr .insee .bpm .metadata .reader .ddi .DDIReader ;
69import fr .insee .bpm .metadata .reader .lunatic .LunaticReader ;
10+ import fr .insee .genesis .Constants ;
11+ import fr .insee .genesis .domain .utils .GroupUtils ;
712import fr .insee .genesis .exceptions .GenesisError ;
813import fr .insee .genesis .infrastructure .utils .FileUtils ;
914import lombok .extern .slf4j .Slf4j ;
1217import java .io .FileInputStream ;
1318import java .io .IOException ;
1419import java .nio .file .Path ;
20+ import java .util .Arrays ;
1521import java .util .List ;
1622@ Slf4j
1723@ Service
@@ -31,9 +37,16 @@ public VariablesMap parseMetadata(String metadataFilePath, boolean withDDI) {
3137 try {
3238 log .info ("Try to read {} file: {}" , withDDI ? "DDI" : "Lunatic" , metadataFilePath );
3339 if (withDDI ) {
34- return DDIReader .getMetadataFromDDI (
40+ MetadataModel metadataModel = DDIReader .getMetadataFromDDI (
3541 Path .of (metadataFilePath ).toFile ().toURI ().toURL ().toString (),
36- new FileInputStream (metadataFilePath )).getVariables ();
42+ new FileInputStream (metadataFilePath ));
43+ // Temporary solution
44+ // the logic of adding variables from lunatic to the ones present in the DDI needs to be implemented in BPM
45+ // (only in Kraftwerk for the moment)
46+ for (String enoVar : Constants .getEnoVariables ()){
47+ metadataModel .getVariables ().putVariable (new Variable (enoVar , metadataModel .getRootGroup (), VariableType .STRING ));
48+ }
49+ return metadataModel .getVariables ();
3750 } else {
3851 return LunaticReader .getMetadataFromLunatic (
3952 new FileInputStream (metadataFilePath )).getVariables ();
@@ -78,6 +91,11 @@ public VariablesMap readMetadatas(String campaignName, String modeName, FileUtil
7891 return null ;
7992 }
8093 }
94+ /* // Adding Eno variables if necessary
95+ // For review : not sure if this the best way to do it
96+ for (String enoVar : Arrays.stream(Constants.getEnoVariables()).toList()){
97+ variablesMap.putVariable(new Variable(enoVar, ));
98+ }*/
8199 return variablesMap ;
82100 }
83101}
0 commit comments