Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Commit

Permalink
implement catalog generation
Browse files Browse the repository at this point in the history
  • Loading branch information
amckenzie authored and mapingo committed Nov 20, 2017
1 parent 7278c18 commit 245b6e5
Show file tree
Hide file tree
Showing 49 changed files with 1,678 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

public class SchemaCatalogException extends RuntimeException {

public SchemaCatalogException(final String message) {
super(message);
}

public SchemaCatalogException(final String message, final Throwable cause) {
super(message, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,12 @@ public URL toUrl(final URI uri) {
throw new SchemaCatalogException(format("Failed to convert URI '%s' to URL", uri), e);
}
}

public URI toUri(final String uri) {
try {
return new URI(uri);
} catch (URISyntaxException e) {
throw new SchemaCatalogException(format("Failed to convert URI '%s' to URL", uri), e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void shouldLoadCatalogsFromTheClasspath() throws Exception {
assertThat(catalog.getGroup().size(), is(2));

assertThat(catalog.getGroup().get(0).getName(), is("standards"));
assertThat(catalog.getGroup().get(0).getBaseLocation(), is("/json/schema/standards"));
assertThat(catalog.getGroup().get(0).getBaseLocation(), is("standards/"));

assertThat(catalog.getGroup().get(0).getSchema().size(), is(2));
assertThat(catalog.getGroup().get(0).getSchema().get(0).getId(), is("http://justice.gov.uk/standards/complex_address.json"));
Expand All @@ -70,6 +70,6 @@ public void shouldLoadCatalogsFromTheClasspath() throws Exception {

assertThat(catalog.getGroup().get(1).getSchema().size(), is(1));
assertThat(catalog.getGroup().get(1).getSchema().get(0).getId(), is("http://justice.gov.uk/context/person.json"));
assertThat(catalog.getGroup().get(1).getSchema().get(0).getLocation(), is("/json/schema/context/person.json"));
assertThat(catalog.getGroup().get(1).getSchema().get(0).getLocation(), is("context/person.json"));
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package uk.gov.justice.schema.catalog.util;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;

import uk.gov.justice.schema.catalog.SchemaCatalogException;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.junit.Test;
Expand Down Expand Up @@ -35,4 +40,25 @@ public void shouldConvertAnUrlToAnUri() throws Exception {

assertThat(url.toString(), is("file://src/main/fred.txt"));
}

@Test
public void shouldConvertAUriStringToAUriObject() throws Exception {

final String uri = "file://src/main/fred.txt";

assertThat(urlConverter.toUri(uri).toString(), is(uri));
}

@Test
public void shouldFailIfConvertingAStringToAUriThrowsAURISyntaxException() throws Exception {
final String uri = "this is not a uri";

try {
urlConverter.toUri(uri);
fail();
} catch (final SchemaCatalogException expected) {
assertThat(expected.getCause(), is(instanceOf(URISyntaxException.class)));
assertThat(expected.getMessage(), is("Failed to convert URI 'this is not a uri' to URL"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"group": [
{
"name": "standards",
"baseLocation": "/json/schema/standards",
"baseLocation": "standards/",
"schema": [
{
"id": "http://justice.gov.uk/standards/complex_address.json",
Expand All @@ -21,7 +21,7 @@
"schema": [
{
"id": "http://justice.gov.uk/context/person.json",
"location": "/json/schema/context/person.json"
"location": "context/person.json"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Catalog {
private final List<Group> group;
private final String name;

public Catalog(final List<Group> group, final String name) {
public Catalog(final String name, final List<Group> group) {
this.group = group;
this.name = name;
}
Expand All @@ -20,4 +20,11 @@ public String getName() {
return name;
}

@Override
public String toString() {
return "Catalog{" +
"group=" + group +
", name='" + name + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

public class CatalogWrapper {

private Catalog catalog;
private final Catalog catalog;

public CatalogWrapper(final Catalog catalog) {
this.catalog = catalog;
}

public Catalog getCatalog() {
return catalog;
}

public void setCatalog(Catalog catalog) {
this.catalog = catalog;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,13 @@ public String getName() {
public List<Schema> getSchema() {
return schema;
}

@Override
public String toString() {
return "Group{" +
"baseLocation='" + baseLocation + '\'' +
", name='" + name + '\'' +
", schema=" + schema +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ public String getId() {
public String getLocation() {
return location;
}

@Override
public String toString() {
return "Schema{" +
"id='" + id + '\'' +
", location='" + location + '\'' +
'}';
}
}
62 changes: 62 additions & 0 deletions catalog-generation-plugin-it/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?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">
<parent>
<artifactId>json-schema-catalog</artifactId>
<groupId>uk.gov.justice.schema</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>catalog-generation-plugin-it</artifactId>

<build>
<plugins>
<plugin>
<artifactId>generator-plugin</artifactId>
<groupId>uk.gov.justice.maven.generator</groupId>
<version>${generator-maven-plugin.version}</version>
<executions>
<execution>
<id>internal-jsons</id>
<configuration>
<generatorName>
uk.gov.justice.schema.catalog.generation.MavenCatalogGenerator
</generatorName>
<parserName>
uk.gov.justice.schema.catalog.generation.io.parser.ListOfUriParser
</parserName>
<basePackageName>uk.gov.justice.events.pojo</basePackageName>
<sourceDirectory>${basedir}/src/raml/json/schema
</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources
</outputDirectory>
<includes>
<include>**/*.json</include>
</includes>
<excludes>
</excludes>
<generatorProperties
implementation="uk.gov.justice.schema.catalog.generation.maven.CatalogGeneratorProperties">
<catalogName>${project.artifactId}</catalogName>
</generatorProperties>
</configuration>
<goals>
<goal>generate</goal>
</goals>
<phase>generate-sources</phase>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>uk.gov.justice.schema</groupId>
<artifactId>catalog-generation</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://justice.gov.uk/context/person.json",
"type": "object",
"properties": {
"nino": {
"type": "string"
},
"name": {
"type": "string"
},
"correspondence_address":
{"$ref" : "http://justice.gov.uk/standards/complex_address.json#/definitions/complex_address2"}

},
"required": [
"nino",
"name",
"correspondence_address"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://justice.gov.uk/standards/address.json",
"type": "object",
"properties": {
"addressline1": {
"type": "string"
},
"addressline2": {
"type": "string"
},
"city": {
"type": "string"
},
"postcode": {
"type": "string"
}
},
"required": [
"addressline1",
"city",
"postcode"
]

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://justice.gov.uk/standards/complex_address.json",
"type": "object",
"definitions": {
"complex_address": {
"type": "object",
"properties": {
"addressline1": {
"type": "string"
},
"addressline2": {
"type": "string"
},
"city": {
"type": "string"
},
"postcode": {
"type": "string"
},
"country": {
"type": "string"
}
},
"required": [
"addressline1",
"city",
"postcode",
"country"
]
},
"complex_address2": {
"type": "object",
"properties": {
"addressline1": {
"type": "string"
},
"addressline2": {
"type": "string"
},
"city": {
"type": "string"
},
"postcode": {
"type": "string"
},
"ss": {
"type": "string"
}
},
"required": [
"addressline1",
"city",
"postcode",
"ss"
]
}
},
"allOf": [
{
"$ref": "#/definitions/complex_address"
}
]
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://justice.gov.uk/standards/defendant.json",
"type": "object",
"properties": {
"personalInfo": {
"type": "string"
},
"currentAddress": {
"type": "string"
},
"correspondenceAddress": {
"type": "string"
},
"courtCentreId": {
"type": "string"
}
},
"required": [
"personalInfo",
"currentAddress"
]
}
20 changes: 20 additions & 0 deletions catalog-generation/paths.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@


Schema file location:
file:/Users/dev/workspace/json-schema-catalog/catalog-generation/target/test-classes/raml/json/schema/context/person.json

Id (taken from the schema file):
http://justice.gov.uk/context/person.json

Location where catalog will be generated (on classpath):
raml/json/schema/schema_catalog.json

Group:
context

Base location:
context/

Location
person.json

Loading

0 comments on commit 245b6e5

Please sign in to comment.