-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Valuesets Implementation * Add Unit Tests * Checkstyle * Add new Unit Test
- Loading branch information
Showing
10 changed files
with
1,052 additions
and
0 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
50 changes: 50 additions & 0 deletions
50
src/main/java/eu/europa/ec/dgc/gateway/entity/ValuesetEntity.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,50 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.entity; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "valueset") | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ValuesetEntity { | ||
|
||
@Id | ||
@Column(name = "id", length = 100) | ||
String id; | ||
|
||
/** | ||
* Signature of the TrustAnchor. | ||
*/ | ||
@Column(name = "json", nullable = false, length = 10240) | ||
String json; | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/eu/europa/ec/dgc/gateway/repository/ValuesetRepository.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,33 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.repository; | ||
|
||
import eu.europa.ec.dgc.gateway.entity.ValuesetEntity; | ||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface ValuesetRepository extends JpaRepository<ValuesetEntity, String> { | ||
|
||
@Query("SELECT v.id FROM ValuesetEntity v") | ||
List<String> getIds(); | ||
|
||
} |
131 changes: 131 additions & 0 deletions
131
src/main/java/eu/europa/ec/dgc/gateway/restapi/controller/ValuesetController.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,131 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.restapi.controller; | ||
|
||
import eu.europa.ec.dgc.gateway.exception.DgcgResponseException; | ||
import eu.europa.ec.dgc.gateway.restapi.dto.ProblemReportDto; | ||
import eu.europa.ec.dgc.gateway.restapi.filter.CertificateAuthenticationRequired; | ||
import eu.europa.ec.dgc.gateway.service.ValuesetService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||
import io.swagger.v3.oas.annotations.media.ArraySchema; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/valuesets") | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ValuesetController { | ||
|
||
private final ValuesetService valuesetService; | ||
|
||
/** | ||
* Controller to get valueset ids. | ||
*/ | ||
@CertificateAuthenticationRequired | ||
@GetMapping(path = "") | ||
@Operation( | ||
summary = "Gets a list of available valuesets.", | ||
tags = {"Valueset"}, | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "List of valueset ids", | ||
content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class))) | ||
), | ||
@ApiResponse( | ||
responseCode = "401", | ||
description = "Unauthorized. No Access to the system. (Client Certificate not present or whitelisted)", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = ProblemReportDto.class) | ||
)) | ||
} | ||
) | ||
public ResponseEntity<List<String>> getValuesetIds() { | ||
return ResponseEntity.ok(valuesetService.getValuesetIds()); | ||
} | ||
|
||
/** | ||
* Controller to get a specific valueset. | ||
*/ | ||
@CertificateAuthenticationRequired | ||
@GetMapping(path = "/{id}") | ||
@Operation( | ||
summary = "Requests a specific valueset by its id.", | ||
tags = {"Valueset"}, | ||
parameters = @Parameter(in = ParameterIn.PATH, name = "id", description = "Valueset ID"), | ||
responses = { | ||
@ApiResponse( | ||
responseCode = "200", | ||
description = "Valueset JSON Object", | ||
content = @Content(schema = @Schema(implementation = String.class)) | ||
), | ||
@ApiResponse( | ||
responseCode = "401", | ||
description = "Unauthorized. No Access to the system. (Client Certificate not present or whitelisted)", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = ProblemReportDto.class) | ||
)), | ||
@ApiResponse( | ||
responseCode = "404", | ||
description = "Valueset not found", | ||
content = @Content( | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
schema = @Schema(implementation = ProblemReportDto.class) | ||
)) | ||
} | ||
) | ||
public ResponseEntity<String> getValueset(@PathVariable("id") String id) { | ||
|
||
Optional<String> valueset = valuesetService.getValueSetById(id); | ||
|
||
if (valueset.isEmpty()) { | ||
throw new DgcgResponseException( | ||
HttpStatus.NOT_FOUND, | ||
"0x100", | ||
"Valueset not found", | ||
String.format("Requested valueset id %s", id), | ||
"Use the GET /valuesets endpoint to get a list of available valueset ids."); | ||
} | ||
|
||
return ResponseEntity | ||
.status(HttpStatus.OK) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.body(valueset.get()); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/eu/europa/ec/dgc/gateway/service/ValuesetService.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,63 @@ | ||
/*- | ||
* ---license-start | ||
* EU Digital Green Certificate Gateway Service / dgc-gateway | ||
* --- | ||
* Copyright (C) 2021 T-Systems International GmbH and all other contributors | ||
* --- | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* ---license-end | ||
*/ | ||
|
||
package eu.europa.ec.dgc.gateway.service; | ||
|
||
import eu.europa.ec.dgc.gateway.entity.ValuesetEntity; | ||
import eu.europa.ec.dgc.gateway.repository.ValuesetRepository; | ||
import eu.europa.ec.dgc.gateway.utils.DgcMdc; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class ValuesetService { | ||
|
||
private final ValuesetRepository valuesetRepository; | ||
|
||
/** | ||
* Gets a list of existing valueset IDs. | ||
* | ||
* @return List of Strings | ||
*/ | ||
public List<String> getValuesetIds() { | ||
log.info("Getting ValueSet IDs"); | ||
|
||
return valuesetRepository.getIds(); | ||
} | ||
|
||
/** | ||
* Gets the content of a valueset by its id. | ||
* | ||
* @param id id of the valueset | ||
* @return the json content | ||
*/ | ||
public Optional<String> getValueSetById(String id) { | ||
DgcMdc.put("valueSetId", id); | ||
log.info("Requesting Value Set."); | ||
|
||
return valuesetRepository.findById(id).map(ValuesetEntity::getJson); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<databaseChangeLog | ||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog | ||
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd" | ||
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS"> | ||
<changeSet id="1623765906647-1" author="f11h"> | ||
<createTable tableName="valueset"> | ||
<column name="id" type="VARCHAR(100)"> | ||
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_VALUESET"/> | ||
</column> | ||
<column name="json" type="VARCHAR(10240)"> | ||
<constraints nullable="false"/> | ||
</column> | ||
</createTable> | ||
</changeSet> | ||
|
||
</databaseChangeLog> |
Oops, something went wrong.