Skip to content

Commit

Permalink
24.08.30 (#348)
Browse files Browse the repository at this point in the history
* BCO scoring changes

* Add New Production Deployment md

Changes to be committed:
	deleted:    docs/bco_scores.json
	modified:   docs/deployment/productionDeployment.md
	new file:   docs/newProductionInstance.md

* Update config.md

* Add API endpoint for basic comaprison

Changes to be committed:
	modified:   biocompute/apis.py
	modified:   biocompute/urls.py
	modified:   requirements.txt

* Fix Django CI issue (#340)

biocompute-objects/portal_userdb#380

Changes to be committed:
	modified:   .github/workflows/django.yml
	modified:   biocompute/apis.py
	modified:   biocompute/models.py
	modified:   config/settings.py
	modified:   config/urls.py

* Update to BcoValidator.load_schema (#341)

Updated the function to check locally for the most used schemas. Improves
testing and speed in BCO validation.

Changes to be committed:
	modified:   biocompute/services.py
	renamed:    config/IEEE/2791object.json -> config/schemas/2791object.json
	new file:   config/schemas/dataset_extension.json
	renamed:    config/IEEE/description_domain.json -> config/schemas/description_domain.json
	renamed:    config/IEEE/error_domain.json -> config/schemas/error_domain.json
	renamed:    config/IEEE/execution_domain.json -> config/schemas/execution_domain.json
	new file:   config/schemas/fhir_extension.json
	new file:   config/schemas/galaxy_extension.json
	renamed:    config/IEEE/io_domain.json -> config/schemas/io_domain.json
	new file:   config/schemas/license_extension.json
	renamed:    config/IEEE/parametric_domain.json -> config/schemas/parametric_domain.json
	renamed:    config/IEEE/provenance_domain.json -> config/schemas/provenance_domain.json
	new file:   config/schemas/scm_extension.json
	renamed:    config/IEEE/usability_domain.json -> config/schemas/usability_domain.json

* Add additional schema files and reorganize

Changes to be committed:
	modified:   biocompute/services.py
	new file:   config/schemas/1.1.0/dataset_extension.json
	new file:   config/schemas/1.1.0/fhir_extension.json
	new file:   config/schemas/1.1.0/galaxy_extension.json
	new file:   config/schemas/1.1.0/license_extension.json
	new file:   config/schemas/1.1.0/scm_extension.json
	renamed:    config/schemas/dataset_extension.json -> config/schemas/1.2.0/dataset_extension.json
	renamed:    config/schemas/fhir_extension.json -> config/schemas/1.2.0/fhir_extension.json
	renamed:    config/schemas/galaxy_extension.json -> config/schemas/1.2.0/galaxy_extension.json
	renamed:    config/schemas/license_extension.json -> config/schemas/1.2.0/license_extension.json
	renamed:    config/schemas/scm_extension.json -> config/schemas/1.2.0/scm_extension.json
	renamed:    config/schemas/2791object.json -> config/schemas/2791/2791object.json
	renamed:    config/schemas/description_domain.json -> config/schemas/2791/description_domain.json
	renamed:    config/schemas/error_domain.json -> config/schemas/2791/error_domain.json
	renamed:    config/schemas/execution_domain.json -> config/schemas/2791/execution_domain.json
	renamed:    config/schemas/io_domain.json -> config/schemas/2791/io_domain.json
	renamed:    config/schemas/parametric_domain.json -> config/schemas/2791/parametric_domain.json
	renamed:    config/schemas/provenance_domain.json -> config/schemas/2791/provenance_domain.json
	renamed:    config/schemas/usability_domain.json -> config/schemas/2791/usability_domain.json
	modified:   config/settings.py
	modified:   requirements.txt

* Add instructions for Docker deployment

Changes to be committed:
	modified:   Dockerfile
	modified:   docker-compose.yml
	modified:   docs/deployment/dockerDeployment.md
	new file:   entrypoint.sh

* Update comparison API (#344)

Changes to be committed:
	modified:   biocompute/apis.py

* Add API for LDH (#347)

#333
Changes to be committed:
	modified:   biocompute/apis.py
	modified:   biocompute/selectors.py
	modified:   biocompute/services.py
	modified:   biocompute/urls.py

---------

Co-authored-by: Kiran Sen <[email protected]>
Co-authored-by: Kiran Sen <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent 2ca9b40 commit 30d2e95
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 24 deletions.
90 changes: 68 additions & 22 deletions biocompute/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
user_can_publish_draft,
user_can_publish_prefix,
prefix_from_object_id,
get_authorized_bcos
)
from biocompute.services import convert_to_ldh
from config.services import (
legacy_api_converter,
bulk_response_constructor,
Expand Down Expand Up @@ -910,27 +912,71 @@ def post(self, request):
accepted_requests = True
data = request.data

try:

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

result = DeepDiff(new_bco, old_bco)
parsed_results = {
'dictionary_item_removed': list(result['dictionary_item_removed']),
'values_changed': list(result['values_changed']),
'iterable_item_removed': list(result['iterable_item_removed'])
}
for index, comparison in enumerate(data):
new_bco, old_bco = comparison
identifier = new_bco["object_id"]+ " vs " + old_bco["object_id"]

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

status_code = response_status(accepted_requests, rejected_requests)
return Response(status=status_code, data=response_data)


class ConverToLDH(APIView):
"""Convert BCO to LDH Format
-------------------
Provides an API endpoint for converting BioCompute Objects (BCOs) to a LDH
compatable format.
Example usage with curl:
```shell
curl -X GET "http://localhost:8000/api/objects/?contents=review&prefix=BCO&owner=tester&object_id=BCO" -H "accept: application/json"
```
This API view is accessible to any user without authentication requirements.
"""
authentication_classes = []
permission_classes = [AllowAny]

status_code = response_status(accepted_requests, rejected_requests)
return Response(status=status_code, data=response_data)
except Exception:
return Response(status=status.HTTP_400_BAD_REQUEST, data={})
@swagger_auto_schema(
operation_id="convert_to_ldh",
manual_parameters=[
openapi.Parameter("object_id",
openapi.IN_QUERY,
description="Object ID to be converted.",
type=openapi.TYPE_STRING,
default="http://127.0.0.1:8000/BCO_000000/1.0"
)
],
responses={
200: "Success. Object contents converted",
404: "Not found. That BCO could not be found on the server or The "\
"requestor does not have appropriate permissions."
},
tags=["BCO Management"],
)

def get(self, request):
authorized_bcos = get_authorized_bcos(request.user.id)

object_id = request.GET["object_id"]
if object_id in authorized_bcos:
data = convert_to_ldh(
object_id=object_id,
username=request.user.username
)

return Response(status=status.HTTP_200_OK, data=data)
else:
return Response(
status=status.HTTP_404_NOT_FOUND,
data={"message": f"{object_id}, could not be found "\
+ "on the server or user does not have permissions."
}
)
2 changes: 1 addition & 1 deletion biocompute/selectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def get_authorized_bcos(user: User):
Returns:
- QuerySet:
A Django QuerySet containing the BCOs the user is authorized to access.
A Django QuerySet containing the BCO object_ids the user is authorized to access.
"""

bcos = Bco.objects.filter(
Expand Down
51 changes: 51 additions & 0 deletions biocompute/services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python3
# biocopmute/services.py

import datetime
import os
import glob
import copy
import json
import jsonref
Expand Down Expand Up @@ -654,3 +657,51 @@ def bco_score(bco_instance: Bco) -> Bco:
bco_instance.score = base_score

return bco_instance

def convert_to_ldh(object_id, username):
"""
"""

data = Bco.objects.get(object_id=object_id).contents
contents = {}
contents['entType'] = 'BioCompute Object'
contents['entIri'] = data['object_id']
contents['entId'] = data['object_id'].split('/')[-2]
contents['modified'] = datetime.datetime.utcnow().isoformat()+'Z'
contents['modifier'] = username
contents['entContent'] = {}


# contents['id'] = get_id()
# contents['IdFor'] = get_id_for()
contents['entAliases'] = [contents['entId'], contents['entIri'], contents['entType']]


try:
contents['entContent']['provenance'] = data['provenance_domain']
except KeyError:
pass
try:
contents['entContent']['usability'] = data['usability_domain']
except KeyError:
pass
try:
contents['entContent']['description'] = data['description_domain']
except KeyError:
pass
try:
contents['entContent']['execution'] = data['execution_domain']
except KeyError:
pass
try:
contents['entContent']['io'] = data['io_domain']
except KeyError:
pass
try:
contents['entContent']['parametric'] = data['parametric_domain']
except KeyError:
pass

print(contents)
return contents

4 changes: 3 additions & 1 deletion biocompute/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
"""BioCompute URLs
"""

from django.urls import path
from django.urls import path, re_path
from biocompute.apis import (
DraftsCreateApi,
DraftsModifyApi,
DraftsPublishApi,
PublishBcoApi,
ValidateBcoApi,
CompareBcoApi,
ConverToLDH,
)

urlpatterns = [
Expand All @@ -19,4 +20,5 @@
path("objects/validate/", ValidateBcoApi.as_view()),
path("objects/publish/", PublishBcoApi.as_view()),
path("objects/compare/", CompareBcoApi.as_view()),
re_path("objects/convert_to_ldh/$", ConverToLDH.as_view()),
]

0 comments on commit 30d2e95

Please sign in to comment.