Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Staging into Main branch #157

Merged
merged 96 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
a2ddca9
MORE2-5 set participants start datetime on registration
Nov 15, 2023
b28a269
MORE2-5 enable relative events on all places
Nov 16, 2023
8b76ae9
TT-13: Adapt Github Pipeline for Gateway
iaigner Nov 16, 2023
b2d3e64
MORE2-5 implement relative schedule calculation
Nov 16, 2023
9fa9913
Merge pull request #1 from redlink-gmbh/adapt-github-pipeline
tkurz Nov 17, 2023
81d0963
MORE2-5 set participants start datetime on registration
Nov 15, 2023
4fb2288
MORE2-5 enable relative events on all places
Nov 16, 2023
c44b6c0
MORE2-5 implement relative schedule calculation
Nov 16, 2023
dcdfc66
Merge remote-tracking branch 'fork/MORE2-5-DG-Implement-appointment-g…
Nov 17, 2023
836fd0a
MORE2-5 enable ical export
Nov 17, 2023
e3789fb
Merge branch 'main' into MORE2-Relative_Study_Start
Nov 17, 2023
cdf9745
Merge branch 'MORE2-Relative_Study_Start' into MORE2-5-DG-Implement-a…
Nov 17, 2023
eb57872
MORE2-5 merge with main
Nov 17, 2023
b4fc34e
Merge pull request #2 from redlink-gmbh/MORE2-5-DG-Implement-appointm…
tkurz Nov 17, 2023
54e87ff
TT-6 check if partipant is avtive
Nov 21, 2023
acf614a
TT-21 remove events schedules outside the study ranges
Nov 21, 2023
9ef059e
TT-21 fix tests failing to to consideration of study boundings
Nov 21, 2023
9bbd3ef
FEATURE make github actions ready for fork features
Nov 22, 2023
56660d0
Merge branch 'forkmain' into FEATURE-Relative_Study_Start
Nov 22, 2023
62bed70
FEATURE improve cal export
Nov 22, 2023
042b2f5
FEATURE set abs or rel to calendar summary
Nov 23, 2023
5924d60
Merge pull request #95 from redlink-gmbh/FEATURE-Relative_Study_Start
alireza-dhp Nov 28, 2023
f2cc6a2
HOTFIX prevent NPE for relative dates without hours and minutes set
Nov 30, 2023
308fdaa
HOTFIX prevent NPE for relative dates and correct md for instant crea…
Nov 30, 2023
619595c
Merge pull request #96 from redlink-gmbh/FEATURE-Relative_Study_Start
alireza-dhp Dec 1, 2023
506705a
105 store correct start date
Dec 21, 2023
414b704
Merge pull request #1 from redlink-gmbh/TT-105-shift-study-start-on-s…
iaigner Dec 21, 2023
b8024b6
Merge pull request #101 from redlink-gmbh/FEATURE-Relative_Study_Start
alireza-dhp Jan 8, 2024
011ec4b
fixed bug where absolute observations are only shown if fully within …
drtyyj Feb 9, 2024
8aae626
Merge pull request #2 from redlink-gmbh/fix-abs-observations-not-showing
drtyyj Feb 12, 2024
bdbd395
Merge pull request #109 from redlink-gmbh/FEATURE-Relative_Study_Start
alireza-dhp Feb 12, 2024
5818296
participant start date only shifted if a relative observation is alre…
drtyyj Feb 15, 2024
cf3b018
Merge pull request #3 from redlink-gmbh/HOTFIX-relative-observation-p…
AdPat-Redlink Feb 16, 2024
fb0c570
Merge pull request #110 from redlink-gmbh/FEATURE-Relative_Study_Start
alireza-dhp Feb 19, 2024
e136720
Issue #111: added Endpoint for retrieving participants with API Key
drtyyj Apr 11, 2024
bf78a6f
Issue #111: Security-Config for new endpoint and minor cleanup
drtyyj Apr 12, 2024
46edaad
Issue #111: refactoring of routingInfo
drtyyj Apr 12, 2024
c29528d
Issue #111: add studygroup and start-datetime to returned data
drtyyj Apr 15, 2024
2e4eb69
Issue #111: requested changes
drtyyj Apr 18, 2024
949df27
Build Docker-Images also on develop-branch
ja-fra Apr 22, 2024
7c69888
#111 Also provide the group-name when listing participants
ja-fra Apr 22, 2024
d7f359d
Merge pull request #112 from MORE-Platform/111_participant_ids_endpoint
ja-fra Apr 23, 2024
4039bd1
Bump com.google.cloud.tools:jib-maven-plugin from 3.3.2 to 3.4.2
dependabot[bot] Apr 26, 2024
5108358
Merge branch 'refs/heads/main' into develop
ja-fra Apr 29, 2024
50eb7c6
#121: re-enable consent-recording on participant-signup
ja-fra Apr 29, 2024
757f2d3
Merge branch 'develop' into dependabot/maven/develop/com.google.cloud…
ja-fra Apr 30, 2024
b14778a
Merge pull request #119 from MORE-Platform/dependabot/maven/develop/c…
ja-fra Apr 30, 2024
f1e553f
Bump org.testcontainers:testcontainers-bom from 1.19.0 to 1.19.7
dependabot[bot] Apr 30, 2024
82a987f
Merge pull request #116 from MORE-Platform/dependabot/maven/develop/o…
github-actions[bot] Apr 30, 2024
9e3928b
Bump io.swagger.core.v3:swagger-annotations from 2.2.16 to 2.2.21
dependabot[bot] Apr 30, 2024
88db9f3
Merge pull request #118 from MORE-Platform/dependabot/maven/develop/i…
github-actions[bot] Apr 30, 2024
01f3100
Bump jakarta.json:jakarta.json-api from 2.1.2 to 2.1.3
dependabot[bot] Apr 30, 2024
ca83357
Merge pull request #127 from MORE-Platform/dependabot/maven/develop/j…
github-actions[bot] Apr 30, 2024
73e0513
Bump net.sf.biweekly:biweekly from 0.6.7 to 0.6.8
dependabot[bot] Apr 30, 2024
13fbc5f
Merge pull request #128 from MORE-Platform/dependabot/maven/develop/n…
github-actions[bot] Apr 30, 2024
f18fa48
Bump the maven-plugin group with 4 updates
dependabot[bot] Apr 30, 2024
cc6bbc1
Merge pull request #125 from MORE-Platform/dependabot/maven/develop/m…
ja-fra Apr 30, 2024
8dece64
Bump co.elastic.clients:elasticsearch-java from 8.10.2 to 8.13.2
dependabot[bot] Apr 30, 2024
86ed1d3
Merge pull request #117 from MORE-Platform/dependabot/maven/develop/c…
ja-fra May 2, 2024
4dd36da
Bump co.elastic.clients:elasticsearch-java from 8.13.2 to 8.13.3
dependabot[bot] May 2, 2024
6fab227
Merge pull request #129 from MORE-Platform/dependabot/maven/develop/c…
github-actions[bot] May 2, 2024
bca41b3
Merge branch 'develop' into 121-participant-consent-is-not-recorded
ja-fra May 6, 2024
d9dd813
Merge pull request #124 from MORE-Platform/121-participant-consent-is…
ja-fra May 6, 2024
874cb01
Bump org.testcontainers:testcontainers-bom from 1.19.7 to 1.19.8
dependabot[bot] May 9, 2024
bea8794
Merge pull request #131 from MORE-Platform/dependabot/maven/develop/o…
github-actions[bot] May 9, 2024
4ef6229
Bump co.elastic.clients:elasticsearch-java from 8.13.3 to 8.13.4
dependabot[bot] May 9, 2024
2e9c516
Merge pull request #132 from MORE-Platform/dependabot/maven/develop/c…
github-actions[bot] May 9, 2024
c0be7e2
Bump io.swagger.core.v3:swagger-annotations from 2.2.21 to 2.2.22
dependabot[bot] May 15, 2024
d4fdd0d
Merge pull request #133 from MORE-Platform/dependabot/maven/develop/i…
github-actions[bot] May 15, 2024
909ac50
Bump spring-boot.version from 3.1.2 to 3.2.5
dependabot[bot] May 15, 2024
d3e4644
Merge pull request #126 from MORE-Platform/dependabot/maven/develop/s…
drtyyj May 16, 2024
5542878
#135: Correctly handle the preview-states in the gateway.
ja-fra May 27, 2024
08b1c31
Merge pull request #136 from MORE-Platform/135-participant-signup-fai…
ja-fra May 27, 2024
a14b0a9
#135: Add another layer of state-check for enrollment
ja-fra May 27, 2024
1ba9358
#135: Fix de-/serialization of relative schedules from the database
ja-fra May 27, 2024
6538888
Merge pull request #137 from MORE-Platform/135-participant-signup-fai…
ja-fra May 28, 2024
87402be
Bump com.google.cloud.tools:jib-maven-plugin from 3.4.2 to 3.4.3
dependabot[bot] May 31, 2024
eb45781
Merge pull request #138 from MORE-Platform/dependabot/maven/develop/c…
github-actions[bot] May 31, 2024
55fd6fb
Bump spring-boot.version from 3.2.5 to 3.3.0
dependabot[bot] May 31, 2024
dc0a8bb
change flyway dependency from core to database-postgres
drtyyj Jun 3, 2024
5cf8704
Merge pull request #134 from MORE-Platform/dependabot/maven/develop/s…
drtyyj Jun 3, 2024
52e6ffb
#135: Align state-translation with study-manager
ja-fra Jun 3, 2024
5cc966a
Merge pull request #139 from MORE-Platform/135-participant-signup-fai…
ja-fra Jun 3, 2024
a51f210
#299: sync SchedulerUtils to StudyManager Backend
drtyyj Jun 4, 2024
72c4442
refactor code to sync with backend and change Pair usage in schedules…
drtyyj Jun 4, 2024
92b9249
remove duplicate line
drtyyj Jun 4, 2024
5961936
#141 - some additional cleanup
ja-fra Jun 4, 2024
29f1786
Merge pull request #140 from MORE-Platform/299_sync_scheduler_with_ba…
ja-fra Jun 4, 2024
3c47caf
Enable Docker-Packaging on the redlink-branch
ja-fra Jun 6, 2024
639209a
Bump spring-boot.version from 3.3.0 to 3.3.1
dependabot[bot] Jun 20, 2024
be8d1f1
Merge pull request #145 from MORE-Platform/dependabot/maven/develop/s…
github-actions[bot] Jun 20, 2024
6e20444
Merge branch 'develop' into redlink
ja-fra Jul 3, 2024
21b70de
Merge pull request #146 from MORE-Platform/redlink
ja-fra Jul 3, 2024
e0d9099
Requesting the Calendar for a non-existing study should result in a 4…
ja-fra Jul 4, 2024
1f0d97b
Merge pull request #147 from MORE-Platform/fix-error-when-accessing-c…
benitsch Jul 4, 2024
a68dd6e
Update compile-test.yml
alireza-dhp Jul 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions .github/workflows/compile-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Test and Compile
on:
workflow_dispatch:
inputs:
dockerTag:
description: If set, docker img is built and tagged accordingly
required: false
push:

jobs:
Expand Down Expand Up @@ -37,7 +41,7 @@ jobs:
Build-and-Deploy:
name: "Build and Push Docker Image"
runs-on: ubuntu-latest
if: github.ref_name == 'main'
if: contains(fromJSON('["main", "develop", "redlink", "staging"]'), github.ref_name) || github.event.inputs.dockerTag != ''
needs:
- Compile-and-Test
steps:
Expand All @@ -47,18 +51,34 @@ jobs:
with:
distribution: 'temurin'
java-version: 17
- name: Generate additional Docker-Tags
run: |
TAGS=${BRANCH}
if [ "$BRANCH" == "$MAIN_BRANCH" ]; then
TAGS="latest,$TAGS"
fi
if [ -n "$EVENT_PARAM" ]; then
TAGS="$EVENT_PARAM"
fi
echo "Generated Docker-Tags: $TAGS"
echo "TAGS=$TAGS" >> "$GITHUB_ENV"
env:
BRANCH: ${{ github.ref_name }}
MAIN_BRANCH: ${{ github.event.repository.default_branch }}
EVENT_PARAM: ${{ github.event.inputs.dockerTag }}
- name: Build JIB container and publish to GitHub Packages
run: ./mvnw -B -U
--no-transfer-progress
clean verify jib:build
-Drevision=${{github.run_number}}
-Dchangelist=
-Dsha1=.${GITHUB_SHA:0:7}
-Dquick
-Ddocker.namespace=${DOCKER_NAMESPACE,,}
-Djib.to.tags=latest
-Djib.to.auth.username=${{ github.actor }}
-Djib.to.auth.password=${{ secrets.GITHUB_TOKEN }}
run:
./mvnw -B -U
--no-transfer-progress
clean verify jib:build
-Drevision=${{github.run_number}}
-Dchangelist=
-Dsha1=.${GITHUB_SHA:0:7}
-Dquick
-Ddocker.namespace=${DOCKER_NAMESPACE,,}
-Djib.to.tags=${TAGS}
-Djib.to.auth.username=${{ github.actor }}
-Djib.to.auth.password=${{ secrets.GITHUB_TOKEN }}
env:
DOCKER_NAMESPACE: ghcr.io/${{ github.repository_owner }}

Expand All @@ -70,4 +90,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: Event File
path: ${{ github.event_path }}
path: ${{ github.event_path }}
30 changes: 18 additions & 12 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.1.2</spring-boot.version>
<testcontainers.version>1.19.0</testcontainers.version>
<spring-boot.version>3.3.1</spring-boot.version>
<testcontainers.version>1.19.8</testcontainers.version>

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

Expand Down Expand Up @@ -74,14 +74,20 @@
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- Cache -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
</dependency>

<!-- Persistence -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
Expand All @@ -98,7 +104,7 @@
<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.16</version>
<version>2.2.22</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
Expand All @@ -112,13 +118,13 @@
<dependency>
<groupId>net.sf.biweekly</groupId>
<artifactId>biweekly</artifactId>
<version>0.6.7</version>
<version>0.6.8</version>
</dependency>

<dependency>
<groupId>co.elastic.clients</groupId>
<artifactId>elasticsearch-java</artifactId>
<version>8.10.2</version>
<version>8.13.4</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand All @@ -127,7 +133,7 @@
<dependency>
<groupId>jakarta.json</groupId>
<artifactId>jakarta.json-api</artifactId>
<version>2.1.2</version>
<version>2.1.3</version>
</dependency>

<!-- Logging -->
Expand Down Expand Up @@ -205,12 +211,12 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.5.0</version>
<version>1.6.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
Expand All @@ -222,7 +228,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -241,7 +247,7 @@
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>3.3.2</version>
<version>3.4.3</version>
<executions>
<execution>
<id>jib-deploy</id>
Expand Down Expand Up @@ -375,7 +381,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
<version>2.2.0</version>
<version>2.4.0</version>
<executions>
<execution>
<id>generate-third-party</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.redlink.more.data.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

@Configuration
@EnableCaching
@EnableScheduling
public class CachingConfiguration {

public static final String OBSERVATION_ENDINGS = "observationEndings";
private static final Logger LOGGER = LoggerFactory.getLogger(CachingConfiguration.class);
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager(OBSERVATION_ENDINGS);
}

@CacheEvict(allEntries = true, value = {OBSERVATION_ENDINGS})
@Scheduled(fixedDelay = 60 * 60 * 1000 , initialDelay = 5000)
public void reportCacheEvict() {
LOGGER.info("Flush Cache");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public SecurityFilterChain filterChain(HttpSecurity http,
//External Data Gateway
req.requestMatchers("/api/v1/external/bulk")
.permitAll();
req.requestMatchers("/api/v1/external/participants")
.permitAll();
req.requestMatchers("/api/v1/calendar/studies/*/calendar.ics")
.permitAll();
// all other apis require credentials
req.requestMatchers("/api/v1/**")
.authenticated();
Expand Down Expand Up @@ -105,4 +109,4 @@ protected RequestRejectedHandler requestRejectedHandler() {
return new HttpStatusRequestRejectedHandler(HttpStatus.I_AM_A_TEAPOT.value());
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.redlink.more.data.controller;

import io.redlink.more.data.api.app.v1.webservices.CalendarApi;
import io.redlink.more.data.service.CalendarService;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController
@RequestMapping(value = "/api/v1", produces = MediaType.APPLICATION_JSON_VALUE)
public class CalendarApiV1Controller implements CalendarApi {

private final CalendarService calendarService;

public CalendarApiV1Controller(CalendarService calendarService) {
this.calendarService = calendarService;
}

@Override
public ResponseEntity<String> getStudyCalendar(Long studyId) {
return ResponseEntity.of(
this.calendarService.getICalendarString(studyId)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public ResponseEntity<List<String>> storeBulk(DataBulkDTO dataBulkDTO) {

final RoutingInfo routingInfo = userDetails.getRoutingInfo();
try (LoggingUtils.LoggingContext ctx = LoggingUtils.createContext(userDetails.getRoutingInfo())) {
if (routingInfo.studyActive()) {
if (routingInfo.acceptData()) {
final List<String> storedIDs = elasticService.storeDataPoints(
DataTransformer.createDataPoints(dataBulkDTO), routingInfo);
return ResponseEntity.ok(storedIDs);
} else {
final List<String> discardedIDs = dataBulkDTO.getDataPoints().stream()
.map(ObservationDataDTO::getDataId)
.toList();
LOG.info("Discarding {} observations because study_{} is not 'active'",
discardedIDs.size(), routingInfo.studyId());
LOG.info("Discarding {} observations because study_{} or participant_{} is not 'active'",
discardedIDs.size(), routingInfo.studyId(), routingInfo.participantId());
return ResponseEntity.ok(
discardedIDs
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

import io.redlink.more.data.api.app.v1.model.EndpointDataBulkDTO;
import io.redlink.more.data.api.app.v1.model.ExternalDataDTO;
import io.redlink.more.data.api.app.v1.model.ParticipantDTO;
import io.redlink.more.data.api.app.v1.webservices.ExternalDataApi;
import io.redlink.more.data.controller.transformer.DataTransformer;
import io.redlink.more.data.controller.transformer.ParticipantTransformer;
import io.redlink.more.data.exception.BadRequestException;
import io.redlink.more.data.model.ApiRoutingInfo;
import io.redlink.more.data.model.RoutingInfo;
import io.redlink.more.data.model.scheduler.Interval;
import io.redlink.more.data.service.ElasticService;
import io.redlink.more.data.service.ExternalService;
import io.redlink.more.data.util.LoggingUtils;
Expand All @@ -25,15 +29,14 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Base64;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping(value = "/api/v1", produces = MediaType.APPLICATION_JSON_VALUE)
public class ExternalDataApiV1Controller implements ExternalDataApi {

private static final Logger LOG = LoggerFactory.getLogger(DataApiV1Controller.class);
private static final Logger LOG = LoggerFactory.getLogger(ExternalDataApiV1Controller.class);

private final ExternalService externalService;
private final ElasticService elasticService;

Expand All @@ -43,45 +46,45 @@ public ExternalDataApiV1Controller(ExternalService externalService, ElasticServi
}

@Override
public ResponseEntity<Void> storeExternalBulk(String moreApiToken, EndpointDataBulkDTO endpointDataBulkDTO) {
public ResponseEntity<List<ParticipantDTO>> listParticipants(String moreApiToken) {
try {
String[] split = moreApiToken.split("\\.");
String[] primaryKey = new String(Base64.getDecoder().decode(split[0])).split("-");
ApiRoutingInfo apiRoutingInfo = externalService.getRoutingInfo(moreApiToken);
return ResponseEntity.ok(
externalService.listParticipants(apiRoutingInfo.studyId(), apiRoutingInfo.studyGroupId())
.stream()
.map(ParticipantTransformer::toDTO)
.toList()
);
} catch(IndexOutOfBoundsException | NumberFormatException e) {
throw new AccessDeniedException("Invalid Token");
}
}

Long studyId = Long.valueOf(primaryKey[0]);
Integer observationId = Integer.valueOf(primaryKey[1]);
@Override
public ResponseEntity<Void> storeExternalBulk(String moreApiToken, EndpointDataBulkDTO endpointDataBulkDTO) {
try {
ApiRoutingInfo apiRoutingInfo = externalService.getRoutingInfo(moreApiToken);
Integer participantId = Integer.valueOf(endpointDataBulkDTO.getParticipantId());
Integer tokenId = Integer.valueOf(primaryKey[2]);
String secret = new String(Base64.getDecoder().decode(split[1]));
Interval interval = externalService.getIntervalForObservation(apiRoutingInfo.studyId(), apiRoutingInfo.observationId(), participantId);

final Optional<ApiRoutingInfo> apiRoutingInfo = externalService.getRoutingInfo(
studyId,
observationId,
tokenId,
secret);
if(apiRoutingInfo.isEmpty()) {
throw new AccessDeniedException("Invalid token");
}

externalService.validateTimeFrame(studyId, observationId,
endpointDataBulkDTO.getDataPoints().stream().map(datapoint ->
datapoint.getTimestamp().toInstant()
).toList());
endpointDataBulkDTO.getDataPoints().stream()
.map(datapoint -> datapoint.getTimestamp().toInstant())
.map(timestamp -> timestamp.isBefore(interval.getStart()) || timestamp.isAfter(interval.getEnd()))
.filter(v -> v)
.findFirst()
.orElseThrow(BadRequestException::TimeFrame);

final RoutingInfo routingInfo = new RoutingInfo(
externalService.validateRoutingInfo(apiRoutingInfo.get(), participantId),
participantId
);
final RoutingInfo routingInfo = externalService.validateAndCreateRoutingInfo(apiRoutingInfo, participantId);
try (LoggingUtils.LoggingContext ctx = LoggingUtils.createContext(routingInfo)) {
if(routingInfo.studyActive()) {
if(routingInfo.acceptData()) {
elasticService.storeDataPoints(
DataTransformer.createDataPoints(endpointDataBulkDTO, apiRoutingInfo.get(), observationId),
DataTransformer.createDataPoints(endpointDataBulkDTO, apiRoutingInfo, apiRoutingInfo.observationId()),
routingInfo
);
} else {
final List<ExternalDataDTO> discardedIDs = endpointDataBulkDTO.getDataPoints();
LOG.info("Discarding {} observations because study_{} is not 'active'",
discardedIDs.size(), routingInfo.studyId());
LOG.info("Discarding {} observations because either study_{} or participant_{} is not 'active'",
discardedIDs.size(), routingInfo.studyId(), routingInfo.participantId());
}
return ResponseEntity.noContent().build();
}
Expand Down
Loading
Loading