Skip to content

Commit

Permalink
create consortium if custody create (#87)
Browse files Browse the repository at this point in the history
* create consortium if custody create

* resolved flake8 error
  • Loading branch information
vishalajackus authored Jul 29, 2021
1 parent 2ee19dd commit 2db3290
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion gateway/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from gateway import exceptions
from gateway import utils
from core.models import LogicModule
from core.models import LogicModule, Consortium
from gateway.clients import SwaggerClient, AsyncSwaggerClient
from datamesh.services import DataMesh

Expand Down Expand Up @@ -104,6 +104,30 @@ def perform(self) -> GatewayResponse:
except exceptions.ServiceDoesNotExist as e:
logger.error(e.content)

path_url = self.request.path # Get request path
list_string_path = path_url.split("/") # Split the request path to check if custody include in it
if ('join' not in self.request.query_params and 'custody' in list_string_path and
status_code == 201 and type(content) in [dict, list] and self.request.method == 'POST'):
# This functionality will execute only when request include custody with post request,
# It will not execute if its join request
related_organization = content.get('organization_uuid')
shipment_name = content.get('shipment')
# Check if consortium already present for respective shipment
consortium = Consortium.objects.filter(name=shipment_name).first()
if consortium:
# if consortium exist,update consortium for organization uuid
organization_list = consortium.organization_uuids
import uuid
org_uuid = uuid.UUID(related_organization)
if org_uuid not in organization_list:
# To avoid repeated organization uuid adding in consortium organization uuid
organization_list.append(related_organization)
consortium.organization_uuids = organization_list
consortium.save()
else:
# If consortium does not exists for shipment name, then create consortium
Consortium.objects.create(name=shipment_name, organization_uuids=[related_organization])

if type(content) in [dict, list]:
content = json.dumps(content, cls=utils.GatewayJSONEncoder)

Expand Down

0 comments on commit 2db3290

Please sign in to comment.