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
e6baa8d
commit b65e787
Showing
15 changed files
with
457 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?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>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hamcrest</groupId> | ||
<artifactId>hamcrest-library</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
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; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...riptor-parser/src/main/java/uk/gov/justice/domain/subscriptiondescriptor/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.subscriptiondescriptor; | ||
|
||
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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...escriptor-parser/src/main/java/uk/gov/justice/domain/subscriptiondescriptor/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,19 @@ | ||
package uk.gov.justice.domain.subscriptiondescriptor; | ||
|
||
public class Location { | ||
private final String jmsUri; | ||
private final String restUri; | ||
|
||
public Location(final String jmsUri, final String restUri) { | ||
this.jmsUri = jmsUri; | ||
this.restUri = restUri; | ||
} | ||
|
||
public String getJmsUri() { | ||
return jmsUri; | ||
} | ||
|
||
public String getRestUri() { | ||
return restUri; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...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,28 @@ | ||
package uk.gov.justice.domain.subscriptiondescriptor; | ||
|
||
import java.util.List; | ||
|
||
public class Subscription { | ||
|
||
private final String name; | ||
private final List<Event> events; | ||
private final Eventsource eventsource; | ||
|
||
public Subscription(final String name, final List<Event> events, final Eventsource eventsource) { | ||
this.name = name; | ||
this.events = events; | ||
this.eventsource = eventsource; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public List<Event> getEvents() { | ||
return events; | ||
} | ||
|
||
public Eventsource getEventsource() { | ||
return eventsource; | ||
} | ||
} |
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; | ||
} | ||
} | ||
|
42 changes: 42 additions & 0 deletions
42
...java/uk/gov/justice/maven/generator/io/files/parser/SubscriptionDescriptorFileParser.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,42 @@ | ||
package uk.gov.justice.maven.generator.io.files.parser; | ||
|
||
import static com.fasterxml.jackson.annotation.JsonCreator.Mode.PROPERTIES; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.SubscriptionDescriptor; | ||
import uk.gov.justice.domain.subscriptiondescriptor.SubscriptionDescriptorDef; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategy; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; | ||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; | ||
|
||
public class SubscriptionDescriptorFileParser implements FileParser<SubscriptionDescriptor> { | ||
|
||
@Override | ||
public Collection<SubscriptionDescriptor> parse(final Path baseDir, final Collection<Path> paths) { | ||
return paths.stream() | ||
.map(path -> read(baseDir.resolve(path).toAbsolutePath().toString())) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private SubscriptionDescriptor read(final String filePath) { | ||
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()) | ||
.registerModule(new Jdk8Module()) | ||
.registerModule(new ParameterNamesModule(PROPERTIES)); | ||
|
||
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES); | ||
|
||
try { | ||
return mapper.readValue(new File(filePath), SubscriptionDescriptorDef.class).getSubscriptionDescriptor(); | ||
} catch (IOException e) { | ||
throw new SubscriptionDescriptorIOException("Failed to read subscriptions yaml file", e); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
.../gov/justice/maven/generator/io/files/parser/SubscriptionDescriptorFileParserFactory.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,12 @@ | ||
package uk.gov.justice.maven.generator.io.files.parser; | ||
|
||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.SubscriptionDescriptor; | ||
|
||
public class SubscriptionDescriptorFileParserFactory implements FileParserFactory<SubscriptionDescriptor> { | ||
|
||
@Override | ||
public SubscriptionDescriptorFileParser create() { | ||
return new SubscriptionDescriptorFileParser(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ava/uk/gov/justice/maven/generator/io/files/parser/SubscriptionDescriptorIOException.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; | ||
|
||
public class SubscriptionDescriptorIOException extends RuntimeException { | ||
public SubscriptionDescriptorIOException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../justice/maven/generator/io/files/parser/SubscriptionDescriptorFileParserFactoryTest.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,21 @@ | ||
package uk.gov.justice.maven.generator.io.files.parser; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import uk.gov.justice.domain.subscriptiondescriptor.SubscriptionDescriptor; | ||
|
||
import org.junit.Test; | ||
|
||
public class SubscriptionDescriptorFileParserFactoryTest { | ||
|
||
@Test | ||
public void shouldCreateJsonSchemaFileParser() throws Exception { | ||
|
||
final FileParser<SubscriptionDescriptor> subscriptionDescriptorFileParser = new SubscriptionDescriptorFileParserFactory().create(); | ||
|
||
assertThat(subscriptionDescriptorFileParser, is(instanceOf(SubscriptionDescriptorFileParser.class))); | ||
} | ||
|
||
} |
Oops, something went wrong.