This repository has been archived by the owner on Sep 15, 2023. It is now read-only.
-
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 #14 from admin-ch/feature/valuesets
Feature/valuesets
- Loading branch information
Showing
22 changed files
with
1,271 additions
and
30 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
110 changes: 110 additions & 0 deletions
110
...ava/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ValueSetsController.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,110 @@ | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package ch.admin.bag.covidcertificate.backend.verifier.ws.controller; | ||
|
||
import ch.admin.bag.covidcertificate.backend.verifier.ws.model.valuesets.TestValueSets; | ||
import ch.admin.bag.covidcertificate.backend.verifier.ws.model.valuesets.VaccineValueSets; | ||
import ch.admin.bag.covidcertificate.backend.verifier.ws.model.valuesets.ValueSets; | ||
import ch.admin.bag.covidcertificate.backend.verifier.ws.utils.CacheUtil; | ||
import ch.admin.bag.covidcertificate.backend.verifier.ws.utils.EtagUtil; | ||
import ch.ubique.openapi.docannotations.Documentation; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.http.HttpHeaders; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.http.CacheControl; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
@RequestMapping("trust/v1") | ||
public class ValueSetsController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ValueSetsController.class); | ||
|
||
public static final List<String> PATHS_TO_VALUE_SETS = | ||
List.of( | ||
"valuesets/test-manf.json", | ||
"valuesets/test-type.json", | ||
"valuesets/vaccine-mah-manf.json", | ||
"valuesets/vaccine-medicinal-product.json", | ||
"valuesets/vaccine-prophylaxis.json"); | ||
|
||
private final ValueSets valueSets; | ||
private final String valueSetsEtag; | ||
private final ObjectMapper mapper = new ObjectMapper(); | ||
|
||
public ValueSetsController() throws IOException, NoSuchAlgorithmException { | ||
this.valueSets = new ValueSets(getTestValueSet(), getVaccineValueSet()); | ||
|
||
List<String> pathsToValueSets = new ArrayList<>(); | ||
for (String path : PATHS_TO_VALUE_SETS) { | ||
pathsToValueSets.add(new ClassPathResource(path).getFile().getPath()); | ||
} | ||
this.valueSetsEtag = | ||
EtagUtil.getSha1HashForFiles( | ||
pathsToValueSets.toArray(new String[pathsToValueSets.size()])); | ||
} | ||
|
||
private VaccineValueSets getVaccineValueSet() throws IOException { | ||
VaccineValueSets vaccine = new VaccineValueSets(); | ||
vaccine.setMahManf(readFileAsMap("valuesets/vaccine-mah-manf.json")); | ||
vaccine.setMedicinalProduct(readFileAsMap("valuesets/vaccine-medicinal-product.json")); | ||
vaccine.setProphylaxis(readFileAsMap("valuesets/vaccine-prophylaxis.json")); | ||
return vaccine; | ||
} | ||
|
||
private TestValueSets getTestValueSet() throws IOException { | ||
TestValueSets test = new TestValueSets(); | ||
test.setManf(readFileAsMap("valuesets/test-manf.json")); | ||
test.setType(readFileAsMap("valuesets/test-type.json")); | ||
return test; | ||
} | ||
|
||
/** | ||
* maps a file to a generic {@link Map} | ||
* | ||
* @param path relative to classpath | ||
* @return | ||
*/ | ||
private Map readFileAsMap(String path) throws IOException { | ||
File file = new ClassPathResource(path).getFile(); | ||
return mapper.readValue(file, Map.class); | ||
} | ||
|
||
@Documentation( | ||
description = "get value sets", | ||
responses = {"200 => value sets", "304 => no changes since last request"}, | ||
responseHeaders = {"ETag:etag to set for next request:string"}) | ||
@GetMapping(value = "/metadata") | ||
public @ResponseBody ResponseEntity<ValueSets> getVerificationRules( | ||
@RequestHeader(value = HttpHeaders.ETAG, required = false) String etag) { | ||
if (valueSetsEtag.equals(etag)) { | ||
return ResponseEntity.status(HttpStatus.NOT_MODIFIED).build(); | ||
} | ||
return ResponseEntity.ok() | ||
.header(HttpHeaders.ETAG, valueSetsEtag) | ||
.cacheControl(CacheControl.maxAge(CacheUtil.VALUE_SETS_MAX_AGE)) | ||
.body(valueSets); | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
...java/ch/admin/bag/covidcertificate/backend/verifier/ws/model/valuesets/TestValueSets.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,34 @@ | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package ch.admin.bag.covidcertificate.backend.verifier.ws.model.valuesets; | ||
|
||
import java.util.Map; | ||
|
||
public class TestValueSets { | ||
private Map type; | ||
private Map manf; | ||
|
||
public Map getType() { | ||
return type; | ||
} | ||
|
||
public void setType(Map type) { | ||
this.type = type; | ||
} | ||
|
||
public Map getManf() { | ||
return manf; | ||
} | ||
|
||
public void setManf(Map manf) { | ||
this.manf = manf; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...a/ch/admin/bag/covidcertificate/backend/verifier/ws/model/valuesets/VaccineValueSets.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,43 @@ | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package ch.admin.bag.covidcertificate.backend.verifier.ws.model.valuesets; | ||
|
||
import java.util.Map; | ||
|
||
public class VaccineValueSets { | ||
private Map mahManf; | ||
private Map medicinalProduct; | ||
private Map prophylaxis; | ||
|
||
public Map getMahManf() { | ||
return mahManf; | ||
} | ||
|
||
public void setMahManf(Map mahManf) { | ||
this.mahManf = mahManf; | ||
} | ||
|
||
public Map getMedicinalProduct() { | ||
return medicinalProduct; | ||
} | ||
|
||
public void setMedicinalProduct(Map medicinalProduct) { | ||
this.medicinalProduct = medicinalProduct; | ||
} | ||
|
||
public Map getProphylaxis() { | ||
return prophylaxis; | ||
} | ||
|
||
public void setProphylaxis(Map prophylaxis) { | ||
this.prophylaxis = prophylaxis; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...ain/java/ch/admin/bag/covidcertificate/backend/verifier/ws/model/valuesets/ValueSets.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,39 @@ | ||
/* | ||
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package ch.admin.bag.covidcertificate.backend.verifier.ws.model.valuesets; | ||
|
||
public class ValueSets { | ||
private TestValueSets test; | ||
private VaccineValueSets vaccine; | ||
|
||
public ValueSets() {} | ||
|
||
public ValueSets(TestValueSets test, VaccineValueSets vaccine) { | ||
this.test = test; | ||
this.vaccine = vaccine; | ||
} | ||
|
||
public TestValueSets getTest() { | ||
return test; | ||
} | ||
|
||
public void setTest(TestValueSets test) { | ||
this.test = test; | ||
} | ||
|
||
public VaccineValueSets getVaccine() { | ||
return vaccine; | ||
} | ||
|
||
public void setVaccine(VaccineValueSets vaccine) { | ||
this.vaccine = vaccine; | ||
} | ||
} |
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
4 changes: 3 additions & 1 deletion
4
...r/ch-covidcertificate-backend-verifier-ws/src/main/resources/application-local.properties
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# test p12 for local development use | ||
ws.jws.p12=MIINSQIBAzCCDQ8GCSqGSIb3DQEHAaCCD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mfZoigqOWEAnAU93p3Ky5LvRXMdOC6usy/dWy/p5lyVPer2HYWd2t1L9Euq50qCqCaFhUcTRUW1VIzUrI6KetlVlMSUwIwYJKoZIhvcNAQkVMRYEFIK2RpYoOGhJlVhZNI60I1JFWjcNMDEwITAJBgUrDgMCGgUABBRWMvkaO38E9Q4F7E1hrf+/1r4i2wQIswDDbBNBcXMCAggA | ||
ws.jws.password=test | ||
ws.jws.password=test | ||
|
||
ws.authentication.apiKeys.local=4d1d5663-b4ef-46a5-85b6-3d1d376429da |
Oops, something went wrong.