Skip to content

Commit

Permalink
Merge pull request #194 from mkumar-02/15.0-develop
Browse files Browse the repository at this point in the history
G2P Import DCI API: Modified authorization token flow.
  • Loading branch information
shibu-narayanan authored Feb 12, 2024
2 parents 85759f8 + 265e564 commit 4f59205
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
2 changes: 2 additions & 0 deletions g2p_import_dci_api/models/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
DATA_SOURCE_AUTH_PATH_NAME = "Authentication"

REQUEST_TIMEOUT = 60

MAX_REGISTRANT = 150
38 changes: 24 additions & 14 deletions g2p_import_dci_api/models/fetch_social_registry_beneficiary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ class G2PFetchSocialRegistryBeneficiary(models.Model):
_name = "g2p.fetch.social.registry.beneficiary"
_description = "Fetch Social Registry Beneficiary"

MAX_REGISTRANT_IN_FETCH = 150

data_source_id = fields.Many2one("spp.data.source", required=True)

name = fields.Char("Search Criteria Name", required=True)
Expand Down Expand Up @@ -73,11 +71,13 @@ def get_social_registry_auth_url(self, paths):
url = self.data_source_id.url
auth_path = paths.get(constants.DATA_SOURCE_AUTH_PATH_NAME)

return f"{url}{auth_path}"
if auth_path.lstrip().startswith("/"):
return f"{url}{auth_path}"

def get_auth_token(self, auth_url):
else:
return auth_path

headers = self.get_headers_for_request()
def get_auth_token(self, auth_url):

grant_type = (
self.env["ir.config_parameter"]
Expand All @@ -94,20 +94,29 @@ def get_auth_token(self, auth_url):
.sudo()
.get_param("social_registry_client_secret")
)
db_name = (
self.env["ir.config_parameter"].sudo().get_param("social_registry_db_name")
username = (
self.env["ir.config_parameter"]
.sudo()
.get_param("social_registry_user_name")
)
password = (
self.env["ir.config_parameter"]
.sudo()
.get_param("social_registry_user_password")
)

data = {
"grant_type": grant_type,
"client_id": client_id,
"client_secret": client_secret,
"db_name": db_name,
"username": username,
"password": password,
}

response = requests.post(
auth_url,
headers=headers,
data=json.dumps(data),
headers={"Content-Type": "application/x-www-form-urlencoded"},
data=data,
timeout=constants.REQUEST_TIMEOUT,
)

Expand Down Expand Up @@ -355,10 +364,10 @@ def process_registrants(self, partners):
def process_registrants_async(self, partners, count):
_logger.warning("Fetching Registrant Asynchronously!")
jobs = []
for i in range(0, count, self.MAX_REGISTRANT_IN_FETCH):
for i in range(0, count, constants.MAX_REGISTRANT):
jobs.append(
self.delayable().process_registrants(
partners[i : i + self.MAX_REGISTRANT_IN_FETCH]
partners[i : i + constants.MAX_REGISTRANT]
)
)
main_job = group(*jobs)
Expand Down Expand Up @@ -425,11 +434,12 @@ def fetch_social_registry_beneficiary(self):
timeout=constants.REQUEST_TIMEOUT,
)

sticky = False

# Process response
if response.ok:
kind = "success"
message = _("Successfully Imported Social Registry Beneficiaries")
sticky = False

search_responses = (
response.json().get("message", {}).get("search_response", [])
Expand All @@ -443,7 +453,7 @@ def fetch_social_registry_beneficiary(self):
total_partners_count = reg_record.get("totalRegistrantCount", "")

if total_partners_count:
if total_partners_count < self.MAX_REGISTRANT_IN_FETCH:
if total_partners_count < constants.MAX_REGISTRANT:
self.process_registrants(partners)

else:
Expand Down
Binary file removed g2p_import_dci_api/static/src/img/icons/contacts.png
Binary file not shown.

0 comments on commit 4f59205

Please sign in to comment.