Skip to content

Commit 622ccca

Browse files
committed
add get and delete V2 endpoints
1 parent 9859a9f commit 622ccca

5 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package fr.insee.genesis.controller.dto.rawdata;
2+
3+
import fr.insee.genesis.domain.model.context.schedule.KraftwerkExecutionScheduleV2;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.time.LocalDateTime;
10+
11+
@Data
12+
@Builder
13+
@NoArgsConstructor
14+
@AllArgsConstructor
15+
public class ScheduleV2Dto {
16+
private String surveyName;
17+
private String collectionInstrumentId;
18+
private LocalDateTime lastExecution;
19+
private KraftwerkExecutionScheduleV2 kraftwerkExecutionScheduleV2;
20+
}

src/main/java/fr/insee/genesis/controller/rest/DataProcessingContextController.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import fr.insee.genesis.Constants;
44
import fr.insee.genesis.controller.dto.ScheduleDto;
55
import fr.insee.genesis.controller.dto.ScheduleRequestDto;
6+
import fr.insee.genesis.controller.dto.rawdata.ScheduleV2Dto;
67
import fr.insee.genesis.domain.model.context.schedule.ServiceToCall;
78
import fr.insee.genesis.domain.model.context.schedule.TrustParameters;
89
import fr.insee.genesis.domain.ports.api.DataProcessingContextApiPort;
@@ -252,6 +253,17 @@ public ResponseEntity<Object> getAllSchedulesV2() {
252253
return ResponseEntity.ok(surveyScheduleDocumentModels);
253254
}
254255

256+
@Operation(summary = "Fetch all schedules V2")
257+
@GetMapping(path = "/contexts/schedules/v2")
258+
@PreAuthorize("hasAnyRole('SCHEDULER','READER')")
259+
public ResponseEntity<Object> getAllSchedulesV3() {
260+
log.debug("Got GET all schedules V2 request");
261+
262+
List<ScheduleV2Dto> schedules = dataProcessingContextApiPort.getAllSchedulesV2();
263+
264+
log.info("Returning {} V2 schedule documents...", schedules.size());
265+
return ResponseEntity.ok(schedules);
266+
}
255267

256268
@Deprecated(forRemoval = true)
257269
@Operation(summary = "Set last execution date of a partition with new date or nothing")
@@ -317,6 +329,21 @@ public ResponseEntity<Object> deleteSchedulesByCollectionInstrumentId(
317329
return ResponseEntity.ok().build();
318330
}
319331

332+
@Operation(summary = "Delete V2 Kraftwerk execution schedule of a collection instrument id")
333+
@DeleteMapping(path = "/contexts/{collectionInstrumentId}/schedules/v2")
334+
@PreAuthorize("hasRole('USER_KRAFTWERK')")
335+
public ResponseEntity<Object> deleteSchedulesV2ByCollectionInstrumentId(
336+
@PathVariable("collectionInstrumentId") String collectionInstrumentId
337+
){
338+
try {
339+
dataProcessingContextApiPort.deleteSchedulesV2ByCollectionInstrumentId(collectionInstrumentId);
340+
} catch (GenesisException e) {
341+
return new ResponseEntity<>(e.getMessage(), HttpStatusCode.valueOf(e.getStatus()));
342+
}
343+
log.info("V2 schedule deleted for collection instrument {}", collectionInstrumentId);
344+
return ResponseEntity.ok().build();
345+
}
346+
320347
@Operation(summary = "Delete expired schedules")
321348
@DeleteMapping(path = "/context/schedules/expired-schedules")
322349
@PreAuthorize("hasRole('SCHEDULER')")

src/main/java/fr/insee/genesis/domain/model/context/DataProcessingContextModel.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.insee.genesis.domain.model.context;
22

33
import fr.insee.genesis.controller.dto.ScheduleDto;
4+
import fr.insee.genesis.controller.dto.rawdata.ScheduleV2Dto;
45
import fr.insee.genesis.domain.model.context.schedule.KraftwerkExecutionSchedule;
56
import fr.insee.genesis.domain.model.context.schedule.KraftwerkExecutionScheduleV2;
67
import lombok.AllArgsConstructor;
@@ -42,4 +43,13 @@ public ScheduleDto toScheduleDto(){
4243
.kraftwerkExecutionScheduleList(kraftwerkExecutionScheduleList)
4344
.build();
4445
}
46+
47+
public ScheduleV2Dto toScheduleV2Dto() {
48+
return ScheduleV2Dto.builder()
49+
.surveyName(partitionId)
50+
.collectionInstrumentId(collectionInstrumentId)
51+
.lastExecution(lastExecution)
52+
.kraftwerkExecutionScheduleV2(kraftwerkExecutionScheduleV2)
53+
.build();
54+
}
4555
}

src/main/java/fr/insee/genesis/domain/ports/api/DataProcessingContextApiPort.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.insee.genesis.domain.ports.api;
22

33
import fr.insee.genesis.controller.dto.ScheduleDto;
4+
import fr.insee.genesis.controller.dto.rawdata.ScheduleV2Dto;
45
import fr.insee.genesis.controller.utils.ExportType;
56
import fr.insee.genesis.domain.model.context.DataProcessingContextModel;
67
import fr.insee.genesis.domain.model.context.schedule.ServiceToCall;
@@ -44,10 +45,15 @@ void saveKraftwerkExecutionScheduleV2(String collectionInstrumentId,
4445
void updateLastExecutionDateByCollectionInstrumentId(String collectionInstrumentId, LocalDateTime newDate) throws GenesisException;
4546

4647
void deleteSchedules(String surveyName) throws GenesisException;
48+
49+
void deleteSchedulesV2ByCollectionInstrumentId(String collectionInstrumentId) throws GenesisException;
50+
4751
void deleteSchedulesByCollectionInstrumentId(String collectionInstrumentId) throws GenesisException;
4852

4953
List<ScheduleDto> getAllSchedules();
5054

55+
List<ScheduleV2Dto> getAllSchedulesV2();
56+
5157
void deleteExpiredSchedules(String logFolder) throws GenesisException;
5258

5359
long countSchedules();

src/main/java/fr/insee/genesis/domain/service/context/DataProcessingContextService.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
55
import fr.insee.genesis.Constants;
66
import fr.insee.genesis.controller.dto.ScheduleDto;
7+
import fr.insee.genesis.controller.dto.rawdata.ScheduleV2Dto;
78
import fr.insee.genesis.controller.utils.ExportType;
89
import fr.insee.genesis.domain.model.context.DataProcessingContextModel;
910
import fr.insee.genesis.domain.model.context.schedule.KraftwerkExecutionSchedule;
@@ -207,6 +208,17 @@ public void deleteSchedules(String partitionId) throws GenesisException {
207208
dataProcessingContextPersistancePort.save(DataProcessingContextMapper.INSTANCE.modelToDocument(dataProcessingContextModel));
208209
}
209210

211+
@Override
212+
public void deleteSchedulesV2ByCollectionInstrumentId(String collectionInstrumentId) throws GenesisException {
213+
DataProcessingContextModel dataProcessingContextModel =
214+
dataProcessingContextPersistancePort.findByCollectionInstrumentId(collectionInstrumentId);
215+
if (dataProcessingContextModel == null) {
216+
throw new GenesisException(404, NOT_FOUND_MESSAGE);
217+
}
218+
dataProcessingContextModel.setKraftwerkExecutionScheduleV2(null);
219+
dataProcessingContextPersistancePort.save(DataProcessingContextMapper.INSTANCE.modelToDocument(dataProcessingContextModel));
220+
}
221+
210222
@Override
211223
public void deleteSchedulesByCollectionInstrumentId(String collectionInstrumentId) throws GenesisException {
212224
DataProcessingContextModel dataProcessingContextModel =
@@ -232,6 +244,22 @@ public List<ScheduleDto> getAllSchedules() {
232244
return scheduleDtos;
233245
}
234246

247+
@Override
248+
public List<ScheduleV2Dto> getAllSchedulesV2() {
249+
List<ScheduleV2Dto> scheduleV2Dtos = new ArrayList<>();
250+
251+
List<DataProcessingContextModel> dataProcessingContextModels =
252+
DataProcessingContextMapper.INSTANCE.listDocumentToListModel(
253+
dataProcessingContextPersistancePort.findAll()
254+
);
255+
256+
dataProcessingContextModels.forEach(
257+
model -> scheduleV2Dtos.add(model.toScheduleV2Dto())
258+
);
259+
260+
return scheduleV2Dtos;
261+
}
262+
235263
@Override
236264
public void deleteExpiredSchedules(String logFolder) throws GenesisException {
237265
List<DataProcessingContextModel> dataProcessingContextModels =

0 commit comments

Comments
 (0)