Skip to content

Commit

Permalink
Merge pull request #173 from MORE-Platform/develop
Browse files Browse the repository at this point in the history
Merge develop branch into main pull request
  • Loading branch information
alireza-dhp authored Oct 14, 2024
2 parents 24969ed + 82a43a1 commit 8dc5fa7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/compile-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
Expand Down
28 changes: 21 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>17</java.version>
<spring-boot.version>3.3.1</spring-boot.version>
<testcontainers.version>1.19.8</testcontainers.version>
<spring-boot.version>3.3.4</spring-boot.version>
<testcontainers.version>1.20.2</testcontainers.version>

<docker.namespace>more-project</docker.namespace>

Expand Down Expand Up @@ -104,7 +104,7 @@
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.22</version>
<version>2.2.25</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
Expand All @@ -124,7 +124,7 @@
<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.13.4</version>
<version>8.14.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -140,7 +140,7 @@
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.4</version>
<version>8.0</version>
<scope>runtime</scope>
</dependency>

Expand Down Expand Up @@ -228,7 +228,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.3.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -315,7 +315,7 @@
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.6.0</version>
<version>7.7.0</version>
<executions>
<execution>
<id>data-api</id>
Expand Down Expand Up @@ -360,6 +360,19 @@
<generateModelTests>false</generateModelTests>
<generateSupportingFiles>false</generateSupportingFiles>

<typeMappings>
<typeMapping>string+date-time=Instant</typeMapping>
<typeMapping>string+time=LocalTime</typeMapping>
</typeMappings>
<schemaMappings>
<schemaMapping>Instant=java.time.Instant</schemaMapping>
<schemaMapping>LocalTime=java.time.LocalTime</schemaMapping>
</schemaMappings>
<importMappings>
<importMapping>Instant=java.time.Instant</importMapping>
<importMapping>LocalTime=java.time.LocalTime</importMapping>
</importMappings>

<configOptions>
<useSpringBoot3>true</useSpringBoot3>
<sourceFolder>src</sourceFolder>
Expand All @@ -368,6 +381,7 @@
<useTags>true</useTags>
<openApiNullable>false</openApiNullable>
<skipDefaultInterface>true</skipDefaultInterface>
<requestMappingMode>api_interface</requestMappingMode>
</configOptions>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public ResponseEntity<Void> storeExternalBulk(String moreApiToken, EndpointDataB
Interval interval = externalService.getIntervalForObservation(apiRoutingInfo.studyId(), apiRoutingInfo.observationId(), participantId);

endpointDataBulkDTO.getDataPoints().stream()
.map(datapoint -> datapoint.getTimestamp().toInstant())
.map(timestamp -> timestamp.isBefore(interval.getStart()) || timestamp.isAfter(interval.getEnd()))
.map(ExternalDataDTO::getTimestamp)
.map(timestamp -> !(timestamp.isBefore(interval.getStart()) || timestamp.isAfter(interval.getEnd())))
.filter(v -> v)
.findFirst()
.orElseThrow(BadRequestException::TimeFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package io.redlink.more.data.controller.transformer;

import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public final class BaseTransformers {

Expand All @@ -16,14 +14,4 @@ public static Long toVersionTag(Instant modified) {
return modified.toEpochMilli();
}

public static Instant toInstant(OffsetDateTime dateTime) {
if (dateTime == null)
return null;
return dateTime.toInstant();
}

public static OffsetDateTime toOffsetDateTime(Instant instant) {
if (instant == null) return null;
return instant.atOffset(ZoneOffset.UTC);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ public static List<DataPoint> createDataPoints(DataBulkDTO bulk) {
}

public static DataPoint createDataPoint(ObservationDataDTO dataPoint, Instant recordingTime) {
Instant dateTime = dataPoint.getTimestamp();
return new DataPoint(
dataPoint.getDataId(),
dataPoint.getObservationId(),
dataPoint.getObservationType(),
dataPoint.getObservationType(),
recordingTime,
BaseTransformers.toInstant(dataPoint.getTimestamp()),
dateTime,
dataPoint.getDataValue());
}

Expand All @@ -44,13 +45,14 @@ public static List<DataPoint> createDataPoints(EndpointDataBulkDTO bulk, ApiRout
}

public static DataPoint createDataPoint(ExternalDataDTO dataPoint, ApiRoutingInfo routingInfo, Instant recordingTime, Integer observationId) {
Instant dateTime = dataPoint.getTimestamp();
return new DataPoint(
UUID.randomUUID().toString(),
observationId.toString(),
routingInfo.observationType(),
routingInfo.observationType(),
recordingTime,
BaseTransformers.toInstant(dataPoint.getTimestamp()),
dateTime,
dataPoint.getDataValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static ParticipantDTO toDTO(Participant participant) {
participant.alias(),
ParticipantStatusDTO.fromValue(participant.status()),
toGroupDto(participant),
BaseTransformers.toOffsetDateTime(participant.start())
participant.start()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ public static ObservationDTO toDTO(Observation observation, Instant start, Insta
}

public static ObservationScheduleDTO toObservationScheduleDTO(Range<Instant> schedule) {
Instant instant = schedule.getMaximum();
Instant instant1 = schedule.getMinimum();
return new ObservationScheduleDTO()
.start(BaseTransformers.toOffsetDateTime(schedule.getMinimum()))
.end(BaseTransformers.toOffsetDateTime(schedule.getMaximum()))
.start(instant1)
.end(instant)
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.redlink.more.data.api.app.v1.model.PushNotificationDTO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.util.*;

@Component
public class NotificationRepository {

Expand Down Expand Up @@ -68,10 +69,10 @@ private static RowMapper<PushNotificationDTO> getRowMapper() {
};
}

private static OffsetDateTime getTimestamp(ResultSet rs) {
private static Instant getTimestamp(ResultSet rs) {
try {
return Optional.ofNullable(rs.getTimestamp("timestamp"))
.map(d -> d.toInstant().atOffset(ZoneOffset.UTC))
.map(Timestamp::toInstant)
.orElse(null);
} catch (SQLException e) {
return null;
Expand Down

0 comments on commit 8dc5fa7

Please sign in to comment.