-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from redlink-gmbh/FEATURE-Relative_Study_Start
Feature relative study start
- Loading branch information
Showing
26 changed files
with
834 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/io/redlink/more/data/configuration/CachingConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/io/redlink/more/data/controller/CalendarApiV1Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 this.calendarService.getICalendarString(studyId) | ||
.map(ResponseEntity::ok) | ||
.orElseThrow(RuntimeException::new); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/io/redlink/more/data/model/StudyDurationInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.redlink.more.data.model; | ||
|
||
import io.redlink.more.data.model.scheduler.Duration; | ||
import org.apache.commons.lang3.tuple.Pair; | ||
import java.time.LocalDate; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class StudyDurationInfo{ | ||
private LocalDate endDate; | ||
private LocalDate startDate; | ||
private Duration duration; | ||
private final List<Pair<Integer, Duration>> groupDurations = new ArrayList<>(); | ||
|
||
public LocalDate getEndDate() { | ||
return endDate; | ||
} | ||
|
||
public StudyDurationInfo setEndDate(LocalDate endDate) { | ||
this.endDate = endDate; | ||
return this; | ||
} | ||
|
||
public LocalDate getStartDate() { | ||
return startDate; | ||
} | ||
|
||
public StudyDurationInfo setStartDate(LocalDate startDate) { | ||
this.startDate = startDate; | ||
return this; | ||
} | ||
|
||
public Duration getDuration() { | ||
return duration; | ||
} | ||
|
||
public StudyDurationInfo setDuration(Duration duration) { | ||
this.duration = duration; | ||
return this; | ||
} | ||
|
||
public List<Pair<Integer, Duration>> getGroupDurations() { | ||
return groupDurations; | ||
} | ||
|
||
public StudyDurationInfo addGroupDuration(Pair<Integer, Duration> gd) { | ||
this.groupDurations.add(gd); | ||
return this; | ||
} | ||
|
||
public Duration getDurationFor(Integer group) { | ||
if(group == null) { | ||
return getDurationFallback(); | ||
} else { | ||
return this.groupDurations.stream() | ||
.filter(gd -> gd.getLeft().equals(group)) | ||
.findFirst() | ||
.map(Pair::getRight) | ||
.orElse(getDurationFallback()); | ||
} | ||
} | ||
|
||
private Duration getDurationFallback() { | ||
if(this.duration != null) { | ||
return duration; | ||
} else { | ||
return new Duration().setUnit(Duration.Unit.DAY).setValue((int) startDate.until(endDate, ChronoUnit.DAYS)); | ||
} | ||
} | ||
} |
Oops, something went wrong.