Skip to content

Commit

Permalink
Add RAT Valueset Download (#110)
Browse files Browse the repository at this point in the history
* Add Shedlock Table
Implement RAT Valueset Download

* Add missing trailing new line

* Add Unit Tests
Remove enabled flag for proxy -> Autodetection
Disable Sheduling for Tests

* Update RatValuesetUpdateServiceTest.java

* Update pom.xml
  • Loading branch information
f11h committed Jul 7, 2021
1 parent 1146c40 commit 0adf041
Show file tree
Hide file tree
Showing 20 changed files with 1,055 additions and 1 deletion.
32 changes: 32 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
<bcpkix.version>1.68</bcpkix.version>
<semver4j.version>3.1.0</semver4j.version>
<json-schema.version>1.12.3</json-schema.version>
<shedlock.version>4.20.0</shedlock.version>
<spring.cloud.version>2020.0.3</spring.cloud.version>
<!-- plugins -->
<plugin.maven-assembly.version>3.3.0</plugin.maven-assembly.version>
<plugin.checkstyle.version>3.1.2</plugin.checkstyle.version>
Expand Down Expand Up @@ -134,6 +136,18 @@
</repository>
</distributionManagement>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring.cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>eu.europa.ec.dgc</groupId>
Expand Down Expand Up @@ -179,6 +193,14 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -224,6 +246,16 @@
<artifactId>spring-security-web</artifactId>
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-provider-jdbc-template</artifactId>
<version>${shedlock.version}</version>
</dependency>
<dependency>
<groupId>net.javacrumbs.shedlock</groupId>
<artifactId>shedlock-spring</artifactId>
<version>${shedlock.version}</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.cloud.openfeign.EnableFeignClients;

/**
* The Application class.
*/
@SpringBootApplication
@EnableFeignClients
@EnableConfigurationProperties(DgcConfigProperties.class)
public class DgcGatewayApplication extends SpringBootServletInitializer {

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/eu/europa/ec/dgc/gateway/client/JrcClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*-
* ---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.client;

import eu.europa.ec.dgc.gateway.model.JrcRatValuesetResponse;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(
name = "jrcClient",
url = "${dgc.jrc.url}",
configuration = JrcClientConfig.class)
public interface JrcClient {

/**
* This method gets a the RAT values from JRC API.
*
* @return List of RAT values.
*/
@GetMapping(value = "", produces = MediaType.APPLICATION_JSON_VALUE
)
JrcRatValuesetResponse downloadRatValues();
}
94 changes: 94 additions & 0 deletions src/main/java/eu/europa/ec/dgc/gateway/client/JrcClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*-
* ---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.client;

import eu.europa.ec.dgc.gateway.config.DgcConfigProperties;
import feign.Client;
import feign.httpclient.ApacheHttpClient;
import java.security.NoSuchAlgorithmException;
import javax.net.ssl.SSLContext;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.conn.ssl.DefaultHostnameVerifier;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@RequiredArgsConstructor
@Slf4j
public class JrcClientConfig {

private final DgcConfigProperties config;

/**
* Configure the client depending on the ssl properties.
*
* @return an Apache Http Client with or without SSL features
*/
@Bean
public Client jrcClient() throws NoSuchAlgorithmException {
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();

httpClientBuilder.setSSLContext(SSLContext.getDefault());
httpClientBuilder.setSSLHostnameVerifier(new DefaultHostnameVerifier());

if (config.getJrc().getProxy().getHost() != null
&& config.getJrc().getProxy().getPort() != -1
&& !config.getJrc().getProxy().getHost().isEmpty()) {
log.info("Using Proxy for JRC Connection");
// Set proxy
httpClientBuilder.setProxy(new HttpHost(
config.getJrc().getProxy().getHost(),
config.getJrc().getProxy().getPort()
));

// Set proxy authentication
if (config.getJrc().getProxy().getUsername() != null
&& config.getJrc().getProxy().getPassword() != null
&& !config.getJrc().getProxy().getUsername().isEmpty()
&& !config.getJrc().getProxy().getPassword().isEmpty()) {

log.info("Using Proxy with Authentication for JRC Connection");

CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(
new AuthScope(
config.getJrc().getProxy().getHost(),
config.getJrc().getProxy().getPort()),
new UsernamePasswordCredentials(
config.getJrc().getProxy().getUsername(),
config.getJrc().getProxy().getPassword()));

httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
} else {
log.info("Using no proxy for JRC Connection");
}

return new ApacheHttpClient(httpClientBuilder.build());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,26 @@ public class DgcConfigProperties {

private String validationRuleSchema;

private JrcConfig jrc = new JrcConfig();

@Getter
@Setter
public static class JrcConfig {
private String url;
private Integer interval = 21_600_000;
private ProxyConfig proxy = new ProxyConfig();
}

@Getter
@Setter
public static class ProxyConfig {

private String host;
private int port = -1;
private String username;
private String password;
}

@Getter
@Setter
public static class TrustAnchor {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/eu/europa/ec/dgc/gateway/config/SchedulerConfig.java
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.config;

import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@Profile("!test")
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "PT30S")
public class SchedulerConfig {
}
53 changes: 53 additions & 0 deletions src/main/java/eu/europa/ec/dgc/gateway/config/ShedLockConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*-
* ---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.config;

import static net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider.Configuration.builder;

import javax.sql.DataSource;
import lombok.RequiredArgsConstructor;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.jdbctemplate.JdbcTemplateLockProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
@RequiredArgsConstructor
public class ShedLockConfig {

private final DataSource dataSource;

/**
* Creates a LockProvider for ShedLock.
*
* @return LockProvider
*/
@Bean
public LockProvider lockProvider() {
return new JdbcTemplateLockProvider(builder()
.withTableName("shedlock")
.withJdbcTemplate(new JdbcTemplate(dataSource))
.usingDbTime()
.build()
);
}
}
Loading

0 comments on commit 0adf041

Please sign in to comment.