schema-dump #7
|
@ -2,6 +2,7 @@ package eu.dnetlib.dhp.schema.dump;
|
|||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
|
@ -15,7 +16,7 @@ import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityResult;
|
|||
import eu.dnetlib.dhp.schema.dump.oaf.graph.*;
|
||||
|
||||
public class ExecCreateSchemas {
|
||||
|
||||
final static String DIRECTORY = "/eu/dnetlib/dhp/schema/oaf/dump/jsonschemas/";
|
||||
SchemaGenerator generator;
|
||||
|
||||
private void init(){
|
||||
|
@ -35,15 +36,17 @@ public class ExecCreateSchemas {
|
|||
private void generate(Type targetType, String directory, String filename) throws IOException {
|
||||
JsonNode jsonSchema = generator.generateSchema(targetType);
|
||||
|
||||
if(!Files.exists(Paths.get(directory))){
|
||||
Files.createDirectories(Paths.get(directory));
|
||||
String dir = Paths.get(Paths.get(getClass().getResource("/").getPath()).toAbsolutePath() + directory).toString();
|
||||
|
||||
if(!Files.exists(Paths.get(dir))){
|
||||
Files.createDirectories(Paths.get(dir));
|
||||
}
|
||||
|
||||
if(!Files.exists(Paths.get(directory + filename))) {
|
||||
Files.createFile(Paths.get(directory + filename));
|
||||
if(!Files.exists(Paths.get(dir + "/" + filename))) {
|
||||
Files.createFile(Paths.get(dir + "/" + filename));
|
||||
}
|
||||
|
||||
File f = new File(directory + filename);
|
||||
File f = new File(dir + "/" + filename);
|
||||
|
||||
try(PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(f)))) {
|
||||
writer.println(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));
|
||||
|
@ -55,14 +58,14 @@ public class ExecCreateSchemas {
|
|||
|
||||
ExecCreateSchemas ecs = new ExecCreateSchemas();
|
||||
ecs.init();
|
||||
ecs.generate(GraphResult.class, "/tmp/jsonschemas/" , "result_schema.json");
|
||||
ecs.generate(ResearchCommunity.class, "/tmp/jsonschemas/" , "community_infrastructure_schema.json");
|
||||
ecs.generate(Datasource.class, "/tmp/jsonschemas/" , "datasource_schema.json");
|
||||
ecs.generate(Project.class, "/tmp/jsonschemas/" , "project_schema.json");
|
||||
ecs.generate(Relation.class, "/tmp/jsonschemas/" , "relation_schema.json");
|
||||
ecs.generate(Organization.class, "/tmp/jsonschemas/" , "organization_schema.json");
|
||||
ecs.generate(GraphResult.class, DIRECTORY , "result_schema.json");
|
||||
ecs.generate(ResearchCommunity.class, DIRECTORY , "community_infrastructure_schema.json");
|
||||
ecs.generate(Datasource.class, DIRECTORY , "datasource_schema.json");
|
||||
ecs.generate(Project.class, DIRECTORY , "project_schema.json");
|
||||
ecs.generate(Relation.class, DIRECTORY , "relation_schema.json");
|
||||
ecs.generate(Organization.class, DIRECTORY , "organization_schema.json");
|
||||
|
||||
ecs.generate(CommunityResult.class, "/tmp/jsonschemas/" , "community_result_schema.json");
|
||||
ecs.generate(CommunityResult.class, DIRECTORY , "community_result_schema.json");
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue