schema-dump #7
32
pom.xml
32
pom.xml
|
@ -137,7 +137,23 @@
|
|||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${dhp.jackson.version}</version>
|
||||
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -229,6 +245,19 @@
|
|||
<scalaVersion>${scala.version}</scalaVersion>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includePluginDependencies>true</includePluginDependencies>
|
||||
<mainClass>eu.dnetlib.dhp.schema.dump.ExecCreateSchemas</mainClass>
|
||||
<arguments>
|
||||
<argument>eu.dnetlib.dhp.schema.dump.oaf.GraphResult;eu.dnetlib.dhp.schema.dump.oaf.graph.Organization;eu.dnetlib.dhp.schema.dump.oaf.graph.Project</argument>
|
||||
|
||||
</arguments>
|
||||
</configuration>
|
||||
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
@ -364,13 +393,14 @@
|
|||
<groupId>com.github.victools</groupId>
|
||||
<artifactId>jsonschema-generator</artifactId>
|
||||
<version>${jsonschemagenerator.version}</version>
|
||||
<scope>test</scope>
|
||||
<!-- <scope>test</scope>-->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.imifou</groupId>
|
||||
<artifactId>jsonschema-module-addon</artifactId>
|
||||
<version>1.2.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package eu.dnetlib.dhp.schema.dump;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.github.imifou.jsonschema.module.addon.AddonModule;
|
||||
import com.github.victools.jsonschema.generator.*;
|
||||
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityResult;
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.graph.*;
|
||||
|
||||
public class ExecCreateSchemas {
|
||||
|
||||
SchemaGenerator generator;
|
||||
|
||||
private void init(){
|
||||
|
||||
AddonModule module = new AddonModule();
|
||||
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(
|
||||
new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT),
|
||||
SchemaVersion.DRAFT_7,
|
||||
OptionPreset.PLAIN_JSON)
|
||||
.with(module)
|
||||
.with(Option.SCHEMA_VERSION_INDICATOR)
|
||||
.without(Option.NONPUBLIC_NONSTATIC_FIELDS_WITHOUT_GETTERS);
|
||||
SchemaGeneratorConfig config = configBuilder.build();
|
||||
generator = new SchemaGenerator(config);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
if(!Files.exists(Paths.get(directory + filename))) {
|
||||
Files.createFile(Paths.get(directory + filename));
|
||||
}
|
||||
|
||||
File f = new File(directory + filename);
|
||||
|
||||
try(PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(f)))) {
|
||||
writer.println(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(jsonSchema));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
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(CommunityResult.class, "/tmp/jsonschemas/" , "community_result_schema.json");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -9,7 +9,7 @@ public class AuthorPidSchemeValue implements Serializable {
|
|||
@JsonSchema(description="The author's pid scheme. OpenAIRE currently supports 'ORCID'")
|
||||
private String scheme;
|
||||
|
||||
@JsonSchema(description="The author's pid value in that scheme (i.e. 0000-1111-2222-3333")
|
||||
@JsonSchema(description="The author's pid value in that scheme (i.e. 0000-1111-2222-3333)")
|
||||
private String value;
|
||||
|
||||
public String getScheme() {
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.dump.oaf;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
/**
|
||||
* To represent the information described by a scheme and a value in that scheme (i.e. doi). It has two parameters: -
|
||||
* scheme of type String to store the scheme - value of type String to store the value in that scheme
|
||||
*/
|
||||
public class ControlledField implements Serializable {
|
||||
@JsonSchema(description="The scheme used to express the value (i.e. doi)")
|
||||
private String scheme;
|
||||
|
||||
@JsonSchema(description="The value expressed in the scheme (i.e. 10.1000/182)")
|
||||
private String value;
|
||||
|
||||
public String getScheme() {
|
||||
return scheme;
|
||||
}
|
||||
|
||||
public void setScheme(String scheme) {
|
||||
this.scheme = scheme;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static ControlledField newInstance(String scheme, String value) {
|
||||
ControlledField cf = new ControlledField();
|
||||
|
||||
cf.setScheme(scheme);
|
||||
cf.setValue(value);
|
||||
|
||||
return cf;
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@ public class Funder implements Serializable {
|
|||
@JsonSchema(description = "The name of the funder (European Commission)")
|
||||
private String name;
|
||||
|
||||
@JsonSchema(description = "The jurisdiction of the funder (i.e. EU)")
|
||||
@JsonSchema(description = "Geographical jurisdiction (e.g. for European Commission is EU, for Croatian Science Foundation is HR)")
|
||||
private String jurisdiction;
|
||||
|
||||
public String getJurisdiction() {
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.dump.oaf;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
/**
|
||||
* To represent the information described by a key and a value. It has two parameters: - key to store the key (generally
|
||||
* the OpenAIRE id for some entity) - value to store the value (generally the OpenAIRE name for the key)
|
||||
*/
|
||||
public class KeyValue implements Serializable {
|
||||
|
||||
private String key;
|
||||
|
||||
private String value;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static KeyValue newInstance(String key, String value) {
|
||||
KeyValue inst = new KeyValue();
|
||||
inst.key = key;
|
||||
inst.value = value;
|
||||
return inst;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isBlank() {
|
||||
return StringUtils.isBlank(key) && StringUtils.isBlank(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.dump.oaf;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
/**
|
||||
* To represent the information described by a code and a value It has two parameters: - code to store the code
|
||||
* (generally the classid of the eu.dnetlib.dhp.schema.oaf.Qualifier element) - label to store the label (generally the
|
||||
* classname of the eu.dnetlib.dhp.schema.oaf.Qualifier element
|
||||
*/
|
||||
public class Qualifier implements Serializable {
|
||||
|
||||
@JsonSchema(description="A code in vocabulary ")
|
||||
private String code; // the classid in the Qualifier
|
||||
|
||||
@JsonSchema(description="A label for that code ")
|
||||
private String label; // the classname in the Qualifier
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static Qualifier newInstance(String code, String value) {
|
||||
Qualifier qualifier = new Qualifier();
|
||||
qualifier.setCode(code);
|
||||
qualifier.setLabel(value);
|
||||
return qualifier;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package eu.dnetlib.dhp.schema.dump.oaf.community;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
public class CfHbKeyValue implements Serializable {
|
||||
|
||||
@JsonSchema(description = "the OpenAIRE identifier of the data source")
|
||||
private String key;
|
||||
|
||||
@JsonSchema(description = "the name of the data source")
|
||||
private String value;
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static CfHbKeyValue newInstance(String key, String value) {
|
||||
CfHbKeyValue inst = new CfHbKeyValue();
|
||||
inst.key = key;
|
||||
inst.value = value;
|
||||
return inst;
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isBlank() {
|
||||
return StringUtils.isBlank(key) && StringUtils.isBlank(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.dump.oaf.community;
|
||||
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.Instance;
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.KeyValue;
|
||||
|
||||
/**
|
||||
* It extends eu.dnetlib.dhp.dump.oaf.Instance with values related to the community dump. In the Result dump this
|
||||
|
@ -15,22 +16,25 @@ import eu.dnetlib.dhp.schema.dump.oaf.KeyValue;
|
|||
* collectedfrom.key - value corresponds to collectedfrom.value
|
||||
*/
|
||||
public class CommunityInstance extends Instance {
|
||||
private KeyValue hostedby;
|
||||
private KeyValue collectedfrom;
|
||||
@JsonSchema(description = "Information about the source from which the instance can be viewed or downloaded.")
|
||||
private CfHbKeyValue hostedby;
|
||||
|
||||
public KeyValue getHostedby() {
|
||||
@JsonSchema(description = "Information about the source from which the record has been collected")
|
||||
private CfHbKeyValue collectedfrom;
|
||||
|
||||
public CfHbKeyValue getHostedby() {
|
||||
return hostedby;
|
||||
}
|
||||
|
||||
public void setHostedby(KeyValue hostedby) {
|
||||
public void setHostedby(CfHbKeyValue hostedby) {
|
||||
this.hostedby = hostedby;
|
||||
}
|
||||
|
||||
public KeyValue getCollectedfrom() {
|
||||
public CfHbKeyValue getCollectedfrom() {
|
||||
return collectedfrom;
|
||||
}
|
||||
|
||||
public void setCollectedfrom(KeyValue collectedfrom) {
|
||||
public void setCollectedfrom(CfHbKeyValue collectedfrom) {
|
||||
this.collectedfrom = collectedfrom;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.KeyValue;
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.Result;
|
||||
|
||||
/**
|
||||
|
@ -22,11 +21,14 @@ import eu.dnetlib.dhp.schema.dump.oaf.Result;
|
|||
*/
|
||||
public class CommunityResult extends Result {
|
||||
|
||||
@JsonSchema(description = "List of projects (i.e. grants) that (co-)funded the production ofn the research results")
|
||||
private List<Project> projects;
|
||||
|
||||
@JsonSchema(description = "Reference to a relevant research infrastructure, initiative or community (RI/RC) among those collaborating with OpenAIRE. Please see https://connect.openaire.eu")
|
||||
private List<Context> context;
|
||||
|
||||
protected List<KeyValue> collectedfrom;
|
||||
@JsonSchema(description = "Information about the sources from which the record has been collected")
|
||||
protected List<CfHbKeyValue> collectedfrom;
|
||||
|
||||
@JsonSchema(description = "Each instance is one specific materialisation or version of the result. For example, you can have one result with three instance: one is the pre-print, one is the post-print, one is te published version")
|
||||
private List<CommunityInstance> instance;
|
||||
|
@ -39,11 +41,11 @@ public class CommunityResult extends Result {
|
|||
this.instance = instance;
|
||||
}
|
||||
|
||||
public List<KeyValue> getCollectedfrom() {
|
||||
public List<CfHbKeyValue> getCollectedfrom() {
|
||||
return collectedfrom;
|
||||
}
|
||||
|
||||
public void setCollectedfrom(List<KeyValue> collectedfrom) {
|
||||
public void setCollectedfrom(List<CfHbKeyValue> collectedfrom) {
|
||||
this.collectedfrom = collectedfrom;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,9 @@ import java.util.Objects;
|
|||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.Provenance;
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.Qualifier;
|
||||
|
||||
/**
|
||||
* Reference to a relevant research infrastructure, initiative or community (RI/RC) among those collaborating with
|
||||
|
@ -21,7 +22,14 @@ import eu.dnetlib.dhp.schema.dump.oaf.Qualifier;
|
|||
* instantiated if the element datainfo.provenanceaction is not null. In this case - provenance corresponds to
|
||||
* dataInfo.provenanceaction.classname - trust corresponds to dataInfo.trust
|
||||
*/
|
||||
public class Context extends Qualifier {
|
||||
public class Context {
|
||||
@JsonSchema(description="Code identifying the RI/RC")
|
||||
private String code;
|
||||
|
||||
@JsonSchema(description="Label of the RI/RC")
|
||||
private String label;
|
||||
|
||||
@JsonSchema(description = "Why this result is associated to the RI/RC.")
|
||||
private List<Provenance> provenance;
|
||||
|
||||
public List<Provenance> getProvenance() {
|
||||
|
@ -32,6 +40,23 @@ public class Context extends Qualifier {
|
|||
this.provenance = provenance;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public void setLabel(String label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final String p = Optional.ofNullable(getProvenance())
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.dump.oaf.community;
|
||||
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
/**
|
||||
* To store information about the funder funding the project related to the result. It has the following parameters: -
|
||||
* shortName of type String to store the funder short name (e.c. AKA). - name of type String to store the funder name
|
||||
|
@ -9,6 +11,7 @@ package eu.dnetlib.dhp.schema.dump.oaf.community;
|
|||
*/
|
||||
public class Funder extends eu.dnetlib.dhp.schema.dump.oaf.Funder {
|
||||
|
||||
@JsonSchema(description = "Stream of funding (e.g. for European Commission can be H2020 or FP7)")
|
||||
private String fundingStream;
|
||||
|
||||
public String getFundingStream() {
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.dump.oaf.community;
|
||||
|
||||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.Provenance;
|
||||
|
||||
/**
|
||||
|
@ -13,6 +15,7 @@ import eu.dnetlib.dhp.schema.dump.oaf.Provenance;
|
|||
*/
|
||||
public class Project extends eu.dnetlib.dhp.schema.dump.oaf.Project {
|
||||
|
||||
@JsonSchema(description = "Information about the funder funding the project")
|
||||
private Funder funder;
|
||||
|
||||
private Provenance provenance;
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.List;
|
|||
import com.github.imifou.jsonschema.module.addon.annotation.JsonSchema;
|
||||
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.Container;
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.ControlledField;
|
||||
|
||||
/**
|
||||
* To store information about the datasource OpenAIRE collects information from. It contains the following parameters: -
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package eu.dnetlib.dhp.schema.oaf.dump;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -8,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.github.imifou.jsonschema.module.addon.AddonModule;
|
||||
import com.github.victools.jsonschema.generator.*;
|
||||
|
||||
import eu.dnetlib.dhp.schema.dump.ExecCreateSchemas;
|
||||
import eu.dnetlib.dhp.schema.dump.oaf.graph.*;
|
||||
|
||||
//@Disabled
|
||||
|
@ -42,4 +45,11 @@ class GenerateJsonSchema {
|
|||
|
||||
System.out.println(jsonSchema.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void generateJsonSchema3() throws IOException {
|
||||
|
||||
ExecCreateSchemas.main(new String[]{});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue