-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRawResponseReprocessController.java
More file actions
130 lines (109 loc) · 6.18 KB
/
Copy pathRawResponseReprocessController.java
File metadata and controls
130 lines (109 loc) · 6.18 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package fr.insee.genesis.controller.rest.responses;
import fr.insee.genesis.controller.utils.DateTimeUtils;
import fr.insee.genesis.domain.model.surveyunit.rawdata.DataProcessResult;
import fr.insee.genesis.domain.model.surveyunit.rawdata.RawDataModelType;
import fr.insee.genesis.domain.ports.api.ReprocessRawResponseApiPort;
import fr.insee.genesis.exceptions.GenesisException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.time.Instant;
import java.time.LocalDateTime;
@Controller
@RequiredArgsConstructor
@Slf4j
public class RawResponseReprocessController {
private final ReprocessRawResponseApiPort reprocessRawResponseApiPort;
@Operation(summary = "Reprocess raw response of a collection instrument.")
@PostMapping(path = "/raw-responses/{collectionInstrumentId}/reprocess")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<String> reProcessRawResponsesByCollectionInstrumentId(
@Parameter(
description = "Id of the collection instrument (old questionnaireId)",
example = "ENQTEST2025X00")
@PathVariable("collectionInstrumentId")
String collectionInstrumentId,
@Parameter(
description = "Extract since",
schema = @Schema(type = "string", format = "date-time", example = "2026-01-01T00:00:00Z")
)
@RequestParam(value = "sinceDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
Instant sinceDate,
@RequestParam(value = "localSinceDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Parameter(description = "Extract since in Europe/Paris timezone", schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T01:00:00"))
LocalDateTime localSinceDate,
@Parameter(
description = "Extract until",
schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T00:00:00Z")
)
@RequestParam(value = "endDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
Instant endDate,
@RequestParam(value = "localEndDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Parameter(description = "Extract until in Europe/Paris timezone", schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T01:00:00"))
LocalDateTime localEndDate
) throws GenesisException {
Instant resolvedSinceDate = DateTimeUtils.resolveInstant(sinceDate, localSinceDate);
Instant resolvedEndDate = DateTimeUtils.resolveInstant(endDate, localEndDate);
DataProcessResult result = reprocessRawResponseApiPort.reprocessRawResponses(
RawDataModelType.FILIERE,
collectionInstrumentId,
resolvedSinceDate,
resolvedEndDate);
return ResponseEntity.ok(result.message(collectionInstrumentId));
}
@Operation(summary = "Reprocess Lunatic raw data for a questionnaire model. " +
"**Note**: Lunatic raw data is the legacy format of raw responses.")
@PostMapping(path = "/responses/raw/lunatic-json/{questionnaireId}/reprocess")
@PreAuthorize("hasRole('ADMIN')")
public ResponseEntity<String> reProcessJsonRawDataByQuestionnaireId(
@Parameter(
description = "Questionnaire model id (old name for collection instrument id).",
example = "ENQTEST2025X00")
@PathVariable("questionnaireId")
String collectionInstrumentId, // 'questionnaireId' is the legacy name for 'collectionInstrumentId'
@Parameter(
description = "Extract since",
schema = @Schema(type = "string", format = "date-time", example = "2026-01-01T00:00:00Z")
)
@RequestParam(value = "sinceDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
Instant sinceDate,
@RequestParam(value = "localSinceDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Parameter(description = "Extract since in Europe/Paris timezone", schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T01:00:00"))
LocalDateTime localSinceDate,
@Parameter(
description = "Extract until",
schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T00:00:00Z")
)
@RequestParam(value = "endDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
Instant endDate,
@RequestParam(value = "localEndDate", required = false)
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
@Parameter(description = "Extract until in Europe/Paris timezone", schema = @Schema(type = "string", format = "date-time", example = "2026-02-02T01:00:00"))
LocalDateTime localEndDate
) throws GenesisException {
Instant resolvedSinceDate = DateTimeUtils.resolveInstant(sinceDate, localSinceDate);
Instant resolvedEndDate = DateTimeUtils.resolveInstant(endDate, localEndDate);
DataProcessResult result = reprocessRawResponseApiPort.reprocessRawResponses(
RawDataModelType.LEGACY,
collectionInstrumentId,
resolvedSinceDate,
resolvedEndDate);
return ResponseEntity.ok(result.message(collectionInstrumentId));
}
}