Skip to content

Commit 4efc685

Browse files
committed
Add API endpoint for basic comaprison
Changes to be committed: modified: biocompute/apis.py modified: biocompute/urls.py modified: requirements.txt
1 parent d671416 commit 4efc685

File tree

3 files changed

+98
-5
lines changed

3 files changed

+98
-5
lines changed

biocompute/apis.py

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
bulk_response_constructor,
2626
response_status,
2727
)
28+
from deepdiff import DeepDiff
2829
from drf_yasg import openapi
2930
from drf_yasg.utils import swagger_auto_schema
3031
from django.conf import settings
@@ -34,7 +35,7 @@
3435
from rest_framework.views import APIView
3536
from rest_framework.permissions import IsAuthenticated, AllowAny
3637
from rest_framework.response import Response
37-
from tests.fixtures.testing_bcos import BCO_000001_DRAFT
38+
from tests.fixtures.testing_bcos import BCO_000001_DRAFT, BCO_000000_DRAFT
3839

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

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

861862
bco_counter_increment(bco_instance)
862863
return Response(status=status.HTTP_200_OK, data=bco_instance.contents)
864+
865+
class CompareBcoApi(APIView):
866+
"""Bulk Compare BCOs [Bulk Enabled]
867+
868+
--------------------
869+
870+
Bulk operation to compare BCOs.
871+
872+
```JSON
873+
[
874+
{...BCO CONTENTS...},
875+
{...BCO CONTENTS...}
876+
]
877+
878+
"""
879+
880+
authentication_classes = []
881+
permission_classes = [AllowAny]
882+
883+
@swagger_auto_schema(
884+
operation_id="api_bco_compare",
885+
request_body=openapi.Schema(
886+
type=openapi.TYPE_ARRAY,
887+
title="Bulk Compare BCOs",
888+
items=openapi.Schema(
889+
type=openapi.TYPE_ARRAY,
890+
example=[BCO_000000_DRAFT, BCO_000001_DRAFT],
891+
items=openapi.Schema(
892+
type=openapi.TYPE_OBJECT,
893+
required=["contents"],
894+
description="Contents of the BCO.",
895+
)
896+
),
897+
description="Compare one BCO against another.",
898+
),
899+
responses={
900+
200: "All BCO comparisons are successful.",
901+
207: "Some or all BCO comparisons failed. Each object submitted"
902+
" will have it's own response object with it's own status"
903+
" message:\n",
904+
400: "Bad request."
905+
},
906+
tags=["BCO Management"],
907+
)
908+
def post(self, request):
909+
validator = BcoValidator()
910+
response_data = []
911+
rejected_requests = False
912+
accepted_requests = True
913+
data = request.data
914+
915+
for index, comparison in enumerate(data):
916+
new_bco, old_bco = comparison
917+
identifier = new_bco["object_id"]+ " vs " + old_bco["object_id"]
918+
919+
# new_results = validator.parse_and_validate(bco=new_bco)
920+
# old_results = validator.parse_and_validate(bco=old_bco)
921+
# import pdb; pdb.set_trace()
922+
# new_identifier, new_results = new_results.popitem()
923+
# old_identifier, old_results = bco_results.popitem()
924+
925+
# if results["number_of_errors"] > 0:
926+
# rejected_requests = True
927+
# bco_status = "FAILED"
928+
# status_code = 400
929+
# message = "BCO not valid"
930+
931+
# else:
932+
# accepted_requests = True
933+
# bco_status = "SUCCESS"
934+
# status_code = 200
935+
# message = "BCO valid"
936+
937+
response_data.append(bulk_response_constructor(
938+
identifier = identifier,
939+
status="SUCCESS",
940+
code=200,
941+
# message=message,
942+
data=DeepDiff(new_bco, old_bco).to_json()
943+
))
944+
945+
status_code = response_status(accepted_requests, rejected_requests)
946+
return Response(status=status_code, data=response_data)

biocompute/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DraftsPublishApi,
1010
PublishBcoApi,
1111
ValidateBcoApi,
12+
CompareBcoApi,
1213
)
1314

1415
urlpatterns = [
@@ -17,4 +18,5 @@
1718
path("objects/drafts/publish/", DraftsPublishApi.as_view()),
1819
path("objects/validate/", ValidateBcoApi.as_view()),
1920
path("objects/publish/", PublishBcoApi.as_view()),
21+
path("objects/compare/", CompareBcoApi.as_view()),
2022
]

requirements.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
appdirs==1.4.3
22
asgiref==3.3.4
33
astroid==2.9.3
4-
attrs==20.3.0
4+
attrs==23.2.0
55
black==22.6.0
66
CacheControl==0.12.6
77
cachetools==5.3.0
@@ -11,18 +11,20 @@ chardet==3.0.4
1111
charset-normalizer==2.0.7
1212
click==8.1.3
1313
colorama==0.4.3
14+
configparser==5.3.0
1415
contextlib2==0.6.0
1516
coreapi==2.3.3
1617
coreschema==0.0.4
1718
coverage==6.3.2
1819
cryptography==39.0.0
20+
deepdiff==7.0.1
1921
distlib==0.3.0
2022
distro==1.4.0
2123
Django==3.2.13
2224
django-cors-headers==3.7.0
23-
django-guardian==2.3.0
2425
django-reset-migrations==0.4.0
2526
django-rest-framework==0.1.0
27+
django-rest-passwordreset==1.3.0
2628
django-rest-swagger==2.2.0
2729
djangorestframework==3.12.2
2830
djangorestframework-api-key==2.0.0
@@ -42,20 +44,23 @@ isort==5.10.1
4244
itypes==1.2.0
4345
Jinja2==3.0.1
4446
jsonref==0.2
45-
jsonschema==3.2.0
47+
jsonschema==4.20.0
48+
jsonschema-specifications==2023.12.1
4649
lazy-object-proxy==1.7.1
4750
lockfile==0.12.2
4851
MarkupSafe==2.0.1
4952
mccabe==0.6.1
5053
msgpack==0.6.2
5154
mypy-extensions==0.4.3
5255
openapi-codec==1.3.2
56+
ordered-set==4.1.0
5357
packaging==20.3
5458
pathspec==0.9.0
5559
pep517==0.8.2
5660
platformdirs==2.5.1
5761
pluggy==1.2.0
5862
progress==1.5
63+
psycopg2==2.9.5
5964
pyasn1==0.4.8
6065
pyasn1-modules==0.2.8
6166
pycparser==2.21
@@ -71,8 +76,10 @@ python-dateutil==2.8.1
7176
pytoml==0.1.21
7277
pytz==2020.4
7378
PyYAML==6.0
79+
referencing==0.32.0
7480
requests==2.26.0
7581
retrying==1.3.3
82+
rpds-py==0.16.2
7683
rsa==4.9
7784
ruamel.yaml==0.17.16
7885
ruamel.yaml.clib==0.2.6

0 commit comments

Comments
 (0)