Skip to content

Commit

Permalink
fix: updating model catalog example
Browse files Browse the repository at this point in the history
  • Loading branch information
mosoriob committed Jun 10, 2020
1 parent 301461d commit 91c01dd
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/modelcatalog/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ firebase:

endpoint:
url: http://endpoint.mint.isi.edu/modelCatalog-1.4.0
prefix: https://w3id.org/okn/i/masd
prefix: https://w3id.org/okn/i/mint
graph_base: http://endpoint.mint.isi.edu/modelCatalog-1.4.0/data/

custom_queries_directory: examples/modelcatalog/custom_queries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ WHERE {
?region ?region_p ?region_o .
OPTIONAL {
?region_o ?sub_region_p ?sub_region_o
FILTER (?sub_region_p != <https://w3id.org/okn/o/sdm#geo>) .

}
FILTER (?region_p != <https://w3id.org/okn/o/sdm#geo>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

CONSTRUCT {
?setup ?predicate ?prop .
?prop a ?type
?prop a ?type .
?region ?region_p ?region_o .
?region_o ?sub_region_p ?sub_region_o .
}
WHERE {
GRAPH ?_g_iri {
Expand All @@ -28,9 +30,20 @@ WHERE {
FILTER REGEX(?variableLabel, ?_label, "i")
}
}
?setup ?predicate ?prop
OPTIONAL {
?prop a ?type
{
?setup ?predicate ?prop
OPTIONAL {
?prop a ?type
}
}
UNION {
?setup sdm:hasRegion ?region .
?region ?region_p ?region_o .
FILTER (?region_p != <https://w3id.org/okn/o/sdm#geo>) .
OPTIONAL {
?region_o ?sub_region_p ?sub_region_o .
FILTER (?sub_region_p != <https://w3id.org/okn/o/sdm#geo>)
}
}
}
}
5 changes: 2 additions & 3 deletions src/main/java/edu/isi/oba/Mapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ private void add_user_path(Path pathGenerator) {
userProperties.put("password", password);

Schema userSchema = new Schema();
userSchema.setName("ObaUser");
userSchema.setName("User");
userSchema.setType("object");
userSchema.setProperties(userProperties);
userSchema.setXml(new XML().name("User"));
schemas.put("User", userSchema);

this.paths.addPathItem("/user/login", pathGenerator.user_login(userSchema));
this.paths.addPathItem("/user/login", pathGenerator.user_login(userSchema.getName()));
}

private List<OWLClass> add_owlclass_to_openapi(Query query, Path pathGenerator, OWLOntology ontology,
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/edu/isi/oba/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ public PathItem generate_plural(String schemaName, String schemaURI){
}


public PathItem user_login(Schema schema) {
List<Parameter> parameters = new ArrayList<>();
public PathItem user_login(String schema_name) {
ApiResponses apiResponses = new ApiResponses();

final RequestBody requestBody = new RequestBody();

String ref_text = "#/components/schemas/" + schema_name;
Schema schema = new Schema().$ref(ref_text);

MediaType mediaType = new MediaType().schema(schema);
Content content = new Content().addMediaType("application/json", mediaType);
requestBody.setContent(content);
Expand All @@ -84,11 +86,10 @@ public PathItem user_login(Schema schema) {
.content(new Content().addMediaType("application/json", new MediaType().schema(new StringSchema()))));

Map<String,Object> extensions = new HashMap<String, Object>();
extensions.put("x-openapi-router-controller", "openapi_server.controllers.default_controller");
extensions.put("x-openapi-router-controller", "openapi_server.controllers.user_controller");
Operation operation = new Operation()
.description("Login the user")
.extensions(extensions)
.operationId("user_login_get")
.requestBody(requestBody)
.responses(apiResponses);
return new PathItem().post(operation);
Expand Down
Binary file modified src/main/resources/servers.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import json
import requests
from werkzeug.exceptions import Unauthorized

import connexion
from openapi_server.settings import FIREBASE_KEY
from openapi_server.models.user import User

JWT_ISSUER = 'com.zalando.connexion'
JWT_SECRET = 'change_this'
JWT_LIFETIME_SECONDS = 60000000
Expand Down Expand Up @@ -39,7 +41,7 @@ def auth_with_password(email, password):

return response.ok

def user_login_get(username, password): # noqa: E501
def user_login_post(): # noqa: E501
"""Logs user into the system
# noqa: E501
Expand All @@ -51,7 +53,9 @@ def user_login_get(username, password): # noqa: E501
:rtype: str
"""
if not auth_with_password(username, password):
if connexion.request.is_json:
user = User.from_dict(connexion.request.get_json()) # noqa: E501
if not auth_with_password(user.username, user.password):
return "Invalid User or Password", 401, {}


Expand All @@ -60,16 +64,14 @@ def user_login_get(username, password): # noqa: E501
"iss": JWT_ISSUER,
"iat": int(timestamp),
"exp": int(timestamp + JWT_LIFETIME_SECONDS),
"sub": str(username),
"sub": str(user.username),
}

access_token = jwt.encode(payload, JWT_SECRET, algorithm=JWT_ALGORITHM)
return {
"access_token": access_token,
"token_type": "bearer",
"expires_in": JWT_LIFETIME_SECONDS,
"refresh_token": "IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk",
"scope": "create"
}, 200, {'X-Expires-After': JWT_LIFETIME_SECONDS, 'X-Rate-Limit': 1000}


"access_token": access_token,
"token_type": "bearer",
"expires_in": JWT_LIFETIME_SECONDS,
"refresh_token": "IwOGYzYTlmM2YxOTQ5MGE3YmNmMDFkNTVk",
"scope": "create"
}, 200, {'X-Expires-After': JWT_LIFETIME_SECONDS, 'X-Rate-Limit': 1000}

0 comments on commit 91c01dd

Please sign in to comment.