Skip to content

Commit 20d64cb

Browse files
authored
Merge pull request #3 from marmoure/feature/schema-content
Get schema content
2 parents ac9c10a + a7ac644 commit 20d64cb

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/main/java/com/evolvedbinary/bblValidator/controller/SchemaController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.micronaut.http.annotation.Controller;
77
import io.micronaut.http.annotation.Get;
88
import io.micronaut.http.annotation.Produces;
9+
import io.micronaut.http.annotation.PathVariable;
910

1011
import java.util.List;
1112

@@ -23,4 +24,10 @@ public SchemaController(SchemaService schemaService) {
2324
public List<SchemaInfo> listSchemas() {
2425
return schemaService.listSchemas();
2526
}
27+
28+
@Get("/{schema-id}")
29+
@Produces("text/csv-schema")
30+
public String getSchema(@PathVariable("schema-id") String schemaId) throws Exception {
31+
return schemaService.getSchema(schemaId);
32+
}
2633
}

src/main/java/com/evolvedbinary/bblValidator/service/SchemaService.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
import java.nio.file.Path;
1515
import java.nio.file.Paths;
1616
import java.util.ArrayList;
17+
import java.util.HashMap;
1718
import java.util.List;
19+
import java.util.Map;
1820
import java.util.stream.Stream;
1921

2022
@Singleton
@@ -24,6 +26,7 @@ public class SchemaService {
2426
private static final String SCHEMA_DIRECTORY = "schemas";
2527

2628
private final List<SchemaInfo> schemas = new ArrayList<>();
29+
private final Map<String, String> schemaContents = new HashMap<>();
2730
private final ObjectMapper objectMapper = new ObjectMapper();
2831

2932
@PostConstruct
@@ -78,6 +81,8 @@ private void loadSchemaMetadata(Path metadataPath) {
7881
Path schemaFilePath = metadataPath.getParent().resolve(schemaFileName);
7982

8083
if (Files.exists(schemaFilePath)) {
84+
String schemaContent = Files.readString(schemaFilePath, StandardCharsets.UTF_8);
85+
schemaContents.put(schemaInfo.getId(), schemaContent);
8186
schemas.add(schemaInfo);
8287
LOG.debug("Loaded schema: {}", schemaInfo.getId());
8388
} else {
@@ -91,5 +96,15 @@ private void loadSchemaMetadata(Path metadataPath) {
9196
public List<SchemaInfo> listSchemas() {
9297
return new ArrayList<>(schemas);
9398
}
99+
100+
public String getSchema(String schemaId) throws Exception {
101+
String content = schemaContents.get(schemaId);
102+
103+
if (content == null) {
104+
throw new Exception("Schema not found: " + schemaId);
105+
}
106+
107+
return content;
108+
}
94109
}
95110

0 commit comments

Comments
 (0)