forked from finos/morphir
-
Notifications
You must be signed in to change notification settings - Fork 0
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
36dd0d7
commit 2f22276
Showing
10 changed files
with
764 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ node_modules | |
|
||
# Temp | ||
C4-PlantUML | ||
.idea/ | ||
.idea/ | ||
.gradle/ | ||
generated/ | ||
build/ |
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,65 @@ | ||
buildscript { | ||
repositories { | ||
mavenCentral() | ||
} | ||
dependencies { | ||
classpath 'org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:1.1.1' | ||
} | ||
} | ||
|
||
plugins { | ||
id 'java' | ||
} | ||
|
||
group 'com.example' | ||
version '1.0-SNAPSHOT' | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
/* | ||
//id "com.netflix.dgs.codegen" version "6.2.1" | ||
dependencyManagement { | ||
imports { | ||
mavenBom("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:latest.release") | ||
} | ||
} | ||
generateJava{ | ||
schemaPaths = ["${projectDir}/DataThread/src/main/resources"] | ||
packageName = 'org.datathread.query' | ||
generateClient = true | ||
} | ||
*/ | ||
|
||
dependencies { | ||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3' | ||
implementation 'org.jsonschema2pojo:jsonschema2pojo-gradle-plugin:1.1.1' | ||
implementation 'com.squareup:javapoet:1.13.0' | ||
// implementation "com.netflix.graphql.dgs:graphql-dgs-spring-graphql-starter" | ||
|
||
testImplementation 'junit:junit:4.13.1' | ||
} | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
|
||
apply plugin: 'jsonschema2pojo' | ||
|
||
jsonSchema2Pojo { | ||
source = files("$projectDir/generated/tsp-output") | ||
targetPackage = 'org.datathread.grammar' | ||
targetDirectory = file("$projectDir/generated/main/java") | ||
} | ||
|
||
sourceSets { | ||
main { | ||
java { | ||
srcDirs 'src/main/java', 'generated/main/java' | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
String baseDirArg = System.getProperty("baseDir", "metastore"); | ||
Path baseDir = Paths.get(baseDirArg).toAbsolutePath().normalize(); | ||
|
||
System.out.println("Using base folder: " + baseDir); | ||
|
||
if (!Files.exists(baseDir)) { | ||
try { | ||
Files.createDirectories(baseDir); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
SpringApplication.run(Application.class, args); | ||
} | ||
} | ||
|
||
@RestController | ||
class RequestController { | ||
|
||
@PostMapping("/element") | ||
public void createElement(@RequestBody String body) { | ||
|
||
processRequest(body, "element"); | ||
} | ||
|
||
@PostMapping("/dataset") | ||
public void createDataset(@RequestBody String body) { | ||
processRequest(body, "dataset"); | ||
} | ||
|
||
private void processRequest(String body, String type) { | ||
// TODO: Implement the logic to process the request here. | ||
} | ||
|
||
|
||
private void saveToFile(Map<String, Object> artifact) throws IOException { | ||
// Save as a JSON file in the data folder | ||
String id = (String) artifact.get("id"); | ||
String[] items = id.split(":"); | ||
String type = items[0]; | ||
Path filePath = Paths.get("data", type + ".json"); | ||
Files.write(filePath, artifact.toString().getBytes()); | ||
} | ||
} |
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,52 @@ | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.squareup.javapoet.TypeSpec; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.io.File; | ||
|
||
import org.datathread.grammar._typespec.json_schema.Element; | ||
import javax.lang.model.element.Modifier; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
String json = null; | ||
try { | ||
System.out.println(new File(".").getAbsolutePath()); | ||
File baseDir = new File("DataThread/example/metastore"); | ||
String id = "element:person:active"; | ||
File file = new File(baseDir, resolveForID(id).getPath()); | ||
|
||
json = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
ObjectMapper mapper = new ObjectMapper(); | ||
|
||
try { | ||
Element element = mapper.readValue(json, Element.class); | ||
TypeSpec java = elementToJava(element); | ||
System.out.println(java); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static TypeSpec elementToJava(Element element) { | ||
TypeSpec java = TypeSpec.classBuilder(element.getName()) | ||
.addModifiers(Modifier.PUBLIC, Modifier.FINAL) | ||
.build(); | ||
|
||
return java; | ||
} | ||
|
||
public static File resolveForID(String id) { | ||
String[] parts = id.split(":"); | ||
return resolveFile(parts[0], parts[1], parts[2]); | ||
} | ||
|
||
public static File resolveFile(String schemaType, String domain, String name) { | ||
return new File(domain, name + "." + schemaType + ".json"); | ||
} | ||
} |
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,14 @@ | ||
type Dataset { | ||
id: ID! | ||
name: String! | ||
version: Int! | ||
fields: [Field!]! | ||
} | ||
|
||
type Field { | ||
name: String! | ||
element: Element! | ||
optional: Boolean | ||
key: Boolean | ||
} | ||
|
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,90 @@ | ||
type Element { | ||
id: ID! | ||
name: String! | ||
element_type: ElementType! | ||
info: ElementInfo | ||
} | ||
|
||
union ElementType = TextType | NumberType | ReferenceType | DateType | TimeType | DateTimeType | BooleanType | EnumType | RecordType | ||
|
||
scalar Date | ||
|
||
type DateType { | ||
Date : Date | ||
} | ||
|
||
scalar Time | ||
|
||
type TimeType { | ||
Time : Time | ||
} | ||
|
||
scalar DateTime | ||
|
||
type DateTimeType { | ||
DateTime : DateTime | ||
} | ||
|
||
scalar Bool | ||
|
||
type BooleanType { | ||
Boolean : Bool | ||
} | ||
|
||
type TextType { | ||
Text : Text! | ||
} | ||
|
||
type Text { | ||
min_length: Int | ||
max_length: Int | ||
} | ||
|
||
type NumberType { | ||
Number : Number! | ||
} | ||
|
||
type Number { | ||
minimum: Int | ||
maximum: Int | ||
precision: Int | ||
} | ||
|
||
type ReferenceType { | ||
Reference : Reference! | ||
} | ||
|
||
type Reference { | ||
ref: Element! | ||
} | ||
|
||
type EnumType { | ||
Enum : Enum! | ||
} | ||
|
||
type Enum { | ||
values: [String]! | ||
} | ||
|
||
type RecordType { | ||
Record : Record! | ||
} | ||
|
||
type Record { | ||
name: String | ||
fields: [Field] | ||
} | ||
|
||
type Field { | ||
name: String! | ||
element: Element! | ||
optional: Boolean | ||
} | ||
|
||
|
||
type ElementInfo { | ||
id: ID! | ||
description: String | ||
display_name: String | ||
short_display_name: String | ||
} |
Oops, something went wrong.