Skip to content

Commit

Permalink
#317: Change LocalDate to Instant, to include the time
Browse files Browse the repository at this point in the history
* Change date to date-time
  • Loading branch information
benitsch committed Jul 17, 2024
1 parent 06933fd commit 1d610b0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.io.IOException;
import java.time.LocalDate;
import java.time.Instant;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -93,7 +93,7 @@ public ResponseEntity<StudyImportExportDTO> exportStudy(Long studyId) {
}

@Override
public ResponseEntity<StreamingResponseBody> exportStudyData(Long studyId, String token, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, LocalDate from, LocalDate to) {
public ResponseEntity<StreamingResponseBody> exportStudyData(Long studyId, String token, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, Instant from, Instant to) {
Optional<DownloadToken> dt = tokenRepository.getToken(token).filter(t -> t.getStudyId().equals(studyId));

if (dt.isPresent()) {
Expand All @@ -118,7 +118,7 @@ public ResponseEntity<StreamingResponseBody> exportStudyData(Long studyId, Strin

@Override
@RequiresStudyRole({StudyRole.STUDY_ADMIN, StudyRole.STUDY_OPERATOR})
public ResponseEntity<GenerateDownloadToken200ResponseDTO> generateDownloadToken(Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, LocalDate from, LocalDate to) {
public ResponseEntity<GenerateDownloadToken200ResponseDTO> generateDownloadToken(Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, Instant from, Instant to) {
var token = tokenRepository.createToken(studyId).getToken();
var uri = ServletUriComponentsBuilder.fromCurrentRequest().pathSegment(token).build(true).toUri();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalDate;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
Expand Down Expand Up @@ -329,7 +328,7 @@ public List<ParticipationData> getParticipationData(Long studyId){
}
}

public void exportData(OutputStream outputStream, Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, LocalDate from, LocalDate to) throws IOException {
public void exportData(OutputStream outputStream, Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, Instant from, Instant to) throws IOException {
String index = getStudyIdString(studyId);

if(!client.indices().exists(e -> e.index(index)).value()) {
Expand Down Expand Up @@ -359,7 +358,7 @@ private void writeHits(List<Hit<JsonNode>> hits, OutputStream outputStream) thro
outputStream.write(datapoints.getBytes(StandardCharsets.UTF_8));
}

private SearchRequest getQuery(String index, List<Integer> studyGroupIds, List<Integer> participantIds, List<Integer> observationIds, LocalDate from, LocalDate to, List<FieldValue> searchAfterSort) {
private SearchRequest getQuery(String index, List<Integer> studyGroupIds, List<Integer> participantIds, List<Integer> observationIds, Instant from, Instant to, List<FieldValue> searchAfterSort) {
SearchRequest.Builder builder = new SearchRequest.Builder();
BoolQuery.Builder boolQueryBuilder = new BoolQuery.Builder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.Instant;
import java.util.*;

@Service
Expand Down Expand Up @@ -152,7 +152,7 @@ public Study importStudy(StudyImportExport studyImport, AuthenticatedUser user)
return newStudy;
}

public void exportStudyData(OutputStream outputStream, Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, LocalDate from, LocalDate to) {
public void exportStudyData(OutputStream outputStream, Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, Instant from, Instant to) {
if (studyService.existsStudy(studyId).orElse(false)) {
exportStudyDataAsync(outputStream, studyId, studyGroupId, participantId, observationId, from, to);
} else {
Expand All @@ -161,7 +161,7 @@ public void exportStudyData(OutputStream outputStream, Long studyId, List<Intege
}

@Async
public void exportStudyDataAsync(OutputStream outputStream, Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, LocalDate from, LocalDate to) {
public void exportStudyDataAsync(OutputStream outputStream, Long studyId, List<Integer> studyGroupId, List<Integer> participantId, List<Integer> observationId, Instant from, Instant to) {
try (outputStream) {
outputStream.write("[".getBytes(StandardCharsets.UTF_8));
elasticService.exportData(outputStream, studyId, studyGroupId, participantId, observationId, from, to);
Expand Down
24 changes: 4 additions & 20 deletions studymanager/src/main/resources/openapi/StudyManagerAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1130,16 +1130,8 @@ paths:
type: array
items:
type: integer
- name: from
in: query
schema:
type: string
format: date
- name: to
in: query
schema:
type: string
format: date
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
'200':
description: Operation successful
Expand Down Expand Up @@ -1185,16 +1177,8 @@ paths:
type: array
items:
type: integer
- name: from
in: query
schema:
type: string
format: date
- name: to
in: query
schema:
type: string
format: date
- $ref: '#/components/parameters/From'
- $ref: '#/components/parameters/To'
responses:
'200':
description: Operation successful
Expand Down

0 comments on commit 1d610b0

Please sign in to comment.