22
33import fr .insee .genesis .configuration .Config ;
44import fr .insee .genesis .domain .model .surveyunit .Mode ;
5- import fr .insee .genesis .domain .ports .api .EditedExternalResponseApiPort ;
6- import fr .insee .genesis .domain .ports .api .EditedPreviousResponseApiPort ;
7- import fr .insee .genesis .domain .ports .api .EditedResponseApiPort ;
5+ import fr .insee .genesis .domain .ports .api .ContextualExternalVariableApiPort ;
6+ import fr .insee .genesis .domain .ports .api .ContextualPreviousVariableApiPort ;
7+ import fr .insee .genesis .domain .ports .api .ContextualVariableApiPort ;
88import fr .insee .genesis .exceptions .GenesisException ;
99import fr .insee .genesis .infrastructure .utils .FileUtils ;
1010import io .swagger .v3 .oas .annotations .Operation ;
2929import java .util .Iterator ;
3030import java .util .stream .Stream ;
3131
32- @ RequestMapping (path = "/edited " )
32+ @ RequestMapping (path = "/contextual-variable " )
3333@ Controller
3434@ Slf4j
3535@ AllArgsConstructor
36- public class EditedResponseController {
36+ public class ContextualVariableController {
3737
38- private final EditedPreviousResponseApiPort editedPreviousResponseApiPort ;
39- private final EditedExternalResponseApiPort editedExternalResponseApiPort ;
40- private final EditedResponseApiPort editedResponseApiPort ;
38+ private final ContextualPreviousVariableApiPort contextualPreviousVariableApiPort ;
39+ private final ContextualExternalVariableApiPort contextualExternalVariableApiPort ;
40+ private final ContextualVariableApiPort contextualVariableApiPort ;
4141 private final Config config ;
4242
43- @ Operation (summary = "Get edited variables (edited and previous)" )
43+ @ Operation (summary = "Get contextual variables (contextual and previous)" )
4444 @ GetMapping (path = "/" )
4545 @ PreAuthorize ("hasAnyRole('USER_PLATINE','SCHEDULER')" )
46- public ResponseEntity <Object > getEditedResponses (
46+ public ResponseEntity <Object > getContextualVariables (
4747 @ RequestParam ("questionnaireId" ) String questionnaireId ,
4848 @ RequestParam ("interrogationId" ) String interrogationId
4949 ){
5050 return ResponseEntity .ok ().body (
51- editedResponseApiPort . getEditedResponse (questionnaireId , interrogationId )
51+ contextualVariableApiPort . getContextualVariable (questionnaireId , interrogationId )
5252 );
5353 }
5454
55- @ Operation (summary = "Save all edited variables json files (edited and previous)" )
55+ @ Operation (summary = "Save all contextual variables json files (contextual and previous)" )
5656 @ PostMapping (path = "/json" )
5757 @ PreAuthorize ("hasAnyRole('USER_PLATINE','SCHEDULER')" )
58- public ResponseEntity <Object > saveEditedResponses (
58+ public ResponseEntity <Object > saveContextualVariables (
5959 @ RequestParam ("questionnaireId" ) String questionnaireId
6060 ){
6161 try {
@@ -71,8 +71,8 @@ public ResponseEntity<Object> saveEditedResponses(
7171 .iterator ();
7272 while (it .hasNext ()) {
7373 Path jsonFilePath = it .next ();
74- if (processEditedFile (questionnaireId , jsonFilePath )) {
75- //If the file is indeed a edited variables file and had been processed
74+ if (processContextualFile (questionnaireId , jsonFilePath )) {
75+ //If the file is indeed a contextual variables file and had been processed
7676 moveFile (questionnaireId , mode , fileUtils , jsonFilePath .toString ());
7777 fileCount ++;
7878 }
@@ -90,17 +90,17 @@ public ResponseEntity<Object> saveEditedResponses(
9090 }
9191
9292 /**
93- * @return true if any edited variable part found in file, false otherwise
93+ * @return true if any contextual variable part found in file, false otherwise
9494 */
95- private boolean processEditedFile (String questionnaireId , Path jsonFilePath ) throws GenesisException {
96- return readEditedPreviousFile (questionnaireId .toUpperCase (), null , jsonFilePath .toString ())
97- || readEditedExternalFile (questionnaireId .toUpperCase (), jsonFilePath .toString ());
95+ private boolean processContextualFile (String questionnaireId , Path jsonFilePath ) throws GenesisException {
96+ return readContextualPreviousFile (questionnaireId .toUpperCase (), null , jsonFilePath .toString ())
97+ || readContextualExternalFile (questionnaireId .toUpperCase (), jsonFilePath .toString ());
9898 }
9999
100- @ Operation (summary = "Add edited previous json file" )
100+ @ Operation (summary = "Add contextual previous json file" )
101101 @ PostMapping (path = "previous/json" )
102102 @ PreAuthorize ("hasAnyRole('USER_PLATINE','SCHEDULER','USER_BACK_OFFICE')" )
103- public ResponseEntity <Object > readEditedPreviousJson (
103+ public ResponseEntity <Object > readContextualPreviousJson (
104104 @ RequestParam ("questionnaireId" ) String questionnaireId ,
105105 @ RequestParam ("mode" ) Mode mode ,
106106 @ RequestParam (value = "sourceState" , required = false ) String sourceState ,
@@ -116,18 +116,18 @@ public ResponseEntity<Object> readEditedPreviousJson(
116116 if (!jsonFileName .toLowerCase ().endsWith (".json" )) {
117117 throw new GenesisException (400 , "File must be a JSON file !" );
118118 }
119- readEditedPreviousFile (questionnaireId .toUpperCase (), sourceState , filePath );
119+ readContextualPreviousFile (questionnaireId .toUpperCase (), sourceState , filePath );
120120 moveFile (questionnaireId , mode , fileUtils , filePath );
121- return ResponseEntity .ok ("Edited previous variable file %s saved !" .formatted (filePath ));
121+ return ResponseEntity .ok ("Contextual previous variable file %s saved !" .formatted (filePath ));
122122 }catch (GenesisException ge ){
123123 return ResponseEntity .status (HttpStatusCode .valueOf (ge .getStatus ())).body (ge .getMessage ());
124124 }
125125 }
126126
127- @ Operation (summary = "Add edited external json file" )
127+ @ Operation (summary = "Add contextual external json file" )
128128 @ PostMapping (path = "/external/json" )
129129 @ PreAuthorize ("hasAnyRole('USER_PLATINE','SCHEDULER','USER_BACK_OFFICE')" )
130- public ResponseEntity <Object > readEditedExternalJson (
130+ public ResponseEntity <Object > readContextualExternalJson (
131131 @ RequestParam ("questionnaireId" ) String questionnaireId ,
132132 @ RequestParam ("mode" ) Mode mode ,
133133 @ RequestParam (value = "jsonFileName" ) String jsonFileName
@@ -142,27 +142,27 @@ public ResponseEntity<Object> readEditedExternalJson(
142142 if (!jsonFileName .toLowerCase ().endsWith (".json" )) {
143143 throw new GenesisException (400 , "File must be a JSON file !" );
144144 }
145- readEditedExternalFile (questionnaireId .toUpperCase (), filePath );
145+ readContextualExternalFile (questionnaireId .toUpperCase (), filePath );
146146 moveFile (questionnaireId , mode , fileUtils , filePath );
147- return ResponseEntity .ok ("Edited external variable file %s saved !" .formatted (filePath ));
147+ return ResponseEntity .ok ("Contextual external variable file %s saved !" .formatted (filePath ));
148148 }catch (GenesisException ge ){
149149 return ResponseEntity .status (HttpStatusCode .valueOf (ge .getStatus ())).body (ge .getMessage ());
150150 }
151151 }
152152
153- private boolean readEditedPreviousFile (String questionnaireId , String sourceState , String filePath ) throws GenesisException {
153+ private boolean readContextualPreviousFile (String questionnaireId , String sourceState , String filePath ) throws GenesisException {
154154 try (InputStream inputStream = new FileInputStream (filePath )) {
155- return editedPreviousResponseApiPort . readEditedPreviousFile (inputStream , questionnaireId , sourceState );
155+ return contextualPreviousVariableApiPort . readContextualPreviousFile (inputStream , questionnaireId , sourceState );
156156 } catch (FileNotFoundException e ) {
157157 throw new GenesisException (404 , "File %s not found" .formatted (filePath ));
158158 } catch (IOException e ) {
159159 throw new GenesisException (500 , e .toString ());
160160 }
161161 }
162162
163- private boolean readEditedExternalFile (String questionnaireId , String filePath ) throws GenesisException {
163+ private boolean readContextualExternalFile (String questionnaireId , String filePath ) throws GenesisException {
164164 try (InputStream inputStream = new FileInputStream (filePath )) {
165- return editedExternalResponseApiPort . readEditedExternalFile (inputStream , questionnaireId );
165+ return contextualExternalVariableApiPort . readContextualExternalFile (inputStream , questionnaireId );
166166 } catch (FileNotFoundException e ) {
167167 throw new GenesisException (404 , "File %s not found" .formatted (filePath ));
168168 } catch (IOException e ) {
0 commit comments