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

Commit

Permalink
add event sources yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedFarouk-HMCTS committed Apr 9, 2018
1 parent 8837a9d commit 8a23f28
Show file tree
Hide file tree
Showing 34 changed files with 1,131 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bower_components/
pom.xml~
.gitignore~
activemq-data/
*.puml

### SublimeText ###
# cache files for sublime text
Expand Down
4 changes: 3 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
<module>generator-maven-test-utils</module>
<module>schema-parser</module>
<module>parser-common</module>
<module>subscription-descriptor-parser</module>
</modules>

<properties>
<common-bom.version>1.21.0</common-bom.version>
<common-bom.version>1.23.0</common-bom.version>
<cpp.repo.name>generator-maven-plugin</cpp.repo.name>
<jackson-dataformat-yaml.version>2.8.6</jackson-dataformat-yaml.version>
</properties>

<scm>
Expand Down
67 changes: 67 additions & 0 deletions subscription-descriptor-parser/pom.xml
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>
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}
}
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;
}

}
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;
}
}

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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
}
Loading

0 comments on commit 8a23f28

Please sign in to comment.