From 5d645955fdf44eb6d8bc4f79d529e386ed5c334a Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 12:37:20 -0500 Subject: [PATCH 1/8] enum for configuration flags --- src/main/java/edu/isi/oba/config/CONFIG_FLAG.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/main/java/edu/isi/oba/config/CONFIG_FLAG.java diff --git a/src/main/java/edu/isi/oba/config/CONFIG_FLAG.java b/src/main/java/edu/isi/oba/config/CONFIG_FLAG.java new file mode 100644 index 0000000..b9622be --- /dev/null +++ b/src/main/java/edu/isi/oba/config/CONFIG_FLAG.java @@ -0,0 +1,13 @@ +package edu.isi.oba.config; + +public enum CONFIG_FLAG { + ALWAYS_GENERATE_ARRAYS, + DEFAULT_DESCRIPTIONS, + DEFAULT_PROPERTIES, + FOLLOW_REFERENCES, + PATH_DELETE, + PATH_GET, + PATH_PATCH, + PATH_POST, + PATH_PUT +} From 8faf2b209ba3257be4d85cbd3e15436cb671c5d0 Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 12:38:28 -0500 Subject: [PATCH 2/8] use map for configuration flags; getters for map --- .../java/edu/isi/oba/config/YamlConfig.java | 87 ++++++++++++------- 1 file changed, 58 insertions(+), 29 deletions(-) diff --git a/src/main/java/edu/isi/oba/config/YamlConfig.java b/src/main/java/edu/isi/oba/config/YamlConfig.java index 97f4dbc..98530a4 100644 --- a/src/main/java/edu/isi/oba/config/YamlConfig.java +++ b/src/main/java/edu/isi/oba/config/YamlConfig.java @@ -3,67 +3,71 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.PathItem; +import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; public class YamlConfig { + private final Map configFlags = new HashMap<>(){{ + put(CONFIG_FLAG.ALWAYS_GENERATE_ARRAYS, true); + put(CONFIG_FLAG.DEFAULT_DESCRIPTIONS, true); + put(CONFIG_FLAG.DEFAULT_PROPERTIES, true); + put(CONFIG_FLAG.FOLLOW_REFERENCES, true); + put(CONFIG_FLAG.PATH_DELETE, false); + put(CONFIG_FLAG.PATH_GET, true); + put(CONFIG_FLAG.PATH_PATCH, false); + put(CONFIG_FLAG.PATH_POST, false); + put(CONFIG_FLAG.PATH_PUT, false); + }}; + String DEFAULT_OUTPUT_DIRECTORY = "outputs"; String DEFAULT_PROJECT_NAME = "default_project"; public OpenAPI openapi; public String output_dir = DEFAULT_OUTPUT_DIRECTORY; public String name = DEFAULT_PROJECT_NAME; public List paths; - public Boolean enable_get_paths = true; - public Boolean enable_post_paths = false; - public Boolean enable_put_paths = false; - public Boolean enable_delete_paths = false; public List ontologies; private EndpointConfig endpoint; - public AuthConfig auth; public FirebaseConfig firebase; public Map> relations; private LinkedHashMap custom_paths = null; public List classes; - public Boolean follow_references = false; - public Boolean default_descriptions = true; - public Boolean default_properties = true; + public String custom_queries_directory; public Boolean getEnable_get_paths() { - return enable_get_paths; + return this.configFlags.get(CONFIG_FLAG.PATH_GET); } public void setEnable_get_paths(Boolean enable_get_paths) { - this.enable_get_paths = enable_get_paths; + this.configFlags.put(CONFIG_FLAG.PATH_GET, enable_get_paths); } public Boolean getEnable_post_paths() { - return enable_post_paths; + return this.configFlags.get(CONFIG_FLAG.PATH_POST); } public void setEnable_post_paths(Boolean enable_post_paths) { - this.enable_post_paths = enable_post_paths; + this.configFlags.put(CONFIG_FLAG.PATH_POST, enable_post_paths); } public Boolean getEnable_put_paths() { - return enable_put_paths; + return this.configFlags.get(CONFIG_FLAG.PATH_PUT); } public void setEnable_put_paths(Boolean enable_put_paths) { - this.enable_put_paths = enable_put_paths; + this.configFlags.put(CONFIG_FLAG.PATH_PUT, enable_put_paths); } public Boolean getEnable_delete_paths() { - return enable_delete_paths; + return this.configFlags.get(CONFIG_FLAG.PATH_DELETE); } public void setEnable_delete_paths(Boolean enable_delete_paths) { - this.enable_delete_paths = enable_delete_paths; + this.configFlags.put(CONFIG_FLAG.PATH_DELETE, enable_delete_paths); } - public String custom_queries_directory; - public String getCustom_queries_directory() { return custom_queries_directory; } @@ -128,7 +132,6 @@ public void setRelations(Map> relations) { this.relations = relations; } - public LinkedHashMap getCustom_paths() { return custom_paths; } @@ -145,36 +148,44 @@ public void setOpenapi(OpenAPI openapi) { this.openapi = openapi; } - public List getClasses() { - return this.classes; - } + public List getClasses() { + return this.classes; + } public void setClasses(List classes) { this.classes = classes; } + public Boolean getAlways_generate_arrays() { + return this.configFlags.get(CONFIG_FLAG.ALWAYS_GENERATE_ARRAYS); + } + + public void setAlways_generate_arrays(Boolean always_generate_arrays) { + this.configFlags.put(CONFIG_FLAG.ALWAYS_GENERATE_ARRAYS, always_generate_arrays); + } + public Boolean getFollow_references() { - return follow_references; + return this.configFlags.get(CONFIG_FLAG.FOLLOW_REFERENCES); } public void setFollow_references(Boolean follow_references) { - this.follow_references = follow_references; + this.configFlags.put(CONFIG_FLAG.FOLLOW_REFERENCES, follow_references); } public Boolean getDefault_descriptions() { - return this.default_descriptions; + return this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS); } public void setDefault_descriptions(Boolean default_descriptions) { - this.default_descriptions = default_descriptions; + this.configFlags.put(CONFIG_FLAG.DEFAULT_DESCRIPTIONS, default_descriptions); } public Boolean getDefault_properties() { - return this.default_properties; + return this.configFlags.get(CONFIG_FLAG.DEFAULT_PROPERTIES); } public void setDefault_properties(Boolean default_properties) { - this.default_properties = default_properties; + this.configFlags.put(CONFIG_FLAG.DEFAULT_PROPERTIES, default_properties); } public AuthConfig getAuth() { @@ -184,5 +195,23 @@ public AuthConfig getAuth() { public void setAuth(AuthConfig auth) { this.auth = auth; } -} + /** + * Get the value of a particular configuration flag. + * + * @param {flag} the configuration flag name + * @return The flag's value (true/false/null). + */ + public Boolean getConfigFlagValue(CONFIG_FLAG flag) { + return this.configFlags.get(flag); + } + + /** + * Get map of all config flags and their values. + * + * @return Map of CONFIG_FLAGs and their Boolean value (true/false/null). + */ + public Map getConfigFlags() { + return this.configFlags; + } +} \ No newline at end of file From 89bbf1f5a247602db9636d1518cdd20e66c913a6 Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 12:46:39 -0500 Subject: [PATCH 3/8] add PATCH placeholder; minor cleanup --- .../java/edu/isi/oba/MapperOperation.java | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/main/java/edu/isi/oba/MapperOperation.java b/src/main/java/edu/isi/oba/MapperOperation.java index 7b9d7a5..584f806 100644 --- a/src/main/java/edu/isi/oba/MapperOperation.java +++ b/src/main/java/edu/isi/oba/MapperOperation.java @@ -2,7 +2,6 @@ import io.swagger.models.Method; import io.swagger.v3.oas.models.Operation; -import io.swagger.v3.oas.models.headers.Header; import io.swagger.v3.oas.models.media.*; import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.PathParameter; @@ -30,14 +29,12 @@ class MapperOperation { private final ApiResponses apiResponses = new ApiResponses(); private final Cardinality cardinality; private final Schema schema; + private final Operation operation; public Operation getOperation() { return operation; } - private final Operation operation; - - public MapperOperation(String schemaName, String schemaURI, Method method, Cardinality cardinality, Boolean auth) { this.auth = auth; this.cardinality = cardinality; @@ -50,6 +47,9 @@ public MapperOperation(String schemaName, String schemaURI, Method method, Cardi case GET: setOperationGet(); break; + case PATCH: + setOperationPatch(); + break; case PUT: setOperationPut(); break; @@ -59,7 +59,8 @@ public MapperOperation(String schemaName, String schemaURI, Method method, Cardi case DELETE: setOperationDelete(); break; - + default: + break; } if (cardinality == Cardinality.SINGULAR){ @@ -70,13 +71,14 @@ public MapperOperation(String schemaName, String schemaURI, Method method, Cardi .schema(new StringSchema())); } - if (auth && (method == Method.PUT || method == Method.POST || method == Method.DELETE )) { + if (auth && Set.of(Method.PATCH, Method.PUT, Method.POST, Method.DELETE).contains(method)) { parameters.add(new QueryParameter() .description("Username") .name("user") .required(false) .schema(new StringSchema())); } + operation = new Operation() .description(description) .summary(summary) @@ -84,18 +86,15 @@ public MapperOperation(String schemaName, String schemaURI, Method method, Cardi .parameters(parameters) .responses(apiResponses); - - if (method == Method.PUT || method == Method.POST ){ + if (Set.of(Method.PATCH, Method.PUT, Method.POST).contains(method)) { operation.setRequestBody(requestBody); } - - if (method == Method.PUT || method == Method.POST || method == Method.DELETE ){ + if (Set.of(Method.PATCH, Method.PUT, Method.POST, Method.DELETE).contains(method)) { SecurityRequirement securityRequirement = new SecurityRequirement(); securityRequirement.addList("BearerAuth"); operation.addSecurityItem(securityRequirement); } - } private void setOperationGet() { @@ -113,7 +112,7 @@ private void setOperationGet() { case PLURAL: summary = "List all instances of " + this.schemaName; description = "Gets a list of all instances of " + this.schemaName + - " (more information in " +this.schemaURI+")"; + " (more information in " + this.schemaURI + ")"; responseDescriptionOk = "Successful response - returns an array with the instances of " + schemaName + "."; //Set response @@ -140,9 +139,9 @@ private void setOperationGet() { .schema(new IntegerSchema()._default(100).maximum(BigDecimal.valueOf(200)).minimum(BigDecimal.valueOf(1)))); break; case SINGULAR: - summary = "Get a single " + this.schemaName +" by its id"; - description = "Gets the details of a given " + this.schemaName+ - " (more information in " +this.schemaURI+")"; + summary = "Get a single " + this.schemaName + " by its id"; + description = "Gets the details of a given " + this.schemaName + + " (more information in " + this.schemaURI + ")"; responseDescriptionOk = "Gets the details of a given " + schemaName; //Set request @@ -153,7 +152,10 @@ private void setOperationGet() { break; } + } + private void setOperationPatch() { + // TODO: implement } private void setOperationPost() { @@ -177,13 +179,12 @@ private void setOperationPost() { ); } - private void setOperationPut() { String requestDescription = "An old " + this.schemaName + "to be updated"; summary = "Update an existing " + this.schemaName; - description = "Updates an existing " + this.schemaName+ - " (more information in " +this.schemaURI+")"; + description = "Updates an existing " + this.schemaName + + " (more information in " + this.schemaURI + ")"; //Set request MediaType mediaType = new MediaType().schema(schema); @@ -199,14 +200,12 @@ private void setOperationPut() { ) .addApiResponse("404", new ApiResponse() .description("Not Found")); - } - private void setOperationDelete() { summary = "Delete an existing " + this.schemaName; - description = "Delete an existing " + this.schemaName+ - " (more information in " +this.schemaURI+")"; + description = "Delete an existing " + this.schemaName + + " (more information in " + this.schemaURI + ")"; //Set the response apiResponses @@ -214,7 +213,5 @@ private void setOperationDelete() { .description("Deleted")) .addApiResponse("404", new ApiResponse() .description("Not Found")); - } - } From 123ca03ca34e26d49f615fbaebf671f6b7985e0b Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 12:51:38 -0500 Subject: [PATCH 4/8] cleanup --- src/main/java/edu/isi/oba/Oba.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/edu/isi/oba/Oba.java b/src/main/java/edu/isi/oba/Oba.java index b3b3c17..2b6f33a 100644 --- a/src/main/java/edu/isi/oba/Oba.java +++ b/src/main/java/edu/isi/oba/Oba.java @@ -4,7 +4,6 @@ import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.PathItem; import org.json.JSONObject; -import org.openapitools.codegen.examples.ExampleGenerator; import java.io.*; import java.nio.file.Path; From cd5a22aeac4f7def9f8acef669deaa41235a5fb3 Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 12:54:04 -0500 Subject: [PATCH 5/8] rename to PathGenerator; use configuration flags Map The reason for renaming this is because 1) all the variables referred to is as "path generator" anyway and 2) to avoid confusion with java.nio.file.Path --- .../isi/oba/{Path.java => PathGenerator.java} | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) rename src/main/java/edu/isi/oba/{Path.java => PathGenerator.java} (78%) diff --git a/src/main/java/edu/isi/oba/Path.java b/src/main/java/edu/isi/oba/PathGenerator.java similarity index 78% rename from src/main/java/edu/isi/oba/Path.java rename to src/main/java/edu/isi/oba/PathGenerator.java index 72023c8..6afb52c 100644 --- a/src/main/java/edu/isi/oba/Path.java +++ b/src/main/java/edu/isi/oba/PathGenerator.java @@ -1,62 +1,65 @@ package edu.isi.oba; +import edu.isi.oba.config.CONFIG_FLAG; + import io.swagger.models.Method; import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.PathItem; import io.swagger.v3.oas.models.headers.Header; import io.swagger.v3.oas.models.media.*; -import io.swagger.v3.oas.models.parameters.Parameter; -import io.swagger.v3.oas.models.parameters.PathParameter; import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.responses.ApiResponses; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; -class Path { - public Boolean enable_get_paths; - public Boolean enable_post_paths; - public Boolean enable_put_paths; - public Boolean enable_delete_paths; +class PathGenerator { + private final Map configFlags = new HashMap<>(); private Boolean auth; - public Path(Boolean enable_get_paths, Boolean enable_post_paths, Boolean enable_put_paths, Boolean enable_delete_paths, Boolean auth) { + public PathGenerator(Map configFlags, Boolean auth) { this.auth = auth; - this.enable_get_paths = enable_get_paths; - this.enable_post_paths = enable_post_paths; - this.enable_put_paths = enable_put_paths; - this.enable_delete_paths = enable_delete_paths; + this.configFlags.putAll(configFlags); } - public PathItem generate_singular(String schemaName, String schemaURI){ + public PathItem generate_singular(String schemaName, String schemaURI) { PathItem path_item = new PathItem(); - if (enable_get_paths) + if (this.configFlags.get(CONFIG_FLAG.PATH_GET)) { path_item.get(new MapperOperation(schemaName, schemaURI, Method.GET, Cardinality.SINGULAR, auth).getOperation()); + } - if (enable_delete_paths) + if (this.configFlags.get(CONFIG_FLAG.PATH_DELETE)) { path_item.delete(new MapperOperation(schemaName, schemaURI, Method.DELETE, Cardinality.SINGULAR, auth).getOperation()); + } + + if (this.configFlags.get(CONFIG_FLAG.PATH_POST)) { + path_item.put(new MapperOperation(schemaName, schemaURI, Method.POST, Cardinality.SINGULAR, auth).getOperation()); + } - if (enable_put_paths) + if (this.configFlags.get(CONFIG_FLAG.PATH_PUT)) { path_item.put(new MapperOperation(schemaName, schemaURI, Method.PUT, Cardinality.SINGULAR, auth).getOperation()); + } return path_item; } - public PathItem generate_plural(String schemaName, String schemaURI){ + public PathItem generate_plural(String schemaName, String schemaURI) { PathItem path_item = new PathItem(); - if (enable_get_paths) + if (this.configFlags.get(CONFIG_FLAG.PATH_GET)) { path_item.get(new MapperOperation(schemaName, schemaURI, Method.GET, Cardinality.PLURAL, auth).getOperation()); - if (enable_post_paths) + } + + if (this.configFlags.get(CONFIG_FLAG.PATH_POST)) { path_item.post(new MapperOperation(schemaName,schemaURI, Method.POST, Cardinality.PLURAL, auth).getOperation()); + } + return path_item; } - public PathItem user_login(String schema_name) { + public static PathItem user_login(String schema_name) { ApiResponses apiResponses = new ApiResponses(); final RequestBody requestBody = new RequestBody(); From e3d7f65ba2da99b731375e7ced199fa93e5fe9ac Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 12:55:00 -0500 Subject: [PATCH 6/8] use configuration flags / map throughout --- src/main/java/edu/isi/oba/Mapper.java | 31 ++++------- src/main/java/edu/isi/oba/MapperSchema.java | 32 +++++------ src/test/java/edu/isi/oba/MapperTest.java | 5 +- src/test/java/edu/isi/oba/ObaUtilsTest.java | 2 - .../java/edu/isi/oba/RestrictionsTest.java | 54 +++++++++++-------- 5 files changed, 58 insertions(+), 66 deletions(-) diff --git a/src/main/java/edu/isi/oba/Mapper.java b/src/main/java/edu/isi/oba/Mapper.java index 9d931a2..9a3195c 100644 --- a/src/main/java/edu/isi/oba/Mapper.java +++ b/src/main/java/edu/isi/oba/Mapper.java @@ -1,5 +1,6 @@ package edu.isi.oba; +import edu.isi.oba.config.CONFIG_FLAG; import edu.isi.oba.config.YamlConfig; import static edu.isi.oba.Oba.logger; @@ -33,17 +34,11 @@ class Mapper { YamlConfig config_data; public OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); - private Boolean follow_references; - private Boolean default_descriptions; - private Boolean default_properties; public Mapper(YamlConfig config_data) throws OWLOntologyCreationException, IOException { this.config_data = config_data; this.selected_paths = config_data.getPaths(); this.mappedClasses = new ArrayList<>(); - this.follow_references = config_data.getFollow_references(); - this.default_descriptions = config_data.getDefault_descriptions(); - this.default_properties = config_data.getDefault_properties(); List config_ontologies = config_data.getOntologies(); String destination_dir = config_data.getOutput_dir() + File.separator + config_data.getName(); @@ -106,14 +101,10 @@ private void download_ontologies(List config_ontologies, String destinat * The schemas includes the properties * * @param destination_dir directory to write the final results - * @param config_data yaml configuration */ public void createSchemas(String destination_dir) { Query query = new Query(destination_dir); - Path pathGenerator = new Path(this.config_data.getEnable_get_paths(), - this.config_data.getEnable_post_paths(), - this.config_data.getEnable_put_paths(), - this.config_data.getEnable_delete_paths(), + PathGenerator pathGenerator = new PathGenerator(this.config_data.getConfigFlags(), this.config_data.getAuth().getEnable() ); @@ -148,7 +139,7 @@ public void createSchemas(String destination_dir) { } } - private void add_user_path(Path pathGenerator) { + private void add_user_path(PathGenerator pathGenerator) { //User schema Map userProperties = new HashMap<>(); StringSchema username = new StringSchema(); @@ -165,7 +156,7 @@ private void add_user_path(Path pathGenerator) { this.paths.addPathItem("/user/login", pathGenerator.user_login(userSchema.getName())); } - private List add_owlclass_to_openapi(Query query, Path pathGenerator, OWLOntology ontology, + private List add_owlclass_to_openapi(Query query, PathGenerator pathGenerator, OWLOntology ontology, String defaultOntologyPrefixIRI, OWLClass cls, Boolean topLevel) { List ref = new ArrayList<>(); String classPrefixIRI = cls.getIRI().getNamespace(); @@ -182,7 +173,7 @@ private List add_owlclass_to_openapi(Query query, Path pathGenerator, if(ontology.containsClassInSignature(clsToCheck.getIRI())) { System.out.println("ADD "+ clsToCheck); for (OWLOntology temp_ontology : this.ontologies) { - if (follow_references) { + if (this.config_data.getConfigFlagValue(CONFIG_FLAG.FOLLOW_REFERENCES)) { this.mappedClasses.add(clsToCheck); getMapperSchema(query, temp_ontology, clsToCheck, this.schemaDescriptions.get(clsToCheck.getIRI())); add_owlclass_to_openapi(query, pathGenerator, temp_ontology, classPrefixIRI, clsToCheck, false); @@ -197,11 +188,9 @@ private List add_owlclass_to_openapi(Query query, Path pathGenerator, logger.info("The class " + ref_class + " exists "); } else { for (OWLOntology temp_ontology : this.ontologies) { - if ( follow_references ) { + if (this.config_data.getConfigFlagValue(CONFIG_FLAG.FOLLOW_REFERENCES)) { this.mappedClasses.add(ref_class); getMapperSchema(query, temp_ontology, ref_class,this.schemaDescriptions.get(ref_class.getIRI())); -// OWLDocumentFormat format = ontology.getFormat(); -// String temp_defaultOntologyPrefixIRI = format.asPrefixOWLDocumentFormat().getDefaultPrefix(); add_owlclass_to_openapi(query, pathGenerator, temp_ontology, classPrefixIRI, ref_class, false); } } @@ -219,7 +208,7 @@ private List add_owlclass_to_openapi(Query query, Path pathGenerator, private MapperSchema getMapperSchema(Query query, OWLOntology ontology, OWLClass cls, String cls_description) { //Convert from OWL Class to OpenAPI Schema. - MapperSchema mapperSchema = new MapperSchema(this.ontologies, cls, cls_description, schemaNames, ontology, this.follow_references, this.default_descriptions, this.default_properties); + MapperSchema mapperSchema = new MapperSchema(this.ontologies, cls, cls_description, schemaNames, ontology, this.config_data.getConfigFlags()); //Write queries query.write_readme(mapperSchema.name); //Create the OpenAPI schema @@ -228,7 +217,7 @@ private MapperSchema getMapperSchema(Query query, OWLOntology ontology, OWLClass return mapperSchema; } - private void addOpenAPIPaths(Path pathGenerator, MapperSchema mapperSchema, OWLClass cls) { + private void addOpenAPIPaths(PathGenerator pathGenerator, MapperSchema mapperSchema, OWLClass cls) { if (selected_classes != null && !selected_classes.contains(cls)) { logger.info("Ignoring class " + cls.toString()); } else { @@ -251,11 +240,11 @@ private void setSchemaNames(Set classes) { private void setSchemaDrescriptions(Set classes, OWLOntology ontology){ for (OWLClass cls: classes) { System.out.println(cls); - schemaDescriptions.put(cls.getIRI(), ObaUtils.getDescription(cls, ontology, this.default_descriptions)); + schemaDescriptions.put(cls.getIRI(), ObaUtils.getDescription(cls, ontology, this.config_data.getConfigFlagValue(CONFIG_FLAG.DEFAULT_DESCRIPTIONS))); } } - private void add_path(Path pathGenerator, MapperSchema mapperSchema) { + private void add_path(PathGenerator pathGenerator, MapperSchema mapperSchema) { String singular_name = "/" + mapperSchema.name.toLowerCase() + "s/{id}"; String plural_name = "/" + mapperSchema.name.toLowerCase() + "s"; //Create the plural paths: for example: /models/ diff --git a/src/main/java/edu/isi/oba/MapperSchema.java b/src/main/java/edu/isi/oba/MapperSchema.java index 3684f1e..42d1bfe 100644 --- a/src/main/java/edu/isi/oba/MapperSchema.java +++ b/src/main/java/edu/isi/oba/MapperSchema.java @@ -1,5 +1,6 @@ package edu.isi.oba; +import edu.isi.oba.config.CONFIG_FLAG; import static edu.isi.oba.Oba.logger; import io.swagger.v3.oas.models.examples.Example; @@ -8,7 +9,6 @@ import java.util.*; -import org.openapitools.codegen.examples.ExampleGenerator; import org.semanticweb.owlapi.apibinding.OWLManager; import org.semanticweb.owlapi.model.*; import org.semanticweb.owlapi.reasoner.OWLReasoner; @@ -35,9 +35,8 @@ class MapperSchema { private OWLOntology ontology_cls; private OWLReasonerFactory reasonerFactory; public List properties_range; - private boolean follow_references; - private Boolean default_descriptions; - private Boolean default_properties; + + private final Map configFlags = new HashMap<>(); public List propertiesFromObjectRestrictions; public Map> propertiesFromObjectRestrictions_ranges; @@ -62,11 +61,9 @@ public Schema getSchema() { return this.schema; } - public MapperSchema(List ontologies, OWLClass cls, String clsDescription, Map schemaNames, OWLOntology class_ontology, Boolean follow_references, Boolean default_descriptions, Boolean default_properties) { + public MapperSchema(List ontologies, OWLClass cls, String clsDescription, Map schemaNames, OWLOntology class_ontology, Map configFlags) { this.schemaNames = schemaNames; - this.follow_references = follow_references; - this.default_descriptions = default_descriptions; - this.default_properties = default_properties; + this.configFlags.putAll(configFlags); this.cls = cls; this.cls_description = clsDescription; this.type = "object"; @@ -255,7 +252,7 @@ private Map getDataProperties() { } List propertyRanges = getCodeGenTypesByRangeData(ranges, odp); - String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.default_descriptions); + String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS)); MapperDataProperty mapperProperty = new MapperDataProperty(propertyName, propertyDescription, isFunctional, restrictionValues, valuesFromDataRestrictions_ranges, propertyRanges, array, nullable); try { this.properties.put(mapperProperty.name, mapperProperty.getSchemaByDataProperty()); @@ -267,7 +264,7 @@ private Map getDataProperties() { } } - if (this.default_properties) { + if (this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS)) { properties.putAll(this.getDefaultProperties()); } @@ -364,7 +361,7 @@ private Map getObjectProperties() { String propertyURI = odp.getIRI().toString(); propertyNameURI.put(propertyURI, propertyName); - List propertyRanges = getCodeGenTypesByRangeObject(ranges, odp, owlThing, this.follow_references); + List propertyRanges = getCodeGenTypesByRangeObject(ranges, odp, owlThing); Map restrictionValues = new HashMap() ; for (OWLOntology ontology: this.ontologies) { @@ -383,7 +380,7 @@ private Map getObjectProperties() { propertyRanges.clear(); } - String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.default_descriptions); + String propertyDescription = ObaUtils.getDescription(odp, this.ontology_cls, this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS)); MapperObjectProperty mapperObjectProperty = new MapperObjectProperty(propertyName, propertyDescription, isFunctional, restrictionValues, propertyRanges); try { this.properties.put(mapperObjectProperty.name, mapperObjectProperty.getSchemaByObjectProperty()); @@ -421,10 +418,9 @@ private List getCodeGenTypesByRangeData(Set r * @param ranges Represents a ObjectPropertyRange * @param odp Represents a OWLObjectProperty * @param owlThing - * @param follow_references * @return A list with the properties */ - private List getCodeGenTypesByRangeObject(Set ranges, OWLObjectProperty odp, OWLClass owlThing, boolean follow_references) { + private List getCodeGenTypesByRangeObject(Set ranges, OWLObjectProperty odp, OWLClass owlThing) { List objectProperty = new ArrayList<>(); for (OWLObjectPropertyRangeAxiom propertyRangeAxiom : ranges) { @@ -436,7 +432,7 @@ private List getCodeGenTypesByRangeObject(Set rangesOP = this.propertiesFromObjectRestrictions_ranges.get(this.sfp.getShortForm(op.getIRI())); for (String j : restrictionsValuesFromClass.keySet()) { @@ -512,7 +508,7 @@ private void getClassRestrictions(OWLClass analyzedClass) { for (OWLDataProperty dp: this.propertiesFromDataRestrictions) { List valuesFromDataRestrictions_ranges = new ArrayList<>(); - String propertyDescription = ObaUtils.getDescription(dp, this.ontology_cls, this.default_descriptions); + String propertyDescription = ObaUtils.getDescription(dp, this.ontology_cls, this.configFlags.get(CONFIG_FLAG.DEFAULT_DESCRIPTIONS)); if (!this.propertiesFromDataRestrictions_ranges.isEmpty()) { List rangesDP = this.propertiesFromDataRestrictions_ranges.get(this.sfp.getShortForm(dp.getIRI())); for (String j: restrictionsValuesFromClass.keySet()) { @@ -537,7 +533,7 @@ private void getClassRestrictions(OWLClass analyzedClass) { } } - if (this.default_properties) { + if (this.configFlags.get(CONFIG_FLAG.DEFAULT_PROPERTIES)) { this.properties.putAll(this.getDefaultProperties()); } } diff --git a/src/test/java/edu/isi/oba/MapperTest.java b/src/test/java/edu/isi/oba/MapperTest.java index 2236ada..62c01e7 100644 --- a/src/test/java/edu/isi/oba/MapperTest.java +++ b/src/test/java/edu/isi/oba/MapperTest.java @@ -2,6 +2,7 @@ import static edu.isi.oba.ObaUtils.get_yaml_data; import edu.isi.oba.config.AuthConfig; +import edu.isi.oba.config.CONFIG_FLAG; import edu.isi.oba.config.YamlConfig; import java.io.File; @@ -10,6 +11,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.LogManager; @@ -18,7 +20,6 @@ import io.swagger.v3.oas.models.media.Schema; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.semanticweb.owlapi.model.OWLClass; @@ -113,7 +114,7 @@ public void testComplexOntology() throws Exception{ Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://businessontology.com/ontology/Person"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), Map.ofEntries(Map.entry(CONFIG_FLAG.DEFAULT_DESCRIPTIONS, true), Map.entry(CONFIG_FLAG.DEFAULT_PROPERTIES, true), Map.entry(CONFIG_FLAG.FOLLOW_REFERENCES, true))); Schema schema = mapperSchema.getSchema(); // The person schema must not be null. Assertions.assertNotNull(schema); diff --git a/src/test/java/edu/isi/oba/ObaUtilsTest.java b/src/test/java/edu/isi/oba/ObaUtilsTest.java index ccb34ea..c32f380 100644 --- a/src/test/java/edu/isi/oba/ObaUtilsTest.java +++ b/src/test/java/edu/isi/oba/ObaUtilsTest.java @@ -9,13 +9,11 @@ import org.json.JSONObject; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.semanticweb.owlapi.model.OWLClass; import org.semanticweb.owlapi.model.OWLOntologyCreationException; -@Disabled public class ObaUtilsTest { @Test diff --git a/src/test/java/edu/isi/oba/RestrictionsTest.java b/src/test/java/edu/isi/oba/RestrictionsTest.java index 0ce6dc6..ee63783 100644 --- a/src/test/java/edu/isi/oba/RestrictionsTest.java +++ b/src/test/java/edu/isi/oba/RestrictionsTest.java @@ -1,12 +1,14 @@ package edu.isi.oba; import static edu.isi.oba.ObaUtils.get_yaml_data; +import edu.isi.oba.config.CONFIG_FLAG; import edu.isi.oba.config.YamlConfig; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.LogManager; @@ -26,6 +28,12 @@ public class RestrictionsTest { static Logger logger = null; + + // Convenience variable so we don't need to retype this for each MapperSchema constructor. + private final Map configFlags = Map.ofEntries( + Map.entry(CONFIG_FLAG.DEFAULT_DESCRIPTIONS, true), + Map.entry(CONFIG_FLAG.DEFAULT_PROPERTIES, true), + Map.entry(CONFIG_FLAG.FOLLOW_REFERENCES, true)); /** * This method allows you to configure the logger variable that is required to print several @@ -56,7 +64,7 @@ public void testFunctionalObjectProperty() throws OWLOntologyCreationException, Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#University"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("hasRector"); if (property instanceof io.swagger.v3.oas.models.media.ArraySchema) { @@ -82,7 +90,7 @@ public void testObjectUnionOf() throws OWLOntologyCreationException, Exception { Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#StudyMaterial"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("author"); if (property instanceof ArraySchema) { @@ -116,7 +124,7 @@ public void testObjectIntersectionOf() throws OWLOntologyCreationException, Exce Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Course"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("hasEvaluationMethod"); if (property instanceof ArraySchema) { @@ -148,7 +156,7 @@ public void testSimpleObjectSomeValuesFrom() throws OWLOntologyCreationException Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#University"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("hasDepartment"); if (property instanceof ArraySchema) { @@ -176,7 +184,7 @@ public void testObjectSomeValuesFrom_ComposedByRestriction() throws OWLOntologyC Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Student"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("enrolledIn"); if (property instanceof ArraySchema) { @@ -208,7 +216,7 @@ public void testObjectExactCardinality() throws OWLOntologyCreationException, Ex Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#AmericanStudent"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("hasRecord"); if (property instanceof ArraySchema) { @@ -240,7 +248,7 @@ public void testObjectMinCardinality() throws OWLOntologyCreationException, Exce Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#AmericanStudent"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("takesCourse"); if (property instanceof ArraySchema) { @@ -269,7 +277,7 @@ public void testObjectMaxCardinality() throws OWLOntologyCreationException, Exce Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Course"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("hasStudentEnrolled"); if (property instanceof ArraySchema) { @@ -300,7 +308,7 @@ public void testObjectComplementOf() throws OWLOntologyCreationException, Except Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#ProfessorInOtherDepartment"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); if (schema.getNot()!=null) Assertions.assertEquals(schema.getNot().get$ref(),expectedResult); @@ -324,7 +332,7 @@ public void testObjectHasValue() throws OWLOntologyCreationException, Exception Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#ProfessorInArtificialIntelligence"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("belongsTo"); if (((ObjectSchema) property).getDefault()!=null) @@ -351,7 +359,7 @@ public void testObjectOneOf() throws OWLOntologyCreationException, Exception { Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Professor"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("hasDegree"); @@ -385,7 +393,7 @@ public void testFunctionalDataProperty() throws OWLOntologyCreationException, Ex Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#AmericanStudent"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("birthDate"); if (property instanceof io.swagger.v3.oas.models.media.ArraySchema) { @@ -412,7 +420,7 @@ public void testDataUnionOf() throws OWLOntologyCreationException, Exception { Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Course"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("ects"); if (property instanceof ArraySchema) { @@ -446,7 +454,7 @@ public void testDataIntersectionOf() throws OWLOntologyCreationException, Except Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#ProfessorInArtificialIntelligence"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("memberOfOtherDepartments"); if (property instanceof ArraySchema) { @@ -478,7 +486,7 @@ public void testDataSomeValuesFrom() throws OWLOntologyCreationException, Except Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#StudyProgram"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("studyProgramName"); if (property instanceof ArraySchema) { @@ -506,7 +514,7 @@ public void testDataSomeValuesFrom_ComposedByRestriction() throws OWLOntologyCre Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#ProfessorInArtificialIntelligence"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("memberOfOtherDepartments"); if (property instanceof ArraySchema) { @@ -538,7 +546,7 @@ public void testDataAllValuesFrom() throws OWLOntologyCreationException, Excepti Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#StudyProgram"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("studyProgramName"); if (property instanceof ArraySchema) { @@ -563,7 +571,7 @@ public void testDataOneOf() throws OWLOntologyCreationException, Exception { Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Person"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("gender"); if (property instanceof ArraySchema) { @@ -596,7 +604,7 @@ public void testDataHasValue() throws OWLOntologyCreationException, Exception { Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#AmericanStudent"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("nationality"); @@ -621,7 +629,7 @@ public void testDataExactCardinality() throws OWLOntologyCreationException,Excep Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#University"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("universityName"); Integer maxItems = ((ArraySchema) property).getItems().getMaxItems(); @@ -650,7 +658,7 @@ public void testDataMinCardinality() throws OWLOntologyCreationException, Except Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Professor"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("researchField"); Integer minItems = ((ArraySchema) property).getItems().getMinItems(); @@ -676,7 +684,7 @@ public void testDataMaxCardinality() throws OWLOntologyCreationException, Except Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Person"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("address"); Integer maxItems = ((ArraySchema) property).getItems().getMaxItems(); @@ -702,7 +710,7 @@ public void testDataComplementOf() throws OWLOntologyCreationException,Exception Mapper mapper = new Mapper(config_data); OWLClass cls = mapper.manager.getOWLDataFactory().getOWLClass("https://w3id.org/example#Department"); String desc = ObaUtils.getDescription(cls, mapper.ontologies.get(0), true); - MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), true, true, true); + MapperSchema mapperSchema = new MapperSchema(mapper.ontologies, cls, desc, mapper.schemaNames, mapper.ontologies.get(0), this.configFlags); Schema schema = mapperSchema.getSchema(); Object property= schema.getProperties().get("numberOfProfessors"); if (((ArraySchema) property).getItems().getNot()!=null) From d54e3cd871f65625c6b16be2c59e813ca5b56faf Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 12:58:28 -0500 Subject: [PATCH 7/8] bump as patch version Mostly refactoring. Added PATCH placeholder and a new ALWAYS_GENERATE_ARRAYS flag to be used soon. This is basically a patch without any functionality changes. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0098c2e..2975a76 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ jar edu.isi.oba oba - 3.8.0 + 3.8.1 core https://github.com/KnowledgeCaptureAndDiscovery/OBA From 8b0da604e3aba48d051386fac99af8c0835c2d0c Mon Sep 17 00:00:00 2001 From: Christopher Weedall <5010253+cweedall@users.noreply.github.com> Date: Wed, 1 May 2024 13:24:51 -0500 Subject: [PATCH 8/8] add PATCH getter/setter --- src/main/java/edu/isi/oba/config/YamlConfig.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/edu/isi/oba/config/YamlConfig.java b/src/main/java/edu/isi/oba/config/YamlConfig.java index 98530a4..56052d6 100644 --- a/src/main/java/edu/isi/oba/config/YamlConfig.java +++ b/src/main/java/edu/isi/oba/config/YamlConfig.java @@ -44,6 +44,14 @@ public void setEnable_get_paths(Boolean enable_get_paths) { this.configFlags.put(CONFIG_FLAG.PATH_GET, enable_get_paths); } + public Boolean getEnable_patch_paths() { + return this.configFlags.get(CONFIG_FLAG.PATH_PATCH); + } + + public void setEnable_patch_paths(Boolean enable_patch_paths) { + this.configFlags.put(CONFIG_FLAG.PATH_PATCH, enable_patch_paths); + } + public Boolean getEnable_post_paths() { return this.configFlags.get(CONFIG_FLAG.PATH_POST); }