Skip to content

Commit

Permalink
Open sourcing
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Laurin committed Mar 27, 2018
0 parents commit a3cb736
Show file tree
Hide file tree
Showing 479 changed files with 35,089 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{md,markdown}]
trim_trailing_whitespace = false

[*.{js,ts,json,yml,html}]
indent_style = space
indent_size = 2

[*.java]
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab

[Jenkinsfile*]
indent_style = space
indent_size = 4
39 changes: 39 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Contribution guidelines

We're happy to accept 3rd-party contributions. Please make sure you read this document before you do any work though,
as we have some expectations related to the content and quality of change sets.

## What you should know about this application

This project is part of a flexible case management system for HMCTS' services.

## Before contributing

Any ideas on the user journeys and general service experience you may have **should be first consulted
with us by submitting a new issue** to this repository. Ideas are always welcome, but if something is divergent or unrelated
to what we're trying to achieve we won't be able to accept it. Please keep this in mind as we don't want to waste anybody's time.

In the interest of creating a friendly collaboration environment, please read and adhere to an open source contributor's
[code of conduct](http://contributor-covenant.org/version/1/4/).

## Making a contribution

After your idea has been accepted you can implement it. We don't allow direct changes to the codebase from the public,
they have to go through a review first.

Here's what you should do:
1. [fork](https://help.github.com/articles/fork-a-repo/) this repository and clone it to your machine,
2. create a new branch for your change:
* use the latest *master* to branch from,
3. implement the change in your branch:
* if the change is non-trivial it's a good practice to split it into several logically independent units and deliver
each one as a separate commit,
* make sure the commit messages use proper language and accurately describe commit's content, e.g. *"Unify postcode lookup elements spacing"*.
More information on good commit messages can be found [here](http://chris.beams.io/posts/git-commit/),
4. test if your feature works as expected and does not break any existing features, this may include implementing additional automated tests or amending existing ones,
5. push the change to your GitHub fork,
6. submit a [pull request](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) to our repository:
* ensure that the pull request and related GitHub issue reference each other.

At this point the pull request will wait for someone from our team to review. It may be accepted straight away,
or we may ask you to make some additional amendments before incorporating it into the main branch.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### What would you like to change?

### How do you think that would improve the project?

### If this entry is related to a bug, please provide the steps to reproduce it
23 changes: 23 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Before creating a pull request make sure that:**

- [ ] commit messages are meaningful and follow good commit message guidelines
- [ ] README and other documentation has been updated / added (if needed)
- [ ] tests have been updated / new tests has been added (if needed)

Please remove this line and everything above and fill the following sections:


### JIRA link (if applicable) ###



### Change description ###



**Does this PR introduce a breaking change?** (check one with "x")

```
[ ] Yes
[ ] No
```
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
.classpath
.project
.settings/
target/

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# ide generated files
*.sublime-project
*.sublime-workspace

# IntelliJ IDEA files
.idea/
*.iml
/core-case-data/case-definition-api/target
/core-case-data/case-definition-api-client/target

.DS_Store

application/src/test/resources/test-local-override.properties

.gradle/
build/
**/out/
**/build/
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM openjdk:8-jre

COPY application/build/libs/case-definition-store-api-*.jar /app.jar

HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD http_proxy="" curl --silent --fail http://localhost:4451/status/health

EXPOSE 4451

CMD java ${JAVA_OPTS} -Dspring.config.location=/application.properties -Djava.security.egd=file:/dev/./urandom -jar /app.jar
94 changes: 94 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!groovy
@Library("Reform")
import uk.gov.hmcts.Ansible
import uk.gov.hmcts.Packager
import uk.gov.hmcts.RPMTagger

packager = new Packager(this, 'ccdata');
ansible = new Ansible(this, 'ccdata');
server = Artifactory.server 'artifactory.reform'
buildInfo = Artifactory.newBuildInfo()

properties(
[[$class: 'GithubProjectProperty', displayName: 'Case Definition Store API', projectUrlStr: 'https://github.com/hmcts/ccd-definition-store-api'],
pipelineTriggers([[$class: 'GitHubPushTrigger']]),
[$class: 'BuildDiscarderProperty', strategy: [$class: 'LogRotator', artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '7', numToKeepStr: '10']]
]
)

milestone()
lock(resource: "case-definition-store-app-${env.BRANCH_NAME}", inversePrecedence: true) {
node {
try {
timeout(time: 35, unit: 'MINUTES') {

stage('Checkout') {
deleteDir()
checkout scm
}

stage('Build') {
sh "./gradlew clean build sonar -Dsonar.host.url=https://sonar.reform.hmcts.net/ " +
" -Dsonar.projectName=\"CCD :: Case Definition Store API\" "}

onMaster {
publishAndDeploy('master', 'test')
}

onDevelop {
publishAndDeploy('develop', 'dev')
}

milestone()
}
} catch (err) {
notifyBuildFailure channel: '#ccd-notifications'
throw err
} finally {
junit '**/build/test-results/**/*.xml'
}
}
}

def publishAndDeploy(branch, env) {
def rpmVersion
def version
// Temporary port offset avoiding collision till Dev and Test environments are fully separated by DevOps
def backendPort = (env == 'test') ? '4481' : '4451'

stage('Publish JAR') {
server.publishBuildInfo buildInfo
}

stage('Publish RPM') {
rpmVersion = packager.javaRPM(branch,
'definition-store-application',
'application/build/libs/case-definition-store-api-$(./gradlew -q projectVersion).jar',
'springboot',
'application/src/main/resources/application.properties')
packager.publishJavaRPM('definition-store-application')
}

stage('Package (Docker)') {
definitionStoreVersion = dockerImage imageName: 'ccd/ccd-definition-store-api', tags: [branch]
definitionStoreDatabaseVersion = dockerImage imageName: 'ccd/ccd-definition-store-database', context: 'docker/database', tags: [branch]
}

def rpmTagger = new RPMTagger(
this,
'definition-store-application',
packager.rpmName('definition-store-application', rpmVersion),
'ccdata-local'
)

stage('Deploy: ' + env) {
version = "{ccd_definition_api_version: ${rpmVersion}}"
ansible.runDeployPlaybook(version, env, branch)
rpmTagger.tagDeploymentSuccessfulOn(env)
}

stage('Smoke Tests: ' + env) {
sh "curl -vf https://case-definition-app." + env + ".ccd.reform.hmcts.net:" + backendPort + "/status/health"
rpmTagger.tagTestingPassedOn(env)
}
}
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 HMCTS (HM Courts & Tribunals Service)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
104 changes: 104 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Case definition store

Validation and persistence of definitions for field types, jurisdictions, case types and associated display elements.

## Overview

Definitions are imported as an Excel spreadsheet which are parsed, persisted and then exposed as JSON through a REST API.

Spring Boot and Spring Data are used to persist the data in a PostgreSQL database. The database schema is created and maintained by Liquibase changesets applied during application startup.

## Getting started

### Prerequisites

- [JDK 8](https://www.oracle.com/java)
- [Docker](https://www.docker.com)

#### Environment variables

The following environment variables are required:

| Name | Default | Description |
|------|---------|-------------|
| DEFINITION_STORE_DB_USERNAME | - | Username for database |
| DEFINITION_STORE_DB_PASSWORD | - | Password for database |
| DEFINITION_STORE_IDAM_KEY | - | Definition store's IDAM S2S micro-service secret key. This must match the IDAM instance it's being run against. |
| DEFINITION_STORE_S2S_AUTHORISED_SERVICES | ccd_data,ccd_gw | Authorised micro-service names for S2S calls |
| IDAM_USER_URL | - | Base URL for IdAM's User API service (idam-app). `http://localhost:4501` for the dockerised local instance or tunneled `dev` instance. |
| IDAM_S2S_URL | - | Base URL for IdAM's S2S API service (service-auth-provider). `http://localhost:4502` for the dockerised local instance or tunneled `dev` instance. |
| USER_PROFILE_HOST | - | Base URL for the User Profile service. `http://localhost:4453` for the dockerised local instance. |

### Building

The project uses [Maven](https://maven.apache.org/).

To build project please execute the following command:

```bash
mvn install
```

### Running

If you want your code to become available to other Docker projects (e.g. for local environment testing), you need to build the image:

```bash
docker-compose build
```

The above will build both the application and database images.
If you want to build only one of them just specify the name assigned in docker compose file, e.g.:

```bash
docker-compose build ccd-definition-store-api
```

When the project has been packaged in `target/` directory,
you can run it by executing following command:

```bash
docker-compose up
```

As a result the following containers will get created and started:

- Database exposing port `5451`
- API exposing ports `4451`

#### Handling database

Database will get initiated when you run `docker-compose up` for the first time by execute all scripts from `database` directory.

You don't need to migrate database manually since migrations are executed every time `docker-compose up` is executed.

You can connect to the database at `http://localhost:5451` with the username and password set in the environment variables.

## Modules

The application is structured as a Maven multi-module project. The modules are:

### repository

Data access layer.

### domain

Domain logic.

### rest-api

Secured RESTful API giving access to part of the domain logic.

### excel-importer

Secured endpoint and specific logic for importing case definition as an Excel spreadsheet.

### application

Spring application entry point and configuration.

## LICENSE

This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.

38 changes: 38 additions & 0 deletions aat/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
dependencies {
compile "org.hibernate:hibernate-core:${hibernateVersion}"
compile "org.hibernate:hibernate-entitymanager:${hibernateVersion}"
compile "uk.gov.hmcts.reform.auth:auth-checker-lib:${authCheckerVersion}"
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.7.7'
testCompile 'io.github.openfeign:feign-jackson:9.5.1'
testCompile "org.exparity:hamcrest-date:2.0.4"
testCompile "io.rest-assured:rest-assured:3.0.6"
testCompile "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
compile "uk.gov.hmcts.auth.totp:totp:1.0.1"
compile "uk.gov.hmcts.auth.provider.service:service-token-generator:1.0.5"
}

sourceSets {
aat {
java {
srcDir('${rootDir}/src/aat/java')
compileClasspath += main.output
runtimeClasspath += main.output
}
resources {
srcDir('src/aat/resources')
}
}
}

task functional(type: Test) {
group = 'Delivery pipeline'
description = 'Executes functional tests against an AAT CCD Definition Store Instance'
setTestClassesDirs(sourceSets.aat.output.classesDirs)
setClasspath(sourceSets.aat.runtimeClasspath)
include "uk/gov/hmcts/ccd/definitionstore/tests/functional/**"
useJUnitPlatform()
}




Loading

0 comments on commit a3cb736

Please sign in to comment.