Skip to content

Commit

Permalink
#1 initial migration from NIEHS
Browse files Browse the repository at this point in the history
  • Loading branch information
deep.patel committed Dec 17, 2019
1 parent b792d82 commit 453fbb1
Show file tree
Hide file tree
Showing 33 changed files with 2,516 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
**/.classpath
.DS_Store
**/nb-configuration.xml
**/.springBeans
**/testing.properties
**/*.eml
**/Scripts
.idea
*.iml
.project
.idea
.metadata
.DS_Store
Servers
.settings
.classpath
mvn-repo
bin
*.war
*.log
*/nbactions.xml
*.eml
nbactions.xml
testing.properties
*/test-output
JargonVersion.java
**/${test.option.mount.basedir}
**/*.*~
*.*~
.dbeaver*
test.*.properties
**/target
target
86 changes: 85 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,86 @@
# notification-service
# Notification Service(WIP)
A pluggable Spring Boot RESTful web service to enable Notification system in Metalnx.

## Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project.
Refer: [OpenAPI-Spec](https://github.com/swagger-api/swagger-core)

The underlying library integrating swagger to SpringBoot is [springfox](https://github.com/springfox/springfox)

Start your server as an simple java application

You can view the api documentation in swagger-ui by pointing to
http://localhost:8888/swagger-ui.html

Change default port value in application.properties


## Database schema migration and setup
Database schema should be configured using [flywaydb](https://flywaydb.org/). This project includes code that supports database migrations across versions.

Reference [docs](https://flywaydb.org/documentation/)

We'll use the Maven plugin in our own processes and documentation, but there are other options as well.

>**N.B.:**
User and password information needs to be kept secure. There are maven plugin configuration [options](https://flywaydb.org/documentation/maven/).

1. Set up the database (we will use postgres in the spirit of the iRODS install)
```bash
$ (sudo) su - postgres
postgres$ psql
psql> CREATE USER irodsext WITH PASSWORD 'password';
psql> CREATE DATABASE "notification";
psql> GRANT ALL PRIVILEGES ON DATABASE "notifications" TO irodsext;
psql> ALTER USER irodsext WITH SUPERUSER;
psql>Alter user irodsext with SUPERUSER;
```

> need to add superuser role to use uuid-ossp
1. Setting up Maven profile
```bash
vi ~/.m2/settings.xml
```
```xml
<profile>
<id>flyway-local</id>
<properties>
<flyway.jdbc.url>jdbc:postgresql://<address>:<port>/<metalnx-db-name></flyway.jdbc.url>
<flyway.db.user>irodsext</flyway.db.user>
<flyway.db.password>password</flyway.db.password>
<flyway.db.schema>public</flyway.db.schema>
</properties>
</profile>
```
1. Clean database (**Warning** destructive! clears your database)
```bash
mvn flyway:clean
```
1. Migration, this is the first command to run from 0 on a clean database
```bash
mvn flyway:migrate
```

For future migration use benchmark
```bash
mvn flyway:benchmark
```
> Looks at existing database to set to initial version. This is not for new databases.
## Initial database table: "notification"

|attribute_name|datatype|comment|
|---|---|---|
| id(PK) | BIGINT | auto generated sequence |
| notification_id | uuid | using uuid-ossp module functions to generate universally unique identifiers (UUIDs) |
| sender_id | VARCHAR | notification sender's userId extracted from JWT |
| recipient_id | VARCHAR | notification recipient's userId |
| subject | TEXT | notification subject |
| message | TEXT | notification message |
| seen | BOOLEAN | boolean for user's seen/unseen notification status |
| deleted | BOOLEAN | boolean for deleted notification, notification will not be deleted from postgres db |
| date_created | TIMESTAMP | timestamp auto-generated by postgres db |
| severity_level | INTEGER | severity level of notification an integer value between 1 and 5 |
| notification_type | VARCHAR | type of notification options are workflow, permission, system |
| data_location_url | TEXT | notification associated logical location of data |
135 changes: 135 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>gov.nih.niehs.notification</groupId>
<artifactId>notification-service</artifactId>
<packaging>jar</packaging>
<name>Notification Service</name>
<version>1.0.0</version>
<properties>
<java.version>1.7</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.9.2</springfox-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.22.RELEASE</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>4.2.0</version>
<configuration>
<url>${flyway.jdbc.url}</url>
<user>${flyway.db.user}</user>
<password>${flyway.db.password}</password>
<schemas>
<schema>${flyway.db.schema}</schema>
</schemas>
<locations>
<location>classpath:migrations</location>
</locations>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>

<!-- postgresql dependencies -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>

<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>

<dependency>
<groupId>com.github.joschi.jackson</groupId>
<artifactId>jackson-datatype-threetenbp</artifactId>
<version>2.6.4</version>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
22 changes: 22 additions & 0 deletions src/main/java/gov/nih/niehs/notification/RFC3339DateFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gov.nih.niehs.notification;

import com.fasterxml.jackson.databind.util.ISO8601DateFormat;
import com.fasterxml.jackson.databind.util.ISO8601Utils;

import java.text.FieldPosition;
import java.util.Date;


public class RFC3339DateFormat extends ISO8601DateFormat {

private static final long serialVersionUID = 1L;

// Same as ISO8601DateFormat but serializing milliseconds.
@Override
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
String value = ISO8601Utils.format(date, true);
toAppendTo.append(value);
return toAppendTo;
}

}
36 changes: 36 additions & 0 deletions src/main/java/gov/nih/niehs/notification/Swagger2SpringBoot.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gov.nih.niehs.notification;

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

import springfox.documentation.swagger2.annotations.EnableSwagger2;

@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = { "gov.nih.niehs.notification", "gov.nih.niehs.notification.api" , "gov.nih.niehs.notification.configuration"})
public class Swagger2SpringBoot implements CommandLineRunner {

@Override
public void run(String... arg0) throws Exception {
if (arg0.length > 0 && arg0[0].equals("exitcode")) {
throw new ExitException();
}
}

public static void main(String[] args) throws Exception {
new SpringApplication(Swagger2SpringBoot.class).run(args);
}

class ExitException extends RuntimeException implements ExitCodeGenerator {
private static final long serialVersionUID = 1L;

@Override
public int getExitCode() {
return 10;
}

}
}
11 changes: 11 additions & 0 deletions src/main/java/gov/nih/niehs/notification/api/ApiException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package gov.nih.niehs.notification.api;


public class ApiException extends Exception {
private int code;

public ApiException(int code, String msg) {
super(msg);
this.code = code;
}
}
26 changes: 26 additions & 0 deletions src/main/java/gov/nih/niehs/notification/api/ApiOriginFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package gov.nih.niehs.notification.api;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;

public class ApiOriginFilter implements javax.servlet.Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("Access-Control-Allow-Origin", "*");
res.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
res.addHeader("Access-Control-Allow-Headers", "Content-Type");
chain.doFilter(request, response);
}

@Override
public void destroy() {
}

@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
}
Loading

0 comments on commit 453fbb1

Please sign in to comment.