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 2
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
amckenzie
committed
Dec 5, 2017
1 parent
461a87e
commit be21677
Showing
40 changed files
with
801 additions
and
738 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
catalog-core/src/main/java/uk/gov/justice/schema/catalog/Catalog.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,37 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import static java.util.Optional.empty; | ||
import static java.util.Optional.of; | ||
|
||
import uk.gov.justice.schema.catalog.client.SchemaClientFactory; | ||
|
||
import java.util.Optional; | ||
|
||
import org.everit.json.schema.Schema; | ||
import org.everit.json.schema.loader.SchemaClient; | ||
|
||
public class Catalog { | ||
|
||
private final RawCatalog rawCatalog; | ||
private final SchemaClientFactory schemaClientFactory; | ||
private final JsonStringToSchemaConverter jsonStringToSchemaConverter; | ||
|
||
public Catalog(final RawCatalog rawCatalog, final SchemaClientFactory schemaClientFactory, final JsonStringToSchemaConverter jsonStringToSchemaConverter) { | ||
this.rawCatalog = rawCatalog; | ||
this.schemaClientFactory = schemaClientFactory; | ||
this.jsonStringToSchemaConverter = jsonStringToSchemaConverter; | ||
} | ||
|
||
public Optional<Schema> getSchema(final String schemaId) { | ||
|
||
final Optional<String> rawJsonSchema = rawCatalog.getRawJsonSchema(schemaId); | ||
|
||
if (rawJsonSchema.isPresent()) { | ||
final SchemaClient schemaClient = schemaClientFactory.create(rawCatalog); | ||
final Schema schema = jsonStringToSchemaConverter.convert(rawJsonSchema.get(), schemaClient); | ||
return of(schema); | ||
} | ||
|
||
return empty(); | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
catalog-core/src/main/java/uk/gov/justice/schema/catalog/CatalogLoader.java
This file was deleted.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
catalog-core/src/main/java/uk/gov/justice/schema/catalog/CatalogObjectFactory.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,79 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import uk.gov.justice.schema.catalog.client.SchemaClientFactory; | ||
import uk.gov.justice.schema.catalog.util.ClasspathResourceLoader; | ||
import uk.gov.justice.schema.catalog.util.UriResolver; | ||
import uk.gov.justice.schema.catalog.util.UrlConverter; | ||
import uk.gov.justice.services.common.converter.jackson.ObjectMapperProducer; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class CatalogObjectFactory { | ||
|
||
public UrlConverter urlConverter() { | ||
return new UrlConverter(); | ||
} | ||
|
||
public ObjectMapper objectMapper() { | ||
return new ObjectMapperProducer().objectMapper(); | ||
} | ||
|
||
public UriResolver uriResolver() { | ||
return new UriResolver(); | ||
} | ||
|
||
public JsonStringToSchemaConverter jsonStringToSchemaConverter() { | ||
return new JsonStringToSchemaConverter(); | ||
} | ||
|
||
public ClasspathResourceLoader classpathResourceLoader() { | ||
return new ClasspathResourceLoader(); | ||
} | ||
|
||
public ClasspathCatalogLoader classpathCatalogLoader() { | ||
return new ClasspathCatalogLoader( | ||
objectMapper(), | ||
classpathResourceLoader(), | ||
urlConverter()); | ||
} | ||
|
||
public SchemaResolver schemaResolver() { | ||
return new SchemaResolver(urlConverter(), uriResolver()); | ||
} | ||
|
||
public CatalogToSchemaResolver catalogToSchemaResolver() { | ||
return new CatalogToSchemaResolver( | ||
classpathCatalogLoader(), | ||
schemaResolver(), | ||
getLogger(CatalogToSchemaResolver.class)); | ||
} | ||
|
||
public FileContentsAsStringLoader fileContentsAsStringLoader() { | ||
return new FileContentsAsStringLoader(); | ||
} | ||
|
||
public JsonSchemaFileLoader jsonSchemaFileLoader() { | ||
return new JsonSchemaFileLoader(fileContentsAsStringLoader(), catalogToSchemaResolver()); | ||
} | ||
|
||
public SchemaClientFactory schemaClientFactory() { | ||
return new SchemaClientFactory(); | ||
} | ||
|
||
public Catalog catalog() { | ||
return new Catalog( | ||
rawCatalog(), | ||
schemaClientFactory(), | ||
jsonStringToSchemaConverter()); | ||
} | ||
|
||
public RawCatalog rawCatalog() { | ||
final RawCatalog rawCatalog = new RawCatalog(jsonSchemaFileLoader()); | ||
rawCatalog.initialize(); | ||
|
||
return rawCatalog; | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
catalog-core/src/main/java/uk/gov/justice/schema/catalog/CatalogProducer.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,13 @@ | ||
package uk.gov.justice.schema.catalog; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.inject.Produces; | ||
|
||
@ApplicationScoped | ||
public class CatalogProducer { | ||
|
||
@Produces | ||
public Catalog catalog() { | ||
return new CatalogObjectFactory().catalog(); | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
catalog-core/src/main/java/uk/gov/justice/schema/catalog/RawCatalog.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.schema.catalog; | ||
|
||
import static java.util.Optional.ofNullable; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class RawCatalog { | ||
|
||
private final JsonSchemaFileLoader jsonSchemaFileLoader; | ||
|
||
private Map<String, String> schemaIdsToRawJsonSchemaCache = new HashMap<>(); | ||
|
||
public RawCatalog(final JsonSchemaFileLoader jsonSchemaFileLoader) { | ||
this.jsonSchemaFileLoader = jsonSchemaFileLoader; | ||
} | ||
|
||
public void initialize() { | ||
schemaIdsToRawJsonSchemaCache = jsonSchemaFileLoader.loadSchemas(); | ||
} | ||
|
||
public Optional<String> getRawJsonSchema(final String schemaId) { | ||
return ofNullable(schemaIdsToRawJsonSchemaCache.get(schemaId)); | ||
} | ||
} |
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
28 changes: 0 additions & 28 deletions
28
catalog-core/src/main/java/uk/gov/justice/schema/catalog/SchemaResolverAndLoader.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
...-core/src/main/java/uk/gov/justice/schema/catalog/client/LocalFileSystemSchemaClient.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,29 @@ | ||
package uk.gov.justice.schema.catalog.client; | ||
|
||
import static java.lang.String.format; | ||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
import uk.gov.justice.schema.catalog.RawCatalog; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.InputStream; | ||
|
||
import org.everit.json.schema.loader.SchemaClient; | ||
|
||
public class LocalFileSystemSchemaClient implements SchemaClient { | ||
|
||
private final RawCatalog rawCatalog; | ||
|
||
public LocalFileSystemSchemaClient(final RawCatalog rawCatalog) { | ||
this.rawCatalog = rawCatalog; | ||
} | ||
|
||
@Override | ||
public InputStream get(final String schemaId) { | ||
|
||
final String rawJsonSchema = rawCatalog.getRawJsonSchema(schemaId) | ||
.orElseThrow(() -> new SchemaClientException(format("Failed to find schema with id '%s'", schemaId))); | ||
|
||
return new ByteArrayInputStream(rawJsonSchema.getBytes(UTF_8)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../schema/client/SchemaClientException.java → ...catalog/client/SchemaClientException.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
12 changes: 12 additions & 0 deletions
12
catalog-core/src/main/java/uk/gov/justice/schema/catalog/client/SchemaClientFactory.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.schema.catalog.client; | ||
|
||
import uk.gov.justice.schema.catalog.RawCatalog; | ||
|
||
import org.everit.json.schema.loader.SchemaClient; | ||
|
||
public class SchemaClientFactory { | ||
|
||
public SchemaClient create(final RawCatalog rawCatalog) { | ||
return new LocalFileSystemSchemaClient(rawCatalog); | ||
} | ||
} |
Oops, something went wrong.