Skip to content

Commit

Permalink
Merge pull request #1110 from bcgov/dev-AA-foimod-3416
Browse files Browse the repository at this point in the history
#foimod-3416
  • Loading branch information
abin-aot authored Aug 21, 2024
2 parents 60b1a64 + 38502d8 commit 38e00fe
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
57 changes: 32 additions & 25 deletions computingservices/DocumentServices/services/dts/redactionsummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from rstreamio.message.schemas.redactionsummary import get_in_summary_object,get_in_summarypackage_object
import json
from collections import defaultdict
import traceback

class redactionsummary():

Expand All @@ -25,48 +26,54 @@ def __getrangenumber(self, rangeval):

def __packaggesummary(self, message, documentids, pageflags, programareas):
try:
# print("\nInside __packaggesummary")
print("\nInside __packaggesummary")
redactionlayerid = self.__getredactionlayerid(message)
summarymsg = message.summarydocuments
summaryobject = get_in_summary_object(summarymsg)
ordereddocids = summaryobject.sorteddocuments
stitchedpagedata = documentpageflag().getpagecount_by_documentid(message.ministryrequestid, ordereddocids)
totalpagecount = self.__calculate_totalpages(stitchedpagedata)
# print("\ntotalpagecount",totalpagecount)
print("\n __packaggesummary stitchedpagedata",stitchedpagedata)
print("\n __packaggesummary totalpagecount",totalpagecount)

if totalpagecount <=0:
return
_pageflags = self.__transformpageflags(pageflags)
# print("\n_pageflags",_pageflags)
print("\n_pageflags",_pageflags)
summarydata = []
docpageflags = documentpageflag().get_documentpageflag(message.ministryrequestid, redactionlayerid, ordereddocids)
deletedpages = self.__getdeletedpages(message.ministryrequestid, ordereddocids)
skippages= []
pagecount = 0
for docid in ordereddocids:
if docid in documentids:
docdeletedpages = deletedpages[docid] if docid in deletedpages else []
docpageflag = docpageflags[docid]
for pageflag in _pageflags:
filteredpages = self.__get_pages_by_flagid(docpageflag["pageflag"], docdeletedpages, pagecount, pageflag["pageflagid"], message.category)
if len(filteredpages) > 0:
originalpagenos = [pg['originalpageno'] for pg in filteredpages]
docpagesections = documentpageflag().getsections_by_documentid_pageno(redactionlayerid, docid, originalpagenos)
docpageconsults = self.__get_consults_by_pageno(programareas, docpageflag["pageflag"], filteredpages)
pageflag['docpageflags'] = pageflag['docpageflags'] + self.__get_pagesection_mapping(filteredpages, docpagesections, docpageconsults)
skippages = self.__get_skippagenos(docpageflag['pageflag'], message.category)
pagecount = (pagecount+stitchedpagedata[docid]["pagecount"])-len(skippages)
# print("\n_pageflags1",_pageflags)
for pageflag in _pageflags:
_data = {}
if len(pageflag['docpageflags']) > 0:
try:
for docid in ordereddocids:
if docid in documentids:
docdeletedpages = deletedpages[docid] if docid in deletedpages else []
docpageflag = docpageflags[docid]
for pageflag in _pageflags:
filteredpages = self.__get_pages_by_flagid(docpageflag["pageflag"], docdeletedpages, pagecount, pageflag["pageflagid"], message.category)
if len(filteredpages) > 0:
originalpagenos = [pg['originalpageno'] for pg in filteredpages]
docpagesections = documentpageflag().getsections_by_documentid_pageno(redactionlayerid, docid, originalpagenos)
docpageconsults = self.__get_consults_by_pageno(programareas, docpageflag["pageflag"], filteredpages)
pageflag['docpageflags'] = pageflag['docpageflags'] + self.__get_pagesection_mapping(filteredpages, docpagesections, docpageconsults)
skippages = self.__get_skippagenos(docpageflag['pageflag'], message.category)
pagecount = (pagecount+stitchedpagedata[docid]["pagecount"])-len(skippages)
print("\n_pageflags1",_pageflags)
for pageflag in _pageflags:
_data = {}
_data["flagname"] = pageflag["header"].upper()
_data["pagecount"] = len(pageflag['docpageflags'])
_data["sections"] = self.__format_redaction_summary(pageflag["description"], pageflag['docpageflags'], message.category)
summarydata.append(_data)
if len(pageflag['docpageflags']) > 0:
_data = {}
_data["flagname"] = pageflag["header"].upper()
_data["pagecount"] = len(pageflag['docpageflags'])
_data["sections"] = self.__format_redaction_summary(pageflag["description"], pageflag['docpageflags'], message.category)
summarydata.append(_data)
except (Exception) as err:
traceback.print_exc()
print('error occured in __packaggesummary redaction dts service: ', err)
return {"requestnumber": message.requestnumber, "data": summarydata}
except (Exception) as error:
traceback.print_exc()
print('error occured in redaction dts service: ', error)


Expand Down Expand Up @@ -117,7 +124,7 @@ def __packagesummaryforcfdrequests(self, message, documentids):
return {"requestnumber": message.requestnumber, "data": summarydata}

except Exception as error:
print('Error occurred in redaction dts service: ', error)
print('CFD Error occurred in redaction dts service: ', error)


def __calculate_range(self, mapped_flags, docids):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class redactionsummaryservice():
def processmessage(self,incomingmessage):
summaryfilestozip = []
message = get_in_redactionsummary_msg(incomingmessage)
print('\n 1. get_in_redactionsummary_msg is : {0}'.format(message))
try:
pdfstitchjobactivity().recordjobstatus(message,3,"redactionsummarystarted")
summarymsg = message.summarydocuments
Expand All @@ -23,22 +24,22 @@ def processmessage(self,incomingmessage):
documenttypename= 'CFD_responsepackage_redaction_summary'
else:
documenttypename= category+"_redaction_summary" if category == 'responsepackage' else "redline_redaction_summary"
#print('documenttypename', documenttypename)
print('\n 2. documenttypename', documenttypename)
upload_responses=[]
pageflags = self.__get_pageflags(category)
programareas = documentpageflag().get_all_programareas()
messageattributes= json.loads(message.attributes)
#print("\nmessageattributes:",messageattributes)
print("\n 3. messageattributes:",messageattributes)
divisiondocuments = get_in_summary_object(summarymsg).pkgdocuments
#print("\n divisiondocuments:",divisiondocuments)
print("\n 4. divisiondocuments:",divisiondocuments)
for entry in divisiondocuments:
#print("\n entry:",entry)
if 'documentids' in entry and len(entry['documentids']) > 0 :
# print("\n entry['divisionid']:",entry['divisionid'])
print("\n 5. entry['divisionid']:",entry['divisionid'])
divisionid = entry['divisionid']
documentids = entry['documentids']
formattedsummary = redactionsummary().prepareredactionsummary(message, documentids, pageflags, programareas)
#print("formattedsummary", formattedsummary)
print("\n 6. formattedsummary", formattedsummary)
template_path='templates/'+documenttypename+'.docx'
redaction_summary= documentgenerationservice().generate_pdf(formattedsummary, documenttypename,template_path)
divisioname = None
Expand All @@ -58,7 +59,7 @@ def processmessage(self,incomingmessage):
s3uricategoryfolder = category
s3uri = stitcheddocs3uri.split(s3uricategoryfolder+"/")[0] + s3uricategoryfolder+"/"
filename =self.__get_summaryfilename(message.requestnumber, category, divisioname, stitcheddocfilename)
# print("\n filename:",filename)
print("\n redaction_summary.content length: {0}".format(len(redaction_summary.content)))
uploadobj= uploadbytes(filename,redaction_summary.content,s3uri)
upload_responses.append(uploadobj)
if uploadobj["uploadresponse"].status_code == 200:
Expand All @@ -72,6 +73,7 @@ def processmessage(self,incomingmessage):
summaryfilestozip.append({"filename": uploadobj["filename"], "s3uripath":uploadobj["documentpath"]})
return summaryfilestozip
except (Exception) as error:
traceback.print_exc()
print('error occured in redaction summary service: ', error)
pdfstitchjobactivity().recordjobstatus(message,4,"redactionsummaryfailed",str(error),"summary generation failed")
return summaryfilestozip
Expand Down

0 comments on commit 38e00fe

Please sign in to comment.