Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24.07.25 #339

Merged
merged 4 commits into from
Jul 25, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add API endpoint for basic comaprison
Changes to be committed:
	modified:   biocompute/apis.py
	modified:   biocompute/urls.py
	modified:   requirements.txt
HadleyKing committed Jul 25, 2024
commit 945744a2b92e721fa11478b1264d248724e5242c
88 changes: 86 additions & 2 deletions biocompute/apis.py
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@
bulk_response_constructor,
response_status,
)
from deepdiff import DeepDiff
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from django.conf import settings
@@ -34,7 +35,7 @@
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.response import Response
from tests.fixtures.testing_bcos import BCO_000001_DRAFT
from tests.fixtures.testing_bcos import BCO_000001_DRAFT, BCO_000000_DRAFT

hostname = settings.PUBLIC_HOSTNAME
BASE_DIR = settings.BASE_DIR
@@ -198,7 +199,7 @@ class PublishBcoApi(APIView):
"""

permission_classes = [IsAuthenticated]
# swagger_schema = None
swagger_schema = None
#TODO: Add Swaggar docs
# schema = jsonref.load_uri(
# f"file://{BASE_DIR}/config/IEEE/2791object.json"
@@ -860,3 +861,86 @@ def get(self, request, bco_accession, bco_version):

bco_counter_increment(bco_instance)
return Response(status=status.HTTP_200_OK, data=bco_instance.contents)

class CompareBcoApi(APIView):
"""Bulk Compare BCOs [Bulk Enabled]

--------------------

Bulk operation to compare BCOs.

```JSON
[
{...BCO CONTENTS...},
{...BCO CONTENTS...}
]

"""

authentication_classes = []
permission_classes = [AllowAny]

@swagger_auto_schema(
operation_id="api_bco_compare",
request_body=openapi.Schema(
type=openapi.TYPE_ARRAY,
title="Bulk Compare BCOs",
items=openapi.Schema(
type=openapi.TYPE_ARRAY,
example=[BCO_000000_DRAFT, BCO_000001_DRAFT],
items=openapi.Schema(
type=openapi.TYPE_OBJECT,
required=["contents"],
description="Contents of the BCO.",
)
),
description="Compare one BCO against another.",
),
responses={
200: "All BCO comparisons are successful.",
207: "Some or all BCO comparisons failed. Each object submitted"
" will have it's own response object with it's own status"
" message:\n",
400: "Bad request."
},
tags=["BCO Management"],
)
def post(self, request):
validator = BcoValidator()
response_data = []
rejected_requests = False
accepted_requests = True
data = request.data

for index, comparison in enumerate(data):
new_bco, old_bco = comparison
identifier = new_bco["object_id"]+ " vs " + old_bco["object_id"]

# new_results = validator.parse_and_validate(bco=new_bco)
# old_results = validator.parse_and_validate(bco=old_bco)
# import pdb; pdb.set_trace()
# new_identifier, new_results = new_results.popitem()
# old_identifier, old_results = bco_results.popitem()

# if results["number_of_errors"] > 0:
# rejected_requests = True
# bco_status = "FAILED"
# status_code = 400
# message = "BCO not valid"

# else:
# accepted_requests = True
# bco_status = "SUCCESS"
# status_code = 200
# message = "BCO valid"

response_data.append(bulk_response_constructor(
identifier = identifier,
status="SUCCESS",
code=200,
# message=message,
data=DeepDiff(new_bco, old_bco).to_json()
))

status_code = response_status(accepted_requests, rejected_requests)
return Response(status=status_code, data=response_data)
2 changes: 2 additions & 0 deletions biocompute/urls.py
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
DraftsPublishApi,
PublishBcoApi,
ValidateBcoApi,
CompareBcoApi,
)

urlpatterns = [
@@ -17,4 +18,5 @@
path("objects/drafts/publish/", DraftsPublishApi.as_view()),
path("objects/validate/", ValidateBcoApi.as_view()),
path("objects/publish/", PublishBcoApi.as_view()),
path("objects/compare/", CompareBcoApi.as_view()),
]
13 changes: 10 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
appdirs==1.4.3
asgiref==3.3.4
astroid==2.9.3
attrs==20.3.0
attrs==23.2.0
black==22.6.0
CacheControl==0.12.6
cachetools==5.3.0
@@ -11,18 +11,20 @@ chardet==3.0.4
charset-normalizer==2.0.7
click==8.1.3
colorama==0.4.3
configparser==5.3.0
contextlib2==0.6.0
coreapi==2.3.3
coreschema==0.0.4
coverage==6.3.2
cryptography==39.0.0
deepdiff==7.0.1
distlib==0.3.0
distro==1.4.0
Django==3.2.13
django-cors-headers==3.7.0
django-guardian==2.3.0
django-reset-migrations==0.4.0
django-rest-framework==0.1.0
django-rest-passwordreset==1.3.0
django-rest-swagger==2.2.0
djangorestframework==3.12.2
djangorestframework-api-key==2.0.0
@@ -42,20 +44,23 @@ isort==5.10.1
itypes==1.2.0
Jinja2==3.0.1
jsonref==0.2
jsonschema==3.2.0
jsonschema==4.20.0
jsonschema-specifications==2023.12.1
lazy-object-proxy==1.7.1
lockfile==0.12.2
MarkupSafe==2.0.1
mccabe==0.6.1
msgpack==0.6.2
mypy-extensions==0.4.3
openapi-codec==1.3.2
ordered-set==4.1.0
packaging==20.3
pathspec==0.9.0
pep517==0.8.2
platformdirs==2.5.1
pluggy==1.2.0
progress==1.5
psycopg2==2.9.5
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
@@ -71,8 +76,10 @@ python-dateutil==2.8.1
pytoml==0.1.21
pytz==2020.4
PyYAML==6.0
referencing==0.32.0
requests==2.26.0
retrying==1.3.3
rpds-py==0.16.2
rsa==4.9
ruamel.yaml==0.17.16
ruamel.yaml.clib==0.2.6