Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Feb 28, 2020
2 parents 981231d + 097f3fe commit 857d4c1
Show file tree
Hide file tree
Showing 18 changed files with 240 additions and 185 deletions.
Empty file added docs/advanced.md
Empty file.
41 changes: 0 additions & 41 deletions docs/config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,3 @@ openapi:
- url: https://api.models.mint.isi.edu/v1.3.0
- url: https://dev.api.models.mint.isi.edu/v1.3.0
- url: http://localhost:8080/v1.3.0

firebase:
key:


custom_paths:
/custom/model/index:
get:
description: Gets the details of a single instance of a Model
parameters:
- description: Name of the custom query
in: query
name: custom_query_name
required: false
schema:
default: custom_model_index
type: string
- description: Username to query
in: query
name: username
required: false
schema:
type: string
- description: Label of NumericalIndex
in: query
name: label
required: true
schema:
type: string
responses:
'200':

content:
application/json:
schema:
items:
$ref: '#/components/schemas/Model'
description: Gets the details of a single instance of Model
summary: Get a Model
tags:
- Model
1 change: 0 additions & 1 deletion docs/configuration_file.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ ontologies:
- https://mintproject.github.io/Mint-ModelCatalog-Ontology/release/1.2.0/ontology.xml
- https://knowledgecaptureanddiscovery.github.io/SoftwareDescriptionOntology/release/1.4.0/ontology.xml
```
| Field | Value |
|---|---|
| **Required:** | ``true`` |
Expand Down
26 changes: 2 additions & 24 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,9 @@

## Running

- Create the OBA config file from the [sample configuration](config.yaml.sample)
```
ontologies:
- https://mintproject.github.io/Mint-ModelCatalog-Ontology/release/1.2.0/ontology.xml
- https://knowledgecaptureanddiscovery.github.io/SoftwareDescriptionOntology/release/1.4.0/ontology.xml
name: modelcatalog
output_dir: outputs
openapi:
openapi: 3.0.1
info:
description: This is the API of the Software Description Ontology
at [https://mintproject.github.io/Mint-ModelCatalog-Ontology/release/1.3.0/index-en.html](https://w3id.org/okn/o/sdm)
title: Model Catalog
version: v1.3.0
externalDocs:
description: Model Catalog
url: https://w3id.org/okn/o/sdm
servers:
- url: https://api.models.mint.isi.edu/v1.3.0
- url: https://dev.api.models.mint.isi.edu/v1.3.0
- url: http://localhost:8080/v1.3.0
```
1. Create the OBA config file from the [sample configuration](config.yaml.sample)
2. Pass the configuration and run OBA

- Pass the configuration and run OBA
```bash
$ java -jar oba-2.2.0-jar-with-dependencies.jar -c config.yaml
```
145 changes: 145 additions & 0 deletions docs/server.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Generating the server

OBA uses [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator#overview) to generate the server.

## OpenAPI Generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and
configuration automatically given an OpenAPI Spec (both 2.0 and 3.0 are supported). The OpenAPI Generator website
maintains a list of languages/frameworks are supported.

### Integration with RDF

The OpenAPI Generator easily provide an API backend for mocking based on the OpenAPI Specification. However, it does not
provide the logic of the server (For example, a database connection).

OBA modifies the server generated by OpenAPI Generator using templates. As result, the server can:

1. Connect and query resources from the SPARQL endpoint.
- Convert the RDF triples to JSON (using JSON/LD).
2. Connect and insert resources to the SPARQL endpoint.
- Convert the JSON to RDF triples (using JSON/LD).

## Generating the server

Currently, the following languages/frameworks are supported by OBA:

- Python/flash

### How to generate it?

!!! warning
You must install Docker.

Run the script.

```bash
$ bash generate-server.sh
...
...
SUCCESS
```

#### Structure of the server

The server directory contains the following files and directories

```bash
$ ls server/
Dockerfile: A Dockerfile to build the Docker Images
README.md: A README.md with the instructions to run the server
contexts: The directory with the JSON/LD contests
openapi_server: The server implemenation
queries: The directory with the SPARQL queries
requirements.txt: The Python requirements of the server
test-requirements.txt: The Python requirements of testing the server
```


### Generating the JSON/LD context

Since the adoption of JSON/LD is in progress, OBA can convert the format of the responses from JSON/LD to JSON.
To do that, OBA requires a file with the context. Simply speaking, a context is used to map terms to IRIs.

!!! info
Visit the [JSON/LD documentation](https://json-ld.org/spec/latest/json-ld/#the-context) for more information

Currently, OBA does not support the generation of the context file.
We recommend to use the project [owl2jsonld](https://github.com/stain/owl2jsonld)


#### One ontology

If you are using one only. You can run:

```bash
java -jar owl2jsonld-0.3.0-SNAPSHOT-standalone.jar \
https://mintproject.github.io/Mint-ModelCatalog-Ontology/release/1.2.0/ontology.xml > server/context.json
```

### Two or more ontologies

To merge the multiple JSON files, you can install the [jq](https://stedolan.github.io/jq/)

```bash

java -jar owl2jsonld-0.3.0-SNAPSHOT-standalone.jar \
$ONTOLOGY_URL1 > a.json
java -jar owl2jsonld-0.3.0-SNAPSHOT-standalone.jar \
$ONTOLOGY_URL2 > b.json
jq -s '.[0] * .[1]' a.json b.json | jq -S > server/contexts/context.json
rm a.json b.json

```

For example, the Model Catalog ontology:

```bash

java -jar owl2jsonld-0.3.0-SNAPSHOT-standalone.jar \
https://mintproject.github.io/Mint-ModelCatalog-Ontology/release/1.2.0/ontology.xml > a.json
java -jar owl2jsonld-0.3.0-SNAPSHOT-standalone.jar \
https://knowledgecaptureanddiscovery.github.io/SoftwareDescriptionOntology/release/1.2.0/ontology.xml > b.json
jq -s '.[0] * .[1]' a.json b.json | jq -S > server/contexts/context.json
rm a.json b.json

```

## Running the server

## Running with Docker

To run the server on a Docker container, please execute the following from the root directory:

```bash
# building the image
docker build -t openapi_server .

# starting up a container
docker run -p 8080:8080 openapi_server
```


and open your browser to here:
!!! warning
The version (v1.3.0) depends of your configuration. If you have questions, go to the README.


```
http://localhost:8080/v1.3.0/ui/
```

Your OpenAPI definition lives here:

```
http://localhost:8080/v1.3.0/openapi.json
```

To launch the integration tests, use tox:
```
sudo pip install tox
tox
```

## How to use it?

3 changes: 2 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
site_name: OBA documentation
nav:
- Home: index.md
- Quickstart: quickstart.md
- OBA features: features.md
- Quickstart: quickstart.md
- Generating the server: server.md
- Configuration file: configuration_file.md
theme:
name: material
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<groupId>edu.isi.oba</groupId>
<artifactId>oba</artifactId>
<version>2.2.0</version>

<name>core</name>
<!-- FIXME change it to the project's website -->
<url>https://github.com/KnowledgeCaptureAndDiscovery/OBA</url>
Expand Down
23 changes: 6 additions & 17 deletions src/main/java/edu/isi/oba/Mapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.isi.oba;

import edu.isi.oba.config.OntologyConfig;
import edu.isi.oba.config.RelationConfig;
import edu.isi.oba.config.YamlConfig;
import io.swagger.v3.oas.models.Paths;
Expand All @@ -11,9 +10,8 @@
import org.semanticweb.owlapi.formats.RDFXMLDocumentFormat;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.rdf.rdfxml.renderer.OWLOntologyXMLNamespaceManager;
import org.semanticweb.owlapi.util.DefaultPrefixManager;

import java.io.IOException;
import java.io.File;
import java.util.*;

class Mapper {
Expand All @@ -28,8 +26,8 @@ public Mapper(YamlConfig config_data) throws OWLOntologyCreationException {
List<String> paths = config_data.getPaths();

this.selected_paths = paths;
List<String> config_ontologies = config_data.getOntologies();
Map<String, List<RelationConfig>> relations = config_data.getRelations();
List<String> config_ontologies = config_data.getOntologies();
String destination_dir = config_data.getOutput_dir() + File.separator + config_data.getName();

//Load the ontology into the manager
for (String ontologyURL : config_ontologies) {
Expand All @@ -47,7 +45,7 @@ public Mapper(YamlConfig config_data) throws OWLOntologyCreationException {
//Add schema and paths
for (OWLOntology ontology : this.manager.getOntologies()) {
OWLDocumentFormat format = ontology.getFormat();
this.createSchemas(ontology, relations, format);
this.createSchemas(ontology, format, destination_dir);
}
}

Expand All @@ -56,16 +54,15 @@ public Mapper(YamlConfig config_data) throws OWLOntologyCreationException {
* The schemas includes the properties
*
* @param ontology Represents an OWL 2 ontology
* @param relations
* @param format
* @return schemas
*/
private void createSchemas(OWLOntology ontology, Map<String, List<RelationConfig>> relations, OWLDocumentFormat format) {
private void createSchemas(OWLOntology ontology, OWLDocumentFormat format, String destination_dir) {
String defaultOntologyPrefixIRI = ((RDFXMLDocumentFormat) format).getDefaultPrefix();

Set<OWLClass> classes = ontology.getClassesInSignature();

Query query = new Query();
Query query = new Query(destination_dir);
Path pathGenerator = new Path();
query.get_all(DEFAULT_DIR_QUERY);

Expand All @@ -82,14 +79,6 @@ private void createSchemas(OWLOntology ontology, Map<String, List<RelationConfig
Schema schema = mapperSchema.getSchema();
schemas.put(schema.getName(), schema);


//obtain the relations
// List<RelationConfig> model_relations = relations.get(mapperSchema.name);
// for (RelationConfig model_relation : model_relations){
// add_path_relation(pathGenerator, model_relation.getSubject(), model_relation.getPredicate(), model_relation.getPath());
// }


if (this.selected_paths == null){
add_path(pathGenerator, mapperSchema);
} else {
Expand Down
26 changes: 2 additions & 24 deletions src/main/java/edu/isi/oba/Oba.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,29 @@ public static void main(String[] args) throws Exception {
logger.setLevel(Level.FINE);
logger.addHandler(new ConsoleHandler());

String resourcesFolder = "oba";

//parse command line
String config_yaml = get_config_yaml(args);
//read the config yaml from command line
YamlConfig config_data = get_yaml_data(config_yaml);
//copy base project
String destination_dir = config_data.getOutput_dir() + File.separator + config_data.getName();

//read ontologies and get schema and paths

Mapper mapper = new Mapper(config_data);
LinkedHashMap<String, PathItem> custom_paths = config_data.getCustom_paths();
OpenAPI openapi_base = config_data.getOpenapi();
ObaUtils.unZipIt(SERVERS_ZIP, destination_dir);
generate_openapi_spec(openapi_base, mapper, destination_dir, custom_paths);
python_copy_base_project(resourcesFolder, destination_dir);

//python_copy_base_project(resourcesFolder, destination_dir);
}


/**
* Copy the base project dir for a python project
* @param base_project_dir
* @param destination_dir
* @throws IOException
*/
private static void python_copy_base_project(String base_project_dir, String destination_dir) throws IOException, URISyntaxException {
ObaUtils.unZipIt(SERVERS_ZIP, destination_dir);
}

private static void generate_openapi_spec(OpenAPI openapi_base, Mapper mapper, String dir, LinkedHashMap<String, PathItem> custom_paths) throws IOException {
String destinationProjectDirectory = dir;
String destinationProjectDirectory = dir + File.separator + "servers" + File.separator + "python";
Path destinationProject = Paths.get(destinationProjectDirectory);
Serializer serializer = new Serializer(mapper, destinationProject, openapi_base, custom_paths);
SerializerPython serializer_python = new SerializerPython(mapper, destinationProject, openapi_base);
}

private static File[] getResourceFolderFiles (String folder) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL url = loader.getResource(folder);
String path = url.getPath();
return new File(path).listFiles();
}


private static YamlConfig get_yaml_data(String config_yaml) {
Constructor constructor = new Constructor(YamlConfig.class);
Expand Down
Loading

0 comments on commit 857d4c1

Please sign in to comment.