Skip to content

Commit

Permalink
Merge pull request #623 from plantbreeding/data-model-separation
Browse files Browse the repository at this point in the history
Data model separation
  • Loading branch information
daveneti authored Jan 17, 2025
2 parents 0f0159b + 3cb6676 commit 6baa01f
Show file tree
Hide file tree
Showing 38 changed files with 755 additions and 82 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/generate-schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Java CI with Gradle

on:
push:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'
- name: Change wrapper permissions
working-directory: ./generator/
run: chmod +x ./gradlew
- name: Build with Gradle Wrapper
working-directory: ./generator/
run: ./gradlew validate
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
.DS_Store
.settings/
.idea
.vscode/
.idea

/_temp
brapi_blueprint.apib
Expand Down
35 changes: 35 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
# golang: "1.20"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py
# You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
# builder: "dirhtml"
# Fail on all warnings to avoid broken references
fail_on_warning: true

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
2 changes: 1 addition & 1 deletion Scripts/buildReadMes.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def buildTitleStr(path, method, params = [], deprecated = False):
uniquePathStr = ' /brapi/v2' + path
for param in params:
if param['in'] == 'query' :
uniquePathStr += '{?' + param['name'] + '}'
uniquePathStr += '{?' + param['name'] + '}'

if uniquePathStr in uniquePaths:
uniquePathStr += '/'
Expand Down
126 changes: 126 additions & 0 deletions Scripts/oauth_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

import requests
import webbrowser
from threading import Lock
from fastapi import FastAPI
import uvicorn
from pyoauth2.client import OAuth2AuthorizationFlow, FileStorage, OAuth2APIRequest
import contextlib
import time
import threading
import uvicorn

class Server(uvicorn.Server):
def install_signal_handlers(self):
pass

@contextlib.contextmanager
def run_in_thread(self):
thread = threading.Thread(target=self.run)
thread.start()
try:
while not self.started:
time.sleep(1e-3)
yield
finally:
self.should_exit = True
thread.join()

class BrAPIRequest(OAuth2APIRequest):
def __init__(self, access_token):
OAuth2APIRequest.__init__(self, access_token)
self.authorization_header = {"Authorization": "Bearer %s" % self.access_token}

code_lock = Lock()
code_val = {"code": ""}

async def root(code: str):
code_val["code"] = code
code_lock.release()

async def lifespan_func(app: FastAPI):
code_lock.acquire()
print("temp server start")
yield
print("temp server shutdown")

def redirect_function(url):
print("hello?")
app = FastAPI(lifespan=lifespan_func)
app.add_api_route("/login/redirect", root)

config = uvicorn.Config(app=app, host="127.0.0.1", port=8000, log_level="info")
server = Server(config=config)
with server.run_in_thread():
webbrowser.open_new_tab(url)
with code_lock:
print(code_val["code"] )

return code_val["code"]


def retrieve_authorization_code(required_params,
extra_auth_params,
extra_token_params, redirect_func=None):
""" retrieve authorization code to get access token
"""

request_param = {
"client_id": required_params['client_id'],
"redirect_uri": required_params['redirect_uri'],
'scope' : required_params['scope']
}

if extra_auth_params:
request_param.update(extra_auth_params)

r = requests.get(required_params['auth_uri'], params=request_param,
allow_redirects=False)
url = r.url
return url

if __name__ == '__main__':

yt_feed_uri = r"https://test-server.brapi.org/brapi/v2/studies"

required_params = {
'client_id': "exampleClient",
'client_secret': "pnosdgBScMmNVc2vpY1cEwBYjsImpAZn",
'auth_uri': "https://auth.brapi.org/realms/brapi/protocol/openid-connect/auth",
'token_uri': "https://test-server.brapi.org/realms/brapi/protocol/openid-connect/token",
'scope': [r'openid profile'],
'redirect_uri': "http://localhost:8000/login/redirect"
}

extra_auth_params = {
'response_type': "code",
'access_type': "offline"
}

extra_token_params = {
'grant_type': "authorization_code",
}

# storage = FileStorage('/example_client.dat')
# credentials = storage.get()
credentials = None
input("proceed?")
if credentials is None:
flow = OAuth2AuthorizationFlow(required_params,
extra_auth_params,
extra_token_params,
False)


code = flow.retrieve_authorization_code(redirect_func=redirect_function)
flow.set_authorization_code(code)
credentials = flow.retrieve_token()
# storage.save(credentials)

access_token = credentials['access_token']

req = BrAPIRequest(access_token)
data = req.request(yt_feed_uri)
print(data)


12 changes: 12 additions & 0 deletions Specification/BrAPI-Genotyping/Plates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Get a filtered list of `Plates`. Each `Plate` is a collection of `Samples` that

<table>
<tr> <th> Field </th> <th> Type </th> <th> Description </th> </tr>
<tr><td><span style="font-weight:bold;">plateDbId</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>The ID which uniquely identifies a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">plateName</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>A human readable name for a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">additionalInfo</span></td><td>object</td><td>A free space containing any additional information related to a particular object. A data source may provide any JSON object, unrestricted by the BrAPI specification.</td></tr>
<tr><td><span style="font-weight:bold;">externalReferences</span></td><td>array[object]</td><td>An array of external reference ids. These are references to this piece of data in an external system. Could be a simple string or a URI.</td></tr>
Expand Down Expand Up @@ -92,6 +93,7 @@ Get a filtered list of `Plates`. Each `Plate` is a collection of `Samples` that
}
],
"plateBarcode": "11223344",
"plateDbId": "a106467f",
"plateFormat": "PLATE_96",
"plateName": "Plate_123_XYZ",
"programDbId": "bd748e00",
Expand Down Expand Up @@ -149,6 +151,7 @@ Submit new Plate entities to the server

<table>
<tr> <th> Field </th> <th> Type </th> <th> Description </th> </tr>
<tr><td><span style="font-weight:bold;">plateDbId</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>The ID which uniquely identifies a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">plateName</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>A human readable name for a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">additionalInfo</span></td><td>object</td><td>A free space containing any additional information related to a particular object. A data source may provide any JSON object, unrestricted by the BrAPI specification.</td></tr>
<tr><td><span style="font-weight:bold;">externalReferences</span></td><td>array[object]</td><td>An array of external reference ids. These are references to this piece of data in an external system. Could be a simple string or a URI.</td></tr>
Expand Down Expand Up @@ -235,6 +238,7 @@ Submit new Plate entities to the server
}
],
"plateBarcode": "11223344",
"plateDbId": "a106467f",
"plateFormat": "PLATE_96",
"plateName": "Plate_123_XYZ",
"programDbId": "bd748e00",
Expand Down Expand Up @@ -280,6 +284,7 @@ Update the details of existing Plates

<table>
<tr> <th> Field </th> <th> Type </th> <th> Description </th> </tr>
<tr><td><span style="font-weight:bold;">plateDbId</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>The ID which uniquely identifies a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">plateName</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>A human readable name for a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">additionalInfo</span></td><td>object</td><td>A free space containing any additional information related to a particular object. A data source may provide any JSON object, unrestricted by the BrAPI specification.</td></tr>
<tr><td><span style="font-weight:bold;">externalReferences</span></td><td>array[object]</td><td>An array of external reference ids. These are references to this piece of data in an external system. Could be a simple string or a URI.</td></tr>
Expand Down Expand Up @@ -368,6 +373,7 @@ Update the details of existing Plates
}
],
"plateBarcode": "11223344",
"plateDbId": "a106467f",
"plateFormat": "PLATE_96",
"plateName": "Plate_123_XYZ",
"programDbId": "bd748e00",
Expand Down Expand Up @@ -413,6 +419,7 @@ Get the details of a specific `Plate`. Each `Plate` is a collection of `Samples`

<table>
<tr> <th> Field </th> <th> Type </th> <th> Description </th> </tr>
<tr><td><span style="font-weight:bold;">plateDbId</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>The ID which uniquely identifies a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">plateName</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>A human readable name for a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">additionalInfo</span></td><td>object</td><td>A free space containing any additional information related to a particular object. A data source may provide any JSON object, unrestricted by the BrAPI specification.</td></tr>
<tr><td><span style="font-weight:bold;">externalReferences</span></td><td>array[object]</td><td>An array of external reference ids. These are references to this piece of data in an external system. Could be a simple string or a URI.</td></tr>
Expand Down Expand Up @@ -471,6 +478,7 @@ Get the details of a specific `Plate`. Each `Plate` is a collection of `Samples`
}
],
"plateBarcode": "11223344",
"plateDbId": "a106467f",
"plateFormat": "PLATE_96",
"plateName": "Plate_123_XYZ",
"programDbId": "bd748e00",
Expand Down Expand Up @@ -544,6 +552,7 @@ Review the <a target="_blank" href="https://wiki.brapi.org/index.php/Search_Serv

<table>
<tr> <th> Field </th> <th> Type </th> <th> Description </th> </tr>
<tr><td><span style="font-weight:bold;">plateDbId</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>The ID which uniquely identifies a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">plateName</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>A human readable name for a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">additionalInfo</span></td><td>object</td><td>A free space containing any additional information related to a particular object. A data source may provide any JSON object, unrestricted by the BrAPI specification.</td></tr>
<tr><td><span style="font-weight:bold;">externalReferences</span></td><td>array[object]</td><td>An array of external reference ids. These are references to this piece of data in an external system. Could be a simple string or a URI.</td></tr>
Expand Down Expand Up @@ -688,6 +697,7 @@ Review the <a target="_blank" href="https://wiki.brapi.org/index.php/Search_Serv
}
],
"plateBarcode": "11223344",
"plateDbId": "a106467f",
"plateFormat": "PLATE_96",
"plateName": "Plate_123_XYZ",
"programDbId": "bd748e00",
Expand Down Expand Up @@ -760,6 +770,7 @@ Review the <a target="_blank" href="https://wiki.brapi.org/index.php/Search_Serv

<table>
<tr> <th> Field </th> <th> Type </th> <th> Description </th> </tr>
<tr><td><span style="font-weight:bold;">plateDbId</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>The ID which uniquely identifies a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">plateName</span></td><td>string<br><span style="font-size: smaller; color: red;">(Required)</span></td><td>A human readable name for a `Plate`</td></tr>
<tr><td><span style="font-weight:bold;">additionalInfo</span></td><td>object</td><td>A free space containing any additional information related to a particular object. A data source may provide any JSON object, unrestricted by the BrAPI specification.</td></tr>
<tr><td><span style="font-weight:bold;">externalReferences</span></td><td>array[object]</td><td>An array of external reference ids. These are references to this piece of data in an external system. Could be a simple string or a URI.</td></tr>
Expand Down Expand Up @@ -822,6 +833,7 @@ Review the <a target="_blank" href="https://wiki.brapi.org/index.php/Search_Serv
}
],
"plateBarcode": "11223344",
"plateDbId": "a106467f",
"plateFormat": "PLATE_96",
"plateName": "Plate_123_XYZ",
"programDbId": "bd748e00",
Expand Down
6 changes: 3 additions & 3 deletions Specification/BrAPI-Genotyping/Plates/Schemas/Plate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ components:
module: BrAPI-Genotyping
title: Plate
description: A Plate represents the metadata for a collection of Samples. The physical Plate being represented might be a plastic tray full of Samples, or a group of Samples stored in individual containers ie bags, test tubes, etc. Whatever the container is, the Samples in a Plate should be related by the same physical space, though they may or may not be related as part of the same experiment or analysis.
required:
- plateDbId
properties:
required:
- plateDbId
properties:
plateDbId:
description: The ID which uniquely identifies a `Plate`
type: string
Expand Down
2 changes: 1 addition & 1 deletion Wiki/Weekly Meeting Notes.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,4 @@ For next week,
http://docs.breeding.apiary.io/, disregarding analysisMethod. Return two
keys: total_markers, missing_values, in JSON
* Lukas will get Rebecca to add us as editors.
* Meet Thursdays at 4pm EDT.
* Meet Thursdays at 4pm EDT.
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
import sphinx_rtd_theme
# import sphinx_rtd_theme
extensions = [
'sphinx_rtd_theme'
'sphinx_rtd_theme'
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -57,4 +57,4 @@
# or fully qualified paths (eg. https://...)
html_css_files = [
'css/custom.css',
]
]
2 changes: 1 addition & 1 deletion docs/docs/best_practices/Alternative_Standards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ In BrAPI V2.1, the `/events` endpoint was made compatible with the International
MCPD
----

Multi-Crop Passport Descriptors (MCPD) "is a widely used international standard to facilitate germplasm passport information exchange" (`bioversityinternational.org <https://www.bioversityinternational.org/e-library/publications/detail/faobioversity-multi-crop-passport-descriptors-v21-mcpd-v21/>`__). In BrAPI, the primary way to share Germplasm data is through the "GET /germplasm" endpoint. This endpoint has 24 fields out of the available 41 MCPD fields. The BrAPI specification also defines the endpoint "GET /germplasm/{germplasmDbId}/mcpd". This alternate endpoint allows a user to access all 41 MCPD compliant data points when looking at a specific germplasm entry.
Multi-Crop Passport Descriptors (MCPD) "is a widely used international standard to facilitate germplasm passport information exchange" (`BioversityInternational.org <https://www.bioversityinternational.org/e-library/publications/detail/faobioversity-multi-crop-passport-descriptors-v21-mcpd-v21/>`__). In BrAPI, the primary way to share Germplasm data is through the "GET /germplasm" endpoint. This endpoint has 24 fields out of the available 41 MCPD fields. The BrAPI specification also defines the endpoint "GET /germplasm/{germplasmDbId}/mcpd". This alternate endpoint allows a user to access all 41 MCPD compliant data points when looking at a specific germplasm entry.

GeoJSON
-------
Expand Down
Loading

0 comments on commit 6baa01f

Please sign in to comment.