An open API service indexing awesome lists of open source software.

https://github.com/statisticsnorway/klass

A Spring Boot application that handles classifications for SSB. Klass provides a REST api that clients can use to read classifications, and a Vaadin frontend for maintaining classifications.
https://github.com/statisticsnorway/klass

backstage classification codelist gsim statistics

Last synced: 3 months ago
JSON representation

A Spring Boot application that handles classifications for SSB. Klass provides a REST api that clients can use to read classifications, and a Vaadin frontend for maintaining classifications.

Awesome Lists containing this project

README

          

# Klass

Klass is Statistics Norway's system for classifications and code lists. The data model is based on the structure and principles described by [GSIM](https://statswiki.unece.org/spaces/gsim/pages/97356506/1_Introduction).

The information in Klass is exposed through a REST API, available to all, free of charge under the [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/deed.no) license. The API documentation is available in multiple flavours:

- API Guide:
- Swagger UI:
- OpenAPI spec:

## Overview

Klass consists of 4 maven modules

- Klass API (Standalone application that provides the Klass API)
- Klass Forvaltning (Internal tool for maintenance of classifications)
- Klass Shared (Classes shared between API and Forvaltning. primary database and search components)
- Klass Solr (Solr Core configuration and configuration for embedded solr for test/development)
- Klass Index Job (Responsible for periodically updating the OpenSearch index)

## Build

Run `mvn install` to build the project.

## Deploy

Klass is hosted on the Nais application platform. Deploy configuration may be found in the [.nais](.nais) directory. Deploy workflows may be found in the [.github/workflows](.github/workflows) directory.

## Database

Klass uses PostgreSQL for its database.

Tests are run with the Zonky Postgres embedded database so that they use the PostgreSQL dialect and guarantee consistency with deployed environments.

Klass is configured to use Flyway for database initialization and migration.
You can find the collection of SQL scripts in the Klass-shared module under `src/main/resources/db/migration`

## Development

### Requirements

- Maven:
- Sdkman:
- Java 17: `sdk install java 17.0.15-tem`
- Java 8 (for Klass Forvaltning): `sdk install java 8.0.452-tem`

### Code Quality configuration

We follow a multi-layered approach based on the "shift-left" philosophy where problems are addressed as early as possible, ideally while writing the code in the IDE. Checks are performed at three stages:

- In the IDE through extensions
- In CI/CD as a hard check on PRs

Developers are encouraged to install the IDE plugins/extensions to avoid pain at the PR stage.

#### Plugins/extensions

##### IntelliJ

- https://plugins.jetbrains.com/plugin/7973-sonarqube-for-ide
- https://plugins.jetbrains.com/plugin/8527-google-java-format

#### Lint

We use Sonarqube for linting. This runs a range of checks on code quality. It runs in CI/CD and it's a good idea to install the extension in your IDE to get feedback as you code.

#### Formatting

We use google-java-format for code formatting. This avoids unproductive discussions about minutiae of bracket placement etc. Make sure the plugin is installed in your IDE (see [above](#pluginsextensions)).

It's worth running `mvn fmt:format` before opening a PR to avoid any chance of a CI check complaining at you.

### Configuration

#### GitHub Packages

In order to download dependencies from GitHub Packages we must authenticate Maven. See the documentation here:

This may be done by generating a Personal Access Token (classic) on GitHub with the `write:packages` scope. Remember to configure SSO. The following configuration may then be placed in your `~/.m2/settings.xml` file.

```xml


github
USERNAME
TOKEN

```

#### Docker

##### Colima on Mac

Colima should have at least 5G memory and the project folder must be mounted. Change this in `~/.colima/default/colima.yaml` e.g.

```yaml
memory: 5
...
mounts:
- location: /Users/perolsen/Repository/github/klass
writable: false
```

### Introduction

It's recommended to build with maven before starting development as some classes are generated as part of the build process.

Each app has an `.sdkmanrc` file which may be used to configure the Java version to use. This may be activated by entering the directory and running the `sdk env` command. A `Makefile` is also provided with relevant commands for building each app. See for more details

### Klass API

#### Build

Build the app: `make build-klass-api`

#### Docker compose

The apps can be run in multiple different configurations with Docker Compose. See [klass-shared/docker-compose.yaml](klass-shared/docker-compose.yaml) for details.

There are tasks available in the Makefile as well.

### Klass Forvaltning

#### Build

`make build-klass-forvaltning`

#### Run

`make run-klass-forvaltning-local`

Visit

### Spring profiles

Klass API and Klass Forvaltning utilize Spring boot and heavily rely on Spring Profiles to make development and debugging easier.
below is a quick summary of the profiles available (see _application.properties_ for more details)

```
# Application profiles:
#----------------------
# Profiles for production
# production = no test beans and only Active Directory login
#
# Profiles for development
# ad-offline = will only use test/embeded AD (apacheDS) [Forvaltning only]
# small-import = imports a small number of classifications from legacy system, useful during development
# mock-mailserver = outgoing emails are only logged
```

### Build profiles

The profile named `documentation` will generate API documentation with AsciiDoc (default: enabled)

### Run / Debug

You can start an application using maven with the following command

```shell
mvn spring-boot:run
```

Start the forvaltning app with

```shell
make run-klass-forvaltning-local
```

Or from your IDE using the `KlassApiApplication` / `KlassForvaltningApplication` classes.
IntelliJ is recommended, it makes it very easy to start spring boot applications and will make sure your run/debug configuration has all the necessary dependencies (will include maven dependencies with provided scope).

Frontend may be accessed at:

REST api documentation may be accessed at

[![IntelliJ](docs/troubleshoot_workdir_small.png)](./docs/troubleshoot_workdir.png)