This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8837a9d
commit 8a23f28
Showing
34 changed files
with
1,131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?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>generator-maven-plugin</artifactId> | ||
<groupId>uk.gov.justice.maven.generator</groupId> | ||
<version>2.5.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>uk.gov.justice.maven.generator</groupId> | ||
<artifactId>subscription-descriptor-parser</artifactId> | ||
<version>2.5.0-SNAPSHOT</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax</groupId> | ||
<artifactId>javaee-api</artifactId> | ||
<version>7.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>uk.gov.justice.maven.generator</groupId> | ||
<artifactId>parser-common</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.dataformat</groupId> | ||
<artifactId>jackson-dataformat-yaml</artifactId> | ||
<version>${jackson-dataformat-yaml.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.datatype</groupId> | ||
<artifactId>jackson-datatype-jdk8</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.module</groupId> | ||
<artifactId>jackson-module-parameter-names</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.everit-org.json-schema</groupId> | ||
<artifactId>org.everit.json.schema</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jglue.cdi-unit</groupId> | ||
<artifactId>cdi-unit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
20 changes: 20 additions & 0 deletions
20
...iption-descriptor-parser/src/main/java/uk/gov/justice/domain/eventsource/EventSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package uk.gov.justice.domain.eventsource; | ||
|
||
public class EventSource { | ||
|
||
private final String name; | ||
private final Location location; | ||
|
||
public EventSource(final String name, final Location location) { | ||
this.name = name; | ||
this.location = location; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Location getLocation() { | ||
return location; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ption-descriptor-parser/src/main/java/uk/gov/justice/domain/eventsource/EventSources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package uk.gov.justice.domain.eventsource; | ||
|
||
import java.util.List; | ||
|
||
public class EventSources { | ||
|
||
@SuppressWarnings("squid:S1700") | ||
private final List<EventSource> eventSources; | ||
|
||
public EventSources(final List<EventSource> eventSources) { | ||
this.eventSources = eventSources; | ||
} | ||
|
||
public List<EventSource> getEventSources() { | ||
return eventSources; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
subscription-descriptor-parser/src/main/java/uk/gov/justice/domain/eventsource/Location.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uk.gov.justice.domain.eventsource; | ||
|
||
public class Location { | ||
private final String jmsUri; | ||
private final String restUri; | ||
private final String dataSource; | ||
|
||
public Location(final String jmsUri, final String restUri, | ||
final String dataSource) { | ||
this.jmsUri = jmsUri; | ||
this.restUri = restUri; | ||
this.dataSource = dataSource; | ||
} | ||
|
||
public String getJmsUri() { | ||
return jmsUri; | ||
} | ||
|
||
public String getRestUri() { | ||
return restUri; | ||
} | ||
|
||
public String getDataSource() { | ||
return dataSource; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...n-descriptor-parser/src/main/java/uk/gov/justice/domain/subscriptiondescriptor/Event.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package uk.gov.justice.domain.subscriptiondescriptor; | ||
|
||
public class Event { | ||
|
||
private final String name; | ||
private final String schemaUri; | ||
|
||
public Event(final String name, final String schemaUri) { | ||
this.name = name; | ||
this.schemaUri = schemaUri; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getSchemaUri() { | ||
return schemaUri; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...iptor-parser/src/main/java/uk/gov/justice/domain/subscriptiondescriptor/Subscription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package uk.gov.justice.domain.subscriptiondescriptor; | ||
|
||
import java.util.List; | ||
|
||
public class Subscription { | ||
|
||
private final String name; | ||
private final List<Event> events; | ||
private final String eventSourceName; | ||
|
||
public Subscription(final String name, | ||
final List<Event> events, | ||
final String eventSourceName) { | ||
this.name = name; | ||
this.events = events; | ||
this.eventSourceName = eventSourceName; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public List<Event> getEvents() { | ||
return events; | ||
} | ||
|
||
public String getEventSourceName() { | ||
return eventSourceName; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...er/src/main/java/uk/gov/justice/domain/subscriptiondescriptor/SubscriptionDescriptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package uk.gov.justice.domain.subscriptiondescriptor; | ||
|
||
import java.util.List; | ||
|
||
public class SubscriptionDescriptor { | ||
|
||
private final String specVersion; | ||
private final String service; | ||
private final String serviceComponent; | ||
private final List<Subscription> subscriptions; | ||
|
||
public SubscriptionDescriptor(final String specVersion, final String service, final String serviceComponent, final List<Subscription> subscriptions) { | ||
this.specVersion = specVersion; | ||
this.service = service; | ||
this.serviceComponent = serviceComponent; | ||
this.subscriptions = subscriptions; | ||
} | ||
|
||
public String getSpecVersion() { | ||
return specVersion; | ||
} | ||
|
||
public String getService() { | ||
return service; | ||
} | ||
|
||
public String getServiceComponent() { | ||
return serviceComponent; | ||
} | ||
|
||
public List<Subscription> getSubscriptions() { | ||
return subscriptions; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...src/main/java/uk/gov/justice/domain/subscriptiondescriptor/SubscriptionDescriptorDef.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package uk.gov.justice.domain.subscriptiondescriptor; | ||
|
||
public class SubscriptionDescriptorDef { | ||
|
||
private final SubscriptionDescriptor subscriptionDescriptor; | ||
|
||
public SubscriptionDescriptorDef(final SubscriptionDescriptor subscriptionDescriptor) { | ||
this.subscriptionDescriptor = subscriptionDescriptor; | ||
} | ||
|
||
public SubscriptionDescriptor getSubscriptionDescriptor() { | ||
return subscriptionDescriptor; | ||
} | ||
} | ||
|
31 changes: 31 additions & 0 deletions
31
...in/java/uk/gov/justice/maven/generator/io/files/parser/YamlFileToJsonObjectConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package uk.gov.justice.maven.generator.io.files.parser; | ||
|
||
import static java.nio.file.Files.readAllLines; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import org.json.JSONObject; | ||
|
||
public class YamlFileToJsonObjectConverter { | ||
|
||
final String lineSeparator = System.getProperty("line.separator"); | ||
|
||
public JSONObject convert(final Path filePath) throws IOException { | ||
|
||
final String yamlStr = readAllLines(filePath) | ||
.stream() | ||
.collect(joining(lineSeparator)); | ||
|
||
final Object yamlObject = new ObjectMapper(new YAMLFactory()) | ||
.readValue(yamlStr, Object.class); | ||
|
||
final ObjectMapper jsonWriter = new ObjectMapper(); | ||
|
||
final String source = jsonWriter.writeValueAsString(yamlObject); | ||
return new JSONObject(source); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...arser/src/main/java/uk/gov/justice/maven/generator/io/files/parser/YamlFileValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package uk.gov.justice.maven.generator.io.files.parser; | ||
|
||
import static java.lang.String.format; | ||
|
||
import uk.gov.justice.maven.generator.io.files.parser.subscriptiondescriptor.SubscriptionDescriptorException; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Path; | ||
|
||
import org.everit.json.schema.Schema; | ||
import org.everit.json.schema.loader.SchemaLoader; | ||
import org.json.JSONObject; | ||
import org.json.JSONTokener; | ||
|
||
public abstract class YamlFileValidator { | ||
|
||
protected final YamlFileToJsonObjectConverter yamlFileToJsonObjectConverter; | ||
|
||
private final Path yamlSchemaFileName; | ||
|
||
public YamlFileValidator( | ||
final Path yamlSchemaFileName, | ||
final YamlFileToJsonObjectConverter yamlFileToJsonObjectConverter) { | ||
this.yamlFileToJsonObjectConverter = yamlFileToJsonObjectConverter; | ||
this.yamlSchemaFileName = yamlSchemaFileName; | ||
} | ||
|
||
public abstract void validate(final Path path); | ||
|
||
|
||
protected Schema schema() { | ||
try (final InputStream schemaFileStream = this.getClass().getResourceAsStream(yamlSchemaFileName.toString())) { | ||
return SchemaLoader.builder() | ||
.schemaJson(new JSONObject(new JSONTokener(schemaFileStream))) | ||
.build().load().build(); | ||
} catch (final IOException ex) { | ||
throw new SubscriptionDescriptorException(format("Unable to load JSON schema %s from classpath", yamlSchemaFileName), ex); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...justice/maven/generator/io/files/parser/eventsource/EventSourceFileYamlFileValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package uk.gov.justice.maven.generator.io.files.parser.eventsource; | ||
|
||
import static java.lang.String.format; | ||
|
||
import uk.gov.justice.maven.generator.io.files.parser.YamlFileToJsonObjectConverter; | ||
import uk.gov.justice.maven.generator.io.files.parser.YamlFileValidator; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
import org.json.JSONObject; | ||
|
||
public class EventSourceFileYamlFileValidator extends YamlFileValidator { | ||
|
||
public EventSourceFileYamlFileValidator(final Path schemaFile, final YamlFileToJsonObjectConverter yamlFileToJsonObjectConverter) { | ||
super(schemaFile, yamlFileToJsonObjectConverter); | ||
} | ||
|
||
@Override | ||
public void validate(final Path filePath) { | ||
try { | ||
final JSONObject convert = yamlFileToJsonObjectConverter.convert(filePath); | ||
schema().validate(convert); | ||
} catch (IOException ex) { | ||
throw new EventSourcesException(format("Unable to convert to JSON file %s ", filePath.toString()), ex); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ava/uk/gov/justice/maven/generator/io/files/parser/eventsource/EventSourcesException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package uk.gov.justice.maven.generator.io.files.parser.eventsource; | ||
|
||
public class EventSourcesException extends RuntimeException { | ||
public EventSourcesException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
Oops, something went wrong.