Skip to content

Commit

Permalink
Merge pull request #1229 from bcgov/test-rook
Browse files Browse the repository at this point in the history
Test rook
  • Loading branch information
nkan-aot2 authored Dec 6, 2024
2 parents d449076 + da89b35 commit 045fc39
Show file tree
Hide file tree
Showing 12 changed files with 515 additions and 81 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified computingservices/DedupeServices/requirements.txt
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ class NotificationPublishSchema(object):
ministryrequestid = fields.Int(data_key="ministryrequestid",allow_none=False)
serviceid = fields.Str(data_key="serviceid",allow_none=False)
errorflag = fields.Str(data_key="errorflag",allow_none=False)
createdby = fields.Str(data_key="message",allow_none=False)
createdby = fields.Str(data_key="createdby",allow_none=False)
createdat = fields.Str(data_key="createdat",allow_none=False)
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from utils import redisstreamdb, notification_stream_key
from rstreamio.message.schemas.notification import NotificationPublishSchema
from models import dedupeproducermessage
from datetime import datetime

import json

Expand All @@ -17,6 +18,7 @@ def sendnotification(self, message, error=False):
notification_msg.errorflag = self.__booltostr(error)
notification_msg.ministryrequestid = message.ministryrequestid
notification_msg.createdby = message.createdby
notification_msg.createdat = datetime.now().strftime("%m/%d/%Y, %H:%M:%S.%f")
notification_msg.batch = message.batch
#Additional execution parameters : Begin

Expand Down
454 changes: 421 additions & 33 deletions computingservices/DedupeServices/services/s3documentservice.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion computingservices/DedupeServices/utils/basicutils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import json

def to_json(obj):
return json.dumps(obj, default=lambda obj: obj.__dict__)

def add_spacing_around_special_character(special_char, stringvalue):
string= stringvalue.split(special_char)
return f' {special_char} '.join(string)
return f' {special_char} '.join(string)
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def __packagesummaryforcfdrequests(self, message, documentids):
#original_pages = self.__adjust_original_pages(document_pages)
end_page = 0
for record in records:
if record["documentids"][0] in pagecounts:
if len(set(record["documentids"]).intersection(set(pagecounts.keys()))) > 0:
# print("-----------------------Record : ---------------------------", record["documentids"])
record_range, totalpagecount1,end_page = self.__createrecordpagerange(record, pagecounts,end_page )
# print(f"Range for each record- record_range:{record_range} &&& totalpagecount1:{totalpagecount1} \
Expand Down Expand Up @@ -411,7 +411,10 @@ def __format_redaction_summary(self, pageflag, pageredactions, category):
range_start = currentpg["stitchedpageno"] if range_start == 0 else range_start
range_consults = currentpg["consults"]
skipconsult = True if category in ('oipcreviewredline','responsepackage', 'CFD_responsepackage') else False
if currentpg["stitchedpageno"]+1 == nextpg["stitchedpageno"] and (skipconsult == True or (skipconsult == False and currentpg["consults"] == nextpg["consults"])):
if (currentpg["stitchedpageno"]+1 == nextpg["stitchedpageno"]
and (skipconsult == True or (skipconsult == False and currentpg["consults"] == nextpg["consults"]))
and currentpg["sections"] == nextpg["sections"]
):
range_sections.extend(nextpg["sections"])
range_end = nextpg["stitchedpageno"]
else:
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/FOI/Home/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ const ContextMenu = ({
savePageFlag(
requestId,
flagId,
(data: any) => {
(data: any, flagid: number) => {
if(data.status == true){
const updatedPageFlags = updatePageFlagOnPage(
data.updatedpageflag,
pageFlags
);
if(updatedPageFlags?.length > 0)
syncPageFlagsOnAction(updatedPageFlags);
syncPageFlagsOnAction(updatedPageFlags, [pageFlagTypes["Duplicate"], pageFlagTypes["Not Responsive"]].includes(flagid));
}
},
(error: any) => console.log(error),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ const useSaveResponsePackage = () => {
let annotList = annotationManager.getAnnotationsList();
annotationManager.ungroupAnnotations(annotList);
/** remove duplicate and not responsive pages */
let pagesToRemove = [];
var pagesToRemove = [];
for (const infoForEachDoc of pageFlags) {
for (const pageFlagsForEachDoc of infoForEachDoc.pageflag) {
/** pageflag duplicate or not responsive */
Expand Down Expand Up @@ -289,6 +289,27 @@ const useSaveResponsePackage = () => {
render: "Saving section stamps...",
isLoading: true,
});
// update page mappings
for (var page of pagesToRemove) {
delete pageMappedDocs.stitchedPageLookup[page]
}
var updatedPageMapping = Object.entries(pageMappedDocs.stitchedPageLookup)
// remove withheld in full pages after page stamp has been applied
pagesToRemove = [];
for (const infoForEachDoc of pageFlags) {
for (const pageFlagsForEachDoc of infoForEachDoc.pageflag) {
if (pageFlagsForEachDoc.flagid === pageFlagTypes["Withheld in Full"]) {
var pageToRemove = updatedPageMapping.findIndex(p => p[1].docid === infoForEachDoc.documentid && p[1].page === pageFlagsForEachDoc.page) + 1
pagesToRemove.push(pageToRemove);
}
}
}

if (pagesToRemove.length > 0) {
await doc.removePages(pagesToRemove);
}


/**Fixing section cutoff issue in response pkg-
* (For showing section names-freetext annotations are
* added once redactions are applied in the annotationChangedHandler)
Expand Down
5 changes: 4 additions & 1 deletion web/src/components/FOI/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,13 @@ function Home() {
return doclist.find(item => item.file.pagecount > 0);
}

const syncPageFlagsOnAction = (updatedFlags) => {
const syncPageFlagsOnAction = (updatedFlags, isNRorDuplicate) => {

selectorRef?.current?.scrollLeftPanelPosition("")
setPageFlags(updatedFlags);
if (isNRorDuplicate) {
redliningRef?.current?.triggerSetWatermarks();
}
};

useEffect(() => {
Expand Down
95 changes: 55 additions & 40 deletions web/src/components/FOI/Home/Redlining.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ const Redlining = React.forwardRef(
const [pageSelectionsContainNRDup, setPageSelectionsContainNRDup] = useState(false);
const [outstandingBalanceModal, setOutstandingBalanceModal] = useState(false);
const [isOverride, setIsOverride]= useState(false);
const [feeOverrideReason, setFeeOverrideReason]= useState("");

const [feeOverrideReason, setFeeOverrideReason]= useState("");
const [isWatermarkSet, setIsWatermarkSet] = useState(false);
//xml parser
const parser = new XMLParser();
/**Response Package && Redline download and saving logic (react custom hooks)*/
Expand Down Expand Up @@ -240,8 +240,10 @@ const Redlining = React.forwardRef(
documentViewer.setToolMode(
documentViewer.getTool(instance.Core.Tools.ToolNames.REDACTION)
);
documentViewer.getTool(instance.Core.Tools.ToolNames.RECTANGLE).setStyles({
StrokeColor: new Annotations.Color(255, 205, 69)
});
const UIEvents = instance.UI.Events;

//customize header - insert a dropdown button
const document = instance.UI.iframeWindow.document;
setIframeDocument(document);
Expand Down Expand Up @@ -1376,6 +1378,9 @@ const Redlining = React.forwardRef(
annotManager.addAnnotations(newAnnots);
annotManager.drawAnnotationsFromList(newAnnots);
},
triggerSetWatermarks() {
setWatermarks();
}
}));

const disableNRDuplicate = () => {
Expand Down Expand Up @@ -1420,43 +1425,6 @@ const Redlining = React.forwardRef(
if (docInstance && documentList.length > 0) {
const document = docInstance?.UI.iframeWindow.document;
document.getElementById("create_response_pdf").addEventListener("click", handleCreateResponsePDFClick);
docViewer?.setWatermark({
// Draw custom watermark in middle of the document
custom: (ctx, pageNumber, pageWidth, pageHeight) => {
// ctx is an instance of CanvasRenderingContext2D
// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
// Hence being able to leverage those properties
let originalPage = pageMappedDocs['stitchedPageLookup'][pageNumber]
let doc = pageFlags.find(d => d.documentid === originalPage.docid);
let pageFlagsOnPage = doc?.pageflag?.filter(f => f.page === originalPage.page);
let NrOrDupeFlag = pageFlagsOnPage?.find(pageFlagItem => pageFlagItem.flagid === pageFlagTypes["Duplicate"] || pageFlagItem.flagid === pageFlagTypes["Not Responsive"]);
if (NrOrDupeFlag?.flagid === pageFlagTypes["Duplicate"]) {
ctx.fillStyle = "#ff0000";
ctx.font = "20pt Arial";
ctx.globalAlpha = 0.4;

ctx.save();
ctx.translate(pageWidth / 2, pageHeight / 2);
ctx.rotate(-Math.PI / 4);
ctx.fillText("DUPLICATE", 0, 0);
ctx.restore();
}

if (NrOrDupeFlag?.flagid === pageFlagTypes["Not Responsive"]) {
ctx.fillStyle = "#ff0000";
ctx.font = "20pt Arial";
ctx.globalAlpha = 0.4;

ctx.save();
ctx.translate(pageWidth / 2, pageHeight / 2);
ctx.rotate(-Math.PI / 4);
ctx.fillText("NOT RESPONSIVE", 0, 0);
ctx.restore();
}
},
});
docViewer?.refreshAll();
docViewer?.updateView();
}
//Cleanup Function: removes previous event listeiner to ensure handleCreateResponsePDFClick event is not called multiple times on click
return () => {
Expand All @@ -1467,6 +1435,53 @@ const Redlining = React.forwardRef(
};
}, [pageFlags, isStitchingLoaded]);

useEffect(() => {
if (docInstance && documentList.length > 0 && !isWatermarkSet) {
setWatermarks();
setIsWatermarkSet(true)
}
}, [pageFlags, isStitchingLoaded, isWatermarkSet]);


const setWatermarks = () => {
docViewer?.setWatermark({
// Draw custom watermark in middle of the document
custom: (ctx, pageNumber, pageWidth, pageHeight) => {
// ctx is an instance of CanvasRenderingContext2D
// https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D
// Hence being able to leverage those properties
let originalPage = pageMappedDocs['stitchedPageLookup'][pageNumber]
let doc = pageFlags.find(d => d.documentid === originalPage.docid);
let pageFlag = doc?.pageflag?.find(f => f.page === originalPage.page);
if (pageFlag?.flagid === pageFlagTypes["Duplicate"]) {
ctx.fillStyle = "#ff0000";
ctx.font = "20pt Arial";
ctx.globalAlpha = 0.4;

ctx.save();
ctx.translate(pageWidth / 2, pageHeight / 2);
ctx.rotate(-Math.PI / 4);
ctx.fillText("DUPLICATE", 0, 0);
ctx.restore();
}

if (pageFlag?.flagid === pageFlagTypes["Not Responsive"]) {
ctx.fillStyle = "#ff0000";
ctx.font = "20pt Arial";
ctx.globalAlpha = 0.4;

ctx.save();
ctx.translate(pageWidth / 2, pageHeight / 2);
ctx.rotate(-Math.PI / 4);
ctx.fillText("NOT RESPONSIVE", 0, 0);
ctx.restore();
}
},
});
docViewer?.refreshAll();
docViewer?.updateView();
}

const stitchPages = (_doc, pdftronDocObjs) => {
for (let filerow of pdftronDocObjs) {
let _exists = stichedfiles.filter(
Expand Down

0 comments on commit 045fc39

Please sign in to comment.