Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface DPPPTDataService {
* @param batchLength
* @return
*/
int getMaxExposedIdForBatchReleaseTime(Long batchReleaseTime, long batchLength);
int getMaxExposedIdForBatchReleaseTime(long batchReleaseTime, long batchLength);

/**
* Returns all exposees for the given batch.
Expand All @@ -49,7 +49,7 @@ public interface DPPPTDataService {
* @param batchLength
* @return
*/
List<Exposee> getSortedExposedForBatchReleaseTime(Long batchReleaseTime, long batchLength);
List<Exposee> getSortedExposedForBatchReleaseTime(long batchReleaseTime, long batchLength);

/**
* deletes entries older than retentionperiod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void upsertExposees(List<Exposee> exposees, String appSource) {

@Override
@Transactional(readOnly = true)
public int getMaxExposedIdForBatchReleaseTime(Long batchReleaseTime, long batchLength) {
public int getMaxExposedIdForBatchReleaseTime(long batchReleaseTime, long batchLength) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("batchReleaseTime", Date.from(Instant.ofEpochMilli(batchReleaseTime)));
params.addValue("startBatch", Date.from(Instant.ofEpochMilli(batchReleaseTime - batchLength)));
Expand All @@ -97,7 +97,7 @@ public int getMaxExposedIdForBatchReleaseTime(Long batchReleaseTime, long batchL

@Override
@Transactional(readOnly = true)
public List<Exposee> getSortedExposedForBatchReleaseTime(Long batchReleaseTime, long batchLength) {
public List<Exposee> getSortedExposedForBatchReleaseTime(long batchReleaseTime, long batchLength) {
String sql = "select pk_exposed_id, key, key_date from t_exposed where received_at >= :startBatch and received_at < :batchReleaseTime order by pk_exposed_id desc";
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("batchReleaseTime", Date.from(Instant.ofEpochMilli(batchReleaseTime)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class ExposeeRequestList {
@NotNull
@NotEmpty
List<ExposedKey> exposedKeys;
List<@NotNull ExposedKey> exposedKeys;

private Integer fake = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;

import javax.validation.Valid;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.dpppt.backend.sdk.data.DPPPTDataService;
import org.dpppt.backend.sdk.model.BucketList;
import org.dpppt.backend.sdk.model.ExposedOverview;
Expand All @@ -36,6 +38,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -153,22 +156,22 @@ public DPPPTController(DPPPTDataService dataService, String appSource,

@CrossOrigin(origins = { "https://editor.swagger.io" })
@GetMapping(value = "/exposedjson/{batchReleaseTime}", produces = "application/json")
public @ResponseBody ResponseEntity<ExposedOverview> getExposedByDayDate(@PathVariable Long batchReleaseTime,
public @ResponseBody ResponseEntity<ExposedOverview> getExposedByDayDate(@PathVariable long batchReleaseTime,
WebRequest request) throws BadBatchReleaseTimeException{
if(!validationUtils.isValidBatchReleaseTime(batchReleaseTime)) {
return ResponseEntity.notFound().build();
}

List<Exposee> exposeeList = dataService.getSortedExposedForBatchReleaseTime(batchReleaseTime, batchLength);
ExposedOverview overview = new ExposedOverview(exposeeList);
overview.setBatchReleaseTime(batchReleaseTime);
return ResponseEntity.ok().cacheControl(CacheControl.maxAge(Duration.ofMinutes(exposedListCacheContol)))
.header("X-BATCH-RELEASE-TIME", batchReleaseTime.toString()).body(overview);
.header("X-BATCH-RELEASE-TIME", Long.toString(batchReleaseTime)).body(overview);
}

@CrossOrigin(origins = { "https://editor.swagger.io" })
@GetMapping(value = "/exposed/{batchReleaseTime}", produces = "application/x-protobuf")
public @ResponseBody ResponseEntity<Exposed.ProtoExposedList> getExposedByBatch(@PathVariable Long batchReleaseTime,
public @ResponseBody ResponseEntity<Exposed.ProtoExposedList> getExposedByBatch(@PathVariable long batchReleaseTime,
WebRequest request) throws BadBatchReleaseTimeException {
if(!validationUtils.isValidBatchReleaseTime(batchReleaseTime)) {
return ResponseEntity.notFound().build();
Expand All @@ -186,7 +189,7 @@ public DPPPTController(DPPPTDataService dataService, String appSource,
.setBatchReleaseTime(batchReleaseTime).build();

return ResponseEntity.ok().cacheControl(CacheControl.maxAge(Duration.ofMinutes(exposedListCacheContol)))
.header("X-BATCH-RELEASE-TIME", batchReleaseTime.toString()).body(protoExposee);
.header("X-BATCH-RELEASE-TIME", Long.toString(batchReleaseTime)).body(protoExposee);
}

@CrossOrigin(origins = { "https://editor.swagger.io" })
Expand All @@ -206,21 +209,11 @@ public DPPPTController(DPPPTDataService dataService, String appSource,
return ResponseEntity.ok(list);
}

@ExceptionHandler(IllegalArgumentException.class)
@ExceptionHandler({IllegalArgumentException.class, InvalidDateException.class, JsonProcessingException.class,
MethodArgumentNotValidException.class, BadBatchReleaseTimeException.class, DateTimeParseException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<Object> invalidArguments() {
return ResponseEntity.badRequest().build();
}

@ExceptionHandler(InvalidDateException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<Object> invalidDate() {
return ResponseEntity.badRequest().build();
}
@ExceptionHandler(BadBatchReleaseTimeException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<Object> invalidBatchReleaseTime() {
return ResponseEntity.badRequest().build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public DebugController(DebugGAENDataService dataService, ProtoSignature gaenSign
}

@GetMapping(value = "/exposed/{batchReleaseTime}", produces = "application/zip")
public @ResponseBody ResponseEntity<byte[]> getExposedKeys(@PathVariable Long batchReleaseTime, WebRequest request)
public @ResponseBody ResponseEntity<byte[]> getExposedKeys(@PathVariable long batchReleaseTime, WebRequest request)
throws BadBatchReleaseTimeException, IOException, InvalidKeyException,
NoSuchAlgorithmException, SignatureException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Date;
Expand All @@ -27,6 +28,7 @@

import javax.validation.Valid;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.dpppt.backend.sdk.data.gaen.FakeKeyService;
import org.dpppt.backend.sdk.data.gaen.GAENDataService;
import org.dpppt.backend.sdk.model.gaen.DayBuckets;
Expand All @@ -50,6 +52,7 @@
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down Expand Up @@ -221,7 +224,7 @@ public GaenController(GAENDataService dataService, FakeKeyService fakeKeyService
}

@GetMapping(value = "/exposed/{keyDate}", produces = "application/zip")
public @ResponseBody ResponseEntity<byte[]> getExposedKeys(@PathVariable Long keyDate,
public @ResponseBody ResponseEntity<byte[]> getExposedKeys(@PathVariable long keyDate,
@RequestParam(required = false) Long publishedafter, WebRequest request)
throws BadBatchReleaseTimeException, IOException, InvalidKeyException, SignatureException,
NoSuchAlgorithmException {
Expand Down Expand Up @@ -255,7 +258,7 @@ public GaenController(GAENDataService dataService, FakeKeyService fakeKeyService
}

@GetMapping(value = "/exposedjson/{keyDate}", produces = "application/json")
public @ResponseBody ResponseEntity<GaenExposedJson> getExposedKeysAsJson(@PathVariable Long keyDate,
public @ResponseBody ResponseEntity<GaenExposedJson> getExposedKeysAsJson(@PathVariable long keyDate,
@RequestParam(required = false) Long publishedafter, WebRequest request)
throws BadBatchReleaseTimeException {
if (!validationUtils.isValidKeyDate(keyDate)) {
Expand Down Expand Up @@ -316,21 +319,10 @@ private void normalizeRequestTime(long now) {
}
}

@ExceptionHandler(IllegalArgumentException.class)
@ExceptionHandler({IllegalArgumentException.class, InvalidDateException.class, JsonProcessingException.class,
MethodArgumentNotValidException.class, BadBatchReleaseTimeException.class, DateTimeParseException.class})
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<Object> invalidArguments() {
return ResponseEntity.badRequest().build();
}

@ExceptionHandler(InvalidDateException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<Object> invalidDate() {
return ResponseEntity.badRequest().build();
}

@ExceptionHandler(BadBatchReleaseTimeException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResponseEntity<Object> invalidBatchReleaseTime() {
return ResponseEntity.badRequest().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public boolean isDateInRange(OffsetDateTime timestamp) {
* @param keyDate
* @return
*/
public boolean isValidKeyDate(Long keyDate) {
public boolean isValidKeyDate(long keyDate) {
return (Instant.ofEpochMilli(keyDate).atOffset(ZoneOffset.UTC).getHour() == 0);
}

public boolean isValidBatchReleaseTime(Long batchReleaseTime) throws BadBatchReleaseTimeException {
public boolean isValidBatchReleaseTime(long batchReleaseTime) throws BadBatchReleaseTimeException {
if (batchReleaseTime % batchLength != 0) {
throw new BadBatchReleaseTimeException();
}
Expand Down