Skip to content

Commit

Permalink
Merge pull request #227 from usnistgov/feature/ODD-1007
Browse files Browse the repository at this point in the history
Customization API java libraries updates
  • Loading branch information
RayPlante authored Dec 20, 2021
2 parents 5136672 + 04e76e4 commit 8964816
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 180 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/java-source.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
push:
branches-ignore: ['main', 'integration']
paths:
- 'java/src/**'
- 'java/pom.xml'
- 'java/*/src/**'
- 'java/*/pom.xml'
jobs:
buildtest:
runs-on: ubuntu-20.04
Expand All @@ -20,7 +20,7 @@ jobs:
uses: actions/cache@v2
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('java/pom.xml') }}
key: ${{ runner.os }}-m2-${{ hashFiles('java/customization-api/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Set up JDK
Expand All @@ -30,7 +30,7 @@ jobs:
distribution: 'adopt'

- name: Test with Maven
run: cd java && mvn --batch-mode test
run: cd java/customization-api && mvn --batch-mode test



4 changes: 2 additions & 2 deletions .github/workflows/testall.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
- name: Build & Run Python Tests via Docker
run: cd docker && ./testall python

- name: Build & Run Java Tests via Docker
run: cd docker && ./makedist java
- name: Test Java via Docker
run: cd docker && ./testall java

- name: Build Angular Code
run: cd docker && ./makedist angular
Expand Down

This file was deleted.

91 changes: 58 additions & 33 deletions java/customization-api/pom.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<version>2.5.4</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>gov.nist.oar.custom</groupId>
<groupId>gov.nist.oar.customizationapi</groupId>
<artifactId>customization-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>customization-api</name>
<description>Spring boot application to save customization changes from PDR</description>

<packaging>jar</packaging>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
<springfox.version>2.9.2</springfox.version>
<spring-cloud.version>2020.0.4</spring-cloud.version>
<org.springframework.data.version>3.0.3.RELEASE</org.springframework.data.version>
<querydsl.version>4.3.1</querydsl.version>
<mysema.maven.version>1.1.3</mysema.maven.version>
<mongodb-reactivestreams.version>4.1.0</mongodb-reactivestreams.version>
<projectreactor.version>3.2.0.RELEASE</projectreactor.version>
<mongodb-driver.version>4.0.5</mongodb-driver.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>

</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-reactivestreams</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand All @@ -55,7 +69,7 @@
<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>1.0.3.RELEASE</version>
<version>1.0.10.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -74,44 +88,35 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.62</version>
<version>1.69</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.62</version>
<version>1.69</version>
</dependency>

<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>7.9</version>
</dependency>


<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox.version}</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox.version}</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.4</version>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.4</version>
<version>2.0.9</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -133,17 +138,35 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-test -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<!-- <version>5.2.2.RELEASE</version> -->
<scope>test</scope>
</dependency>


</dependencies>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.7</version>
</dependency>

<dependency>
<groupId>org.opensaml</groupId>
<artifactId>opensaml</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>


<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
Expand All @@ -155,7 +178,6 @@
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>customization-api</finalName>
<plugins>
Expand All @@ -174,7 +196,6 @@
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>spring-milestones</id>
Expand All @@ -189,12 +210,16 @@
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
<repository>
<id>Shibbolet</id>
<name>Shibbolet</name>
<url>https://build.shibboleth.net/nexus/content/repositories/releases/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>

</project>
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
package gov.nist.oar.customizationapi;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;
/***
* The class is an entry point for an application to start running on server.
* @author Deoyani Nandrekar-Heinis
Expand All @@ -23,4 +37,55 @@ public static void main(String[] args) {
SpringApplication.run(CustomizationApiApplication.class, args);
}

@Bean
public OpenAPI customOpenAPI(@Value("1.1.0") String appVersion) {
appVersion = VERSION;
List<Server> servers = new ArrayList<>();
servers.add(new Server().url("/customization"));
String description = "These are set of APIs which are used by data publishing workflow to edit new dataset metadata records.";


return new OpenAPI()
.components(new Components().addSecuritySchemes("basicScheme",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
.components(new Components()).servers(servers)
.info(new Info().title("Metadata Cutomization API")
.description(description)
.version(appVersion)

.license(new License().name("NIST Software").url("https://www.nist.gov/open/copyright-fair-use-and-licensing-statements-srd-data-software-and-technical-series-publications")));
}

/**
* The service name
*/
public final static String NAME;

/**
* The version of the service
*/
public final static String VERSION;

static {
String name = null;
String version = null;
try (InputStream verf = CustomizationApiApplication.class.getClassLoader().getResourceAsStream("VERSION")) {
if (verf == null) {
name = "oar-customization";
version = "not set";
}
else {
BufferedReader vrdr = new BufferedReader(new InputStreamReader(verf));
String line = vrdr.readLine();
String[] parts = line.split("\\s+");
name = parts[0];
version = (parts.length > 1) ? parts[1] : "missing";
}
} catch (Exception ex) {
name = "oar-customization";
version = "unknown";
}
NAME = name;
VERSION = version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package gov.nist.oar.customizationapi.config;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.annotation.PostConstruct;
Expand All @@ -25,14 +26,18 @@
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
//import com.mongodb.Mongo;
//import com.mongodb.MongoClient;
//import com.mongodb.MongoClientOptions;
import com.mongodb.MongoCredential;
import com.mongodb.ServerAddress;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
@Configuration
@ConfigurationProperties
@EnableAutoConfiguration
Expand Down Expand Up @@ -76,7 +81,7 @@ public class MongoConfig {
@PostConstruct
public void initIt() throws Exception {

mongoClient = (MongoClient) this.mongo();
mongoClient = this.mongo();
log.info("#### Initialize MongoDB with dbname:"+this.dbname+"####");
this.setMongodb(this.dbname);
this.setRecordCollection(this.record);
Expand Down Expand Up @@ -164,9 +169,28 @@ public String getMDSecret() {
* @return
* @throws Exception
*/
public Mongo mongo() throws Exception {
servers.add(new ServerAddress(host, port));
return new MongoClient(servers, MongoCredential.createCredential(user, dbname, password.toCharArray()),
MongoClientOptions.builder().build());
public MongoClient mongo() throws Exception {
// servers.add(new ServerAddress(host, port));

// MongoCredential credential = MongoCredential.createCredential(user, dbname, password.toCharArray());
// ServerAddress serverAddress = new ServerAddress(host, port);
//
// // Mongo Client
// MongoClient mongoClient = new MongoClient(serverAddress,Arrays.asList(credential));
//
// return new MongoClient(servers, MongoCredential.createCredential(user, dbname, password.toCharArray()),
// MongoClientOptions.builder().build());
//
MongoCredential credential = MongoCredential.createCredential(user, dbname, password.toCharArray());

MongoClientSettings settings = MongoClientSettings.builder()
.credential(credential)
.applyToSslSettings(builder -> builder.enabled(false))
.applyToClusterSettings(builder ->
builder.hosts(Arrays.asList(new ServerAddress(host, port))))
.build();

MongoClient mongoClient = MongoClients.create(settings);
return mongoClient;
}
}
Loading

0 comments on commit 8964816

Please sign in to comment.