Skip to content

Commit

Permalink
Add Valueset Feature (#84)
Browse files Browse the repository at this point in the history
* Valuesets Implementation

* Add Unit Tests

* Checkstyle

* Add new Unit Test
  • Loading branch information
f11h authored Jun 16, 2021
1 parent e09fd8f commit dbe26ea
Show file tree
Hide file tree
Showing 10 changed files with 1,052 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/software-design-dgc-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ This is a List of all Possible Problem Reports that can be returned.
| 0x006 | Upload of Signer Certificate failed | Parameters send in the request | Contains the exception message |
| 0x007 | Possible reasons: Wrong Format no CMS, not the correct signing alg missing attributes, invalid signature, certificate not signed by known CA | Parameters send in the request | Contains the exception message |
| 0x008 | Internal Server Error | Not Available | Not Available |
| 0x100 | Valueset not found | The requested valueset ID | Not available |


## Monitoring
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/eu/europa/ec/dgc/gateway/entity/ValuesetEntity.java
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;

}
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();

}
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());
}

}
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);
}

}
1 change: 1 addition & 0 deletions src/main/resources/db/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.3.xsd">
<include file="db/changelog/init-tables.xml"/>
<include file="db/changelog/create-audit-table.xml"/>
<include file="db/changelog/add-valueset-table.xml"/>


</databaseChangeLog>
19 changes: 19 additions & 0 deletions src/main/resources/db/changelog/add-valueset-table.xml
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>
Loading

0 comments on commit dbe26ea

Please sign in to comment.