/DATA4PTTools

Shared space for the development of the DATA4PT validation tool(s)

Primary LanguageGoMIT LicenseMIT

Greenlight - The Data4PT Validation tool

Go Version Docker pulls Docker stars

Web · CLI · Source · Configuration

Simple validation

The minimal, customizable, NeTEx validation tool

  • Customizable: configure what you see and how you see it.
  • Scripting write your own validation rules using javascript
  • Fancy shows relevant information at a glance.
  • Easy: quick to install – start using it in minutes.

Introduction

The tool consists of a number of components, each with a different responsibility. This will ensure that the tool is modular and that each component is easy to understand and maintain.

Components

Core - This is the main component of the tool, it reads the configuration, handles file imports, calls the validation scripts and summarizes the result. The Core provides an API that other components use to control the validation or to get access to shared functions, e.g, in libXML. The API also makes it possible to extend the tool with different front ends, as the CLI and Web Interface.

libXML - An open source, standard library integrated into the tool. It is libXML that does all the XSD and XML validation. It is called from the scripts via the API in the Core component.

CLI - The Command Line Interface is used in a terminal or integrated in an import/export pipeline. Parameters are used to configure the tool and to specify the files to be validated. The result can be read in the terminal or saved as a file.

Web Interface - Provides an easy to use interface via the web browser. The web interface makes the tool easer to use for the occasional user or for just testing small files. After loading the web page you can select the NeTEx profile to use, select one or more validation rules and then run the validation. After completion you get the result on the web page but can also download it to a file.

Scripts - Individual validation rules implemented as scripts. The scripts are written in JavaScript that is easy to start with and JavaScript is also well documented. The validation scripts are small programs that each implements one or more validation rules. The scrips provided with the tool implements one rule per script to make it easy to follow and understand how they work. To gain a better performance several rules can be implemented in the same script. Each script uses the API in Core to load the files to validate and to call functions in libXML. XPath provided via libXML is used by most of the scripts to search for and compare different elements in the NeTEx-files.

Getting started

To use the tool you need to install Docker on the computer that you will use. You can use Windows, Mac or Linux as your base operating system, and you will find Docker and instructions on how to install in the Docker Getting Started guide.

After you have installed Docker you can get the latest image by typing the following command in a terminal window:

docker pull lekojson/greenlight

Then you can then start the container with the command:

docker run -it -p 8080:8080 lekojson/greenlight server

You can also start the container via Docker Desktop, find the downloaded image and click on start:

Docker Desktop

Web interface

When the container is running you can use the web interface by opening a web browser and type the address http://localhost:8080/, and then click on Begin validating to start a new validation session.

Web Start page

Configuration

First you select which schema/profile to use in the validation. In the current version three default schemas are available; NeTEx Standard, NeTEx Light and EPIP. In a future version of the tool it will be possible to upload your own local schema.

Web Select schema

The next step is to select which additional rules you want to check. You first get an overview and brief description of each rule. Zero or more rules can be selected by clicking the rules in the list box.

Web Select rules

The last step is to upload the files to be validated, it can be single files or multiple files compressed in an archive. Click Upload files to select which files to upload and then wait until all files has been uploaded, see the Status indicator in the files list.

Web Start upload

When all files are uploaded you start the validation by clicking on Validate.

Web Uploaded files

The validation will start by validating each file against the selected schema and rules. Depending on the number of files and their sizes the validation can take some time to complete. When the validation is done the result for each file is displayed. You can also download the result in json or csv format to a local file to process it further.

Web Validation result

🖥️ CLI

Prerequisites

  • Docker installed and ready to go

Getting started

Note: if you don't have NeTEx xml document (or two) ready to test with we provide a few demo files in the source and docker image

  1. Getting the latest image
docker pull lekojson/greenlight
  1. Running a validation

    • With demo files provided in the image

    docker run -it lekojson/greenlight validate -i testdata
    • Providing your own files

    docker run -it -v /path/to/documents:/documents lekojson/greenlight validate -i /documents

🛠️ Building from source

Prerequisites

Getting started

Note: Greenlight is using Go and is powered by libxml2, so make sure those are installed and configured

  1. Clone repository
git clone https://github.com/ITxPT/DATA4PTTools
  1. Navigate to project
cd DATA4PTTools
  1. Downloading dependencies
go get

4.a CLI

  1. Building and running a validation

    • Validate with demo files provided in the source

    changes in path definition will differ running on windows

    go run cmd/*.go validate -i testdata
    • Validate using your own files

    changes in path definition will differ running on windows

    go run cmd/*.go validate -i /path/to/documents

4.b Web GUI

  1. Buliding and running the backend server
  • Build and start the server

go run cmd/*.go server
  1. Building and running the frontend application
  • Navigate to directory

cd app
  • Install dependencies

npm i
  • Start the server

npm run dev
  1. Open a browser and navigate to http://localhost:3000

⚙️ Configuration

Configurations can be made in a three different ways (in order of priority), through command line arguments, environment variables and configuration file

Command line

  • All arguments can be found by running
docker run -it lekojson/greenlight --help

or by command

docker run -it lekojson/greenlight [command] --help
  • Example changing the output from pretty to json in validation
docker run -it lekojson/greenlight validate -i testdata -o json

Environment variables

Environment comes with the prefix GREENLIGHT_ and match the paths (separated by _) in configuration file (see below). Three different datatypes are supported, string, boolean and string slice which also match the configuration file.

  • Setting input through environment variable
docker run -it -e GREENLIGHT_INPUT=/path/to/documents lekojson/greenlight validate

data4pt logo

itxpt logo