Skip to content

Commit

Permalink
Merge branch 'dev-rook-ss-foimod-3328' into dev-rook-NK-FOIMOD-3584
Browse files Browse the repository at this point in the history
  • Loading branch information
nkan-aot2 committed Jan 4, 2025
2 parents a7d1667 + b8fa545 commit 2681349
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
45 changes: 45 additions & 0 deletions api/reviewer_api/models/DocumentPageflags.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,51 @@ def getpageflag_by_request_documentids(cls, _foiministryrequestid, redactionlaye
db.session.close()
return pageflags

@classmethod
def get_pageflag_count_by_requestids(cls, requestid, redactionlayerid):
try:
# Return empty dict if requestids is empty or None
if not requestid:
logging.error("RequestIDs is empty or None")
return {}
sql = """
select dp.foiministryrequestid, count(distinct dp.documentid) as page_count
from "DocumentPageflags" dp
where dp.foiministryrequestid in :requestid
and dp.redactionlayerid = :redactionlayerid
group by dp.foiministryrequestid
order by dp.foiministryrequestid;
"""

rs = db.session.execute(
text(sql),
{
"requestid": tuple(requestid),
"redactionlayerid": redactionlayerid
}
)

result = {}
rows = rs.fetchall()

# Return empty dict if no results found
if not rows:
return {}

# Process results if exists
for row in rows:
count = row["page_count"]
result[row["foiministryrequestid"]] = None if count == 0 else count

return result

except Exception as ex:
logging.error(f"Error in get_pageflag_count_by_requestids: {str(ex)}")
db.session.close()
raise ex
finally:
db.session.close()

@classmethod
def getpublicbody_by_request(cls, _foiministryrequestid, _redactionlayerid):
pageflags = []
Expand Down
27 changes: 26 additions & 1 deletion api/reviewer_api/resources/documentpageflag.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,29 @@ def post(requestid, redactionlayer):
except KeyError as error:
return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400
except BusinessException as exception:
return {'status': exception.status_code, 'message':exception.message}, 500
return {'status': exception.status_code, 'message':exception.message}, 500


@cors_preflight('GET,OPTIONS')
@API.route('/ministryrequest/<requestid>/pageflag/count')
class GetDocumentPageflagCount(Resource):
"""Get document page flag count for openinfo layer"""
@staticmethod
@TRACER.trace()
@cross_origin(origins=allowedorigins())
@auth.require
@auth.ismemberofgroups(getrequiredmemberships())
def get(requestid):
try:
# Get page flag count for openinfo layer (redactionlayerid=4)
result = documentpageflagservice().get_total_pages_by_ministryrequest_openinfo(requestid)

if result is None:
return None, 200

return json.dumps(result), 200

except BusinessException as exception:
return {'status': exception.status_code, 'message': exception.message}, 500
except Exception as error:
return {'status': False, 'message': str(error)}, 400
19 changes: 15 additions & 4 deletions api/reviewer_api/services/documentpageflagservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@
class documentpageflagservice:
def getpageflags_by_requestid_docids(self, requestid, redactionlayer, documentids):
layerids = []

if redactionlayerservice().isopeninfolayer(redactionlayer):
layerids.append(redactionlayerservice().getdefaultredactionlayerid())
else:
layerids.append(redactionlayerservice().getredactionlayerid(redactionlayer))
#layerids.append(redactionlayerservice().getdefaultredactionlayerid())
print("layerids:",layerids)
print("documentids:",documentids)

pageflags = DocumentPageflag.getpageflag_by_request_documentids(requestid, layerids, documentids)
print("pageflags:",pageflags)
return self.__removedeletedpages(requestid, pageflags)

def get_total_pages_by_ministryrequest_openinfo(self, ministryrequestids):
layerid = 4 # openinfo layer id

result = DocumentPageflag.get_pageflag_count_by_requestids(
requestid=ministryrequestids,
redactionlayerid=layerid
)

if not result:
return None

return result

def getpublicbody(self, requestid, redactionlayer):
redactionlayerid = redactionlayerservice().getredactionlayerid(redactionlayer)
return DocumentPageflag.getpublicbody_by_request(requestid, redactionlayerid)
Expand Down

0 comments on commit 2681349

Please sign in to comment.