Skip to content

Commit aade510

Browse files
authored
Merge pull request #628 from bcgov/dev-marshal-AS-4680
Document Reviewer Web- New batch download, stitch logic implementation for Redline download #4680
2 parents d280204 + 365fc96 commit aade510

File tree

532 files changed

+13302
-11263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

532 files changed

+13302
-11263
lines changed

Diff for: MCS.FOI.S3FileConversion/MCS.FOI.DocToPDF/DocFileProcessor.cs

+30-8
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,38 @@ public DocFileProcessor(Stream SourceStream)
4646
wordDocument.RevisionOptions.CommentDisplayMode = CommentDisplayMode.ShowInBalloons;
4747
wordDocument.RevisionOptions.CommentColor = RevisionColor.Blue;
4848

49-
//Creates an instance of DocIORenderer.
50-
using (DocIORenderer renderer = new DocIORenderer())
49+
foreach(var entity in wordDocument.ChildEntities)
5150
{
52-
using PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument);
53-
//Save the PDF file
54-
//Close the instance of document objects
55-
pdfDocument.Save(output);
56-
pdfDocument.Close(true);
57-
converted = true;
51+
if(entity.GetType().FullName == "Syncfusion.DocIO.DLS.WSection")
52+
{
53+
Syncfusion.DocIO.DLS.WSection _wsection = (Syncfusion.DocIO.DLS.WSection)entity;
54+
55+
foreach (IWTable table in _wsection.Tables)
56+
{
57+
table.TableFormat.IsAutoResized = false;
58+
table.TableFormat.WrapTextAround = true;
59+
}
5860

61+
}
62+
63+
}
64+
65+
using (Stream wordstream = new MemoryStream())
66+
{
67+
wordDocument.Save(wordstream, wordDocument.ActualFormatType);
68+
69+
//Creates an instance of DocIORenderer.
70+
using (DocIORenderer renderer = new DocIORenderer())
71+
{
72+
73+
using PdfDocument pdfDocument = renderer.ConvertToPDF(wordstream);
74+
//Save the PDF file
75+
//Close the instance of document objects
76+
pdfDocument.Save(output);
77+
pdfDocument.Close(true);
78+
converted = true;
79+
80+
}
5981
}
6082
}
6183
}

Diff for: MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MCS.FOI.MSGToPDF.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
1313
<PackageReference Include="SkiaSharp" Version="2.88.6" />
1414
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
15-
<PackageReference Include="MsgReader" Version="4.5.0" />
15+
<PackageReference Include="MsgReader" Version="4.2.1" />
1616
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="23.1.40" />
1717
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="23.1.40" />
1818
<PackageReference Include="Syncfusion.HtmlToPdfConverter.QtWebKit.Net.Core" Version="20.3.0.56" />
1919
<PackageReference Include="System.Text.Encoding.CodePages" Version="7.0.0" />
2020
</ItemGroup>
2121

22-
</Project>
22+
</Project>

Diff for: MCS.FOI.S3FileConversion/MCS.FOI.MSGToPDF/MSGFileProcessor.cs

+58-167
Large diffs are not rendered by default.

Diff for: MCS.FOI.S3FileConversion/MCS.FOI.PptToPDF/MCS.FOI.PPTToPDF.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="Serilog" Version="2.10.0" />
1212
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="2.88.6" />
1313
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="23.1.40" />
14-
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
14+
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
1515
</ItemGroup>
1616

1717
</Project>

Diff for: MCS.FOI.S3FileConversion/MCS.FOI.S3FileConversion/S3Handler.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public S3Handler() { }
161161
catch (Exception exception)
162162
{
163163
Console.WriteLine($"Error encountered on server. Message:'{exception.Message}' getting list of objects.");
164-
throw exception;
164+
throw;
165165
}
166166
finally
167167
{

Diff for: api/reviewer_api/models/Annotations.py

+32
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ def get_request_annotations_pagination(
106106
cls, ministryrequestid, mappedlayerids, page, size
107107
):
108108
_deleted = DocumentMaster.getdeleted(ministryrequestid)
109+
_originalnodonversionfiles = DocumentMaster.filteroriginalnoconversionfiles(ministryrequestid)
110+
_replacednoconversionfiles = DocumentMaster.filterreplacednoconversionfiles(ministryrequestid)
111+
_replacedotherfiles = DocumentMaster.filterreplacedfiles(ministryrequestid)
109112
_session = db.session
110113
_subquery_annotation = (
111114
_session.query(
@@ -116,6 +119,8 @@ def get_request_annotations_pagination(
116119
and_(
117120
Annotation.documentid == Document.documentid,
118121
Document.documentmasterid.notin_(_deleted),
122+
or_(Document.documentmasterid.in_(_replacedotherfiles), Document.documentmasterid.in_(_originalnodonversionfiles)),
123+
Document.documentmasterid.notin_(_replacednoconversionfiles),
119124
Document.foiministryrequestid == ministryrequestid,
120125
),
121126
)
@@ -547,6 +552,33 @@ def bulkdeleteannotations(
547552
finally:
548553
db.session.close()
549554

555+
@classmethod
556+
def deletedocumentannotations(
557+
cls, documentids, userinfo
558+
) -> DefaultMethodResult:
559+
try:
560+
sql = """with annotationames as (update "Annotations" a set isactive = false, updatedby = :userinfo, updated_at=now()
561+
where a.documentid in :documentids
562+
and a.isactive = True returning annotationname)
563+
update public."AnnotationSections" as1 set isactive = false, updatedby = :userinfo, updated_at=now()
564+
where annotationname in (select * from annotationames)
565+
and as1.isactive = True"""
566+
db.session.execute(
567+
text(sql),
568+
{
569+
"userinfo": json.dumps(userinfo),
570+
"documentids": tuple(documentids),
571+
},
572+
)
573+
db.session.commit()
574+
return DefaultMethodResult(
575+
True, "Annotations for documentids" + ",".join(str(documentids)) + "are deleted", ",".join(str(documentids))
576+
)
577+
except Exception as ex:
578+
logging.error(ex)
579+
finally:
580+
db.session.close()
581+
550582
@classmethod
551583
def getredactionsbydocumentpages(cls, _documentid, _pages, redactionlayerid):
552584
try:

Diff for: api/reviewer_api/models/DocumentMaster.py

+94
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,102 @@ def getdeleted(cls, ministryrequestid):
8585
finally:
8686
db.session.close()
8787
return documentmasters
88+
89+
90+
@classmethod
91+
def getprocessingchilddocumentids(cls, documentmasterids):
92+
documentmasters = []
93+
try:
94+
sql = """select d.documentid
95+
from public."DocumentMaster" dm
96+
left join public."Documents" d on d.documentmasterid = dm.documentmasterid
97+
where processingparentid = :documentmasterids or dm.documentmasterid = :documentmasterids"""
98+
rs = db.session.execute(text(sql), {'documentmasterids': documentmasterids})
99+
for row in rs:
100+
documentmasters.append(row["documentid"])
101+
except Exception as ex:
102+
logging.error(ex)
103+
db.session.close()
104+
raise ex
105+
finally:
106+
db.session.close()
107+
return documentmasters
88108

89109

110+
@classmethod
111+
def filterreplacednoconversionfiles(cls, ministryrequestid):
112+
documentmasters = []
113+
try:
114+
# filter out replaced jpg, png & pdf files - files do not need conversion
115+
sql = """select processingparentid
116+
from "DocumentMaster"
117+
where processingparentid is not Null and ministryrequestid =:ministryrequestid"""
118+
rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid})
119+
for row in rs:
120+
documentmasters.append(row["processingparentid"])
121+
except Exception as ex:
122+
logging.error(ex)
123+
db.session.close()
124+
raise ex
125+
finally:
126+
db.session.close()
127+
return documentmasters
128+
129+
@classmethod
130+
def filterreplacedfiles(cls, ministryrequestid):
131+
documentmasters = []
132+
try:
133+
# all original/replaced other type of files + all original/replaced (jpg, png & pdf) files
134+
sql = """select MAX(documentmasterid) as documentmasterid
135+
from public."DocumentMaster"
136+
where processingparentid is not null and ministryrequestid =:ministryrequestid
137+
group by processingparentid"""
138+
rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid})
139+
for row in rs:
140+
documentmasters.append(row["documentmasterid"])
141+
except Exception as ex:
142+
logging.error(ex)
143+
db.session.close()
144+
raise ex
145+
finally:
146+
db.session.close()
147+
return documentmasters
148+
149+
@classmethod
150+
def filteroriginalnoconversionfiles(cls, ministryrequestid):
151+
documentmasters = []
152+
try:
153+
# all original/replaced other type of files + all original/replaced (jpg, png & pdf) files
154+
sql = """select documentmasterid
155+
from public."DocumentMaster"
156+
where processingparentid is null and ministryrequestid =:ministryrequestid"""
157+
rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid})
158+
for row in rs:
159+
documentmasters.append(row["documentmasterid"])
160+
except Exception as ex:
161+
logging.error(ex)
162+
db.session.close()
163+
raise ex
164+
finally:
165+
db.session.close()
166+
return documentmasters
167+
168+
169+
@classmethod
170+
def getfilepathbydocumentid(cls, documentid):
171+
try:
172+
sql = """select dm.filepath
173+
from public."DocumentMaster" dm
174+
join public."Documents" d on d.documentmasterid = dm.documentmasterid
175+
where d.documentid = :documentid"""
176+
rs = db.session.execute(text(sql), {'documentid': documentid}).first()
177+
except Exception as ex:
178+
logging.error(ex)
179+
db.session.close()
180+
raise ex
181+
finally:
182+
db.session.close()
183+
return rs[0]
90184

91185
@classmethod
92186
def getredactionready(cls, ministryrequestid):

Diff for: api/reviewer_api/models/DocumentPageflagHistory.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@ class DocumentPageflagHistory(db.Model):
3030

3131
@classmethod
3232
def createpageflag(cls, documentpageflaghistory)->DefaultMethodResult:
33+
# no db close or commit because this function is called in a loop
3334
try:
3435
db.session.add(documentpageflaghistory)
35-
db.session.commit()
3636
return DefaultMethodResult(True, 'Page Flag history is saved', documentpageflaghistory.id)
3737
except Exception as ex:
3838
logging.error(ex)
39-
return DefaultMethodResult(True, 'Page Flag history is not saved', documentpageflaghistory.id)
40-
finally:
41-
db.session.close()
39+
return DefaultMethodResult(True, 'Page Flag history is not saved', documentpageflaghistory.id)

Diff for: api/reviewer_api/models/DocumentPageflags.py

+61-4
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,61 @@ def savepageflag(
133133
finally:
134134
db.session.close()
135135

136+
@classmethod
137+
def bulkarchivepageflag(
138+
cls,
139+
_foiministryrequestid,
140+
_documentids,
141+
userinfo,
142+
) -> DefaultMethodResult:
143+
try:
144+
dbquery = db.session.query(DocumentPageflag)
145+
pageflags = dbquery.filter(
146+
and_(
147+
DocumentPageflag.foiministryrequestid == _foiministryrequestid,
148+
DocumentPageflag.documentid.in_(_documentids),
149+
)
150+
)
151+
for pageflagobj in pageflags:
152+
DocumentPageflagHistory.createpageflag(
153+
DocumentPageflagHistory(
154+
documentpageflagid=pageflagobj.id,
155+
foiministryrequestid=pageflagobj.foiministryrequestid,
156+
documentid=pageflagobj.documentid,
157+
documentversion=pageflagobj.documentversion,
158+
pageflag=json.dumps(pageflagobj.pageflag),
159+
attributes=json.dumps(pageflagobj.attributes),
160+
createdby=json.dumps(pageflagobj.createdby),
161+
created_at=pageflagobj.created_at,
162+
updatedby=json.dumps(pageflagobj.updatedby),
163+
updated_at=pageflagobj.updated_at,
164+
redactionlayerid=pageflagobj.redactionlayerid,
165+
)
166+
)
167+
DocumentPageflagHistory.createpageflag(
168+
DocumentPageflagHistory(
169+
documentpageflagid=pageflagobj.id,
170+
foiministryrequestid=pageflagobj.foiministryrequestid,
171+
documentid=pageflagobj.documentid,
172+
documentversion=pageflagobj.documentversion,
173+
pageflag=json.dumps(pageflagobj.pageflag),
174+
attributes=json.dumps(pageflagobj.attributes),
175+
createdby=json.dumps(pageflagobj.createdby),
176+
created_at=pageflagobj.created_at,
177+
updatedby=json.dumps(userinfo),
178+
updated_at=pageflagobj.updated_at,
179+
redactionlayerid=pageflagobj.redactionlayerid,
180+
)
181+
)
182+
pageflags.delete(synchronize_session='fetch')
183+
db.session.commit()
184+
return DefaultMethodResult(True, "Page Flag is saved", _documentids)
185+
except Exception as ex:
186+
logging.error(ex)
187+
return DefaultMethodResult(True, "Page Flag is not saved", _documentids)
188+
finally:
189+
db.session.close()
190+
136191
@classmethod
137192
def getpageflag(
138193
cls, _foiministryrequestid, _documentid, _documentversion, _redactionlayerid
@@ -162,23 +217,25 @@ def getpageflag(
162217
db.session.close()
163218

164219
@classmethod
165-
def getpageflag_by_request(cls, _foiministryrequestid, redactionlayerid):
220+
def getpageflag_by_request(cls, _foiministryrequestid, redactionlayerid, documentids):
166221
pageflags = []
167222
try:
168223
sql = """select distinct on (dp.documentid) dp.documentid, dp.documentversion, dp.pageflag
169224
from "DocumentPageflags" dp
170225
join "Documents" d on dp.documentid = d.documentid and d.foiministryrequestid = :foiministryrequestid
171-
join "DocumentMaster" dm on dm.documentmasterid = d.documentmasterid and dm.ministryrequestid = :foiministryrequestid
172-
left join "DocumentDeleted" dd on dm.filepath ilike dd.filepath || '%' and dd.ministryrequestid = :foiministryrequestid
173-
where dp.foiministryrequestid = :foiministryrequestid and (dd.deleted is false or dd.deleted is null)
226+
--join "DocumentMaster" dm on dm.documentmasterid = d.documentmasterid and dm.ministryrequestid = :foiministryrequestid
227+
--left join "DocumentDeleted" dd on dm.filepath ilike dd.filepath || '%' and dd.ministryrequestid = :foiministryrequestid
228+
where dp.foiministryrequestid = :foiministryrequestid --and (dd.deleted is false or dd.deleted is null)
174229
and redactionlayerid in :redactionlayerid
230+
and dp.documentid in :documentids
175231
order by dp.documentid, dp.documentversion desc, dp.id desc;
176232
"""
177233
rs = db.session.execute(
178234
text(sql),
179235
{
180236
"foiministryrequestid": _foiministryrequestid,
181237
"redactionlayerid": tuple(redactionlayerid),
238+
"documentids": tuple(documentids),
182239
},
183240
)
184241

Diff for: api/reviewer_api/resources/documentpageflag.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get(requestid, documentid, documentversion, redactionlayerid):
7575

7676

7777
@cors_preflight('GET,OPTIONS')
78-
@API.route('/ministryrequest/<requestid>/pageflag/<redactionlayerid>')
78+
@API.route('/ministryrequest/<requestid>/pageflag/<redactionlayerid>/<documentids>')
7979
class GetDocumentPageflag(Resource):
8080
"""Get document page flag list.
8181
"""
@@ -84,9 +84,10 @@ class GetDocumentPageflag(Resource):
8484
@cross_origin(origins=allowedorigins())
8585
@auth.require
8686
@auth.ismemberofgroups(getrequiredmemberships())
87-
def get(requestid, redactionlayerid):
87+
def get(requestid, redactionlayerid, documentids):
8888
try:
89-
result = documentpageflagservice().getpageflags(requestid, redactionlayerid)
89+
documentids = documentids.split(",")
90+
result = documentpageflagservice().getpageflags(requestid, redactionlayerid, documentids)
9091
return json.dumps(result), 200
9192
except KeyError as error:
9293
return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400

0 commit comments

Comments
 (0)