| " + message.Replace("<br>", "").Replace("<br/>", "") + " |
");
@@ -371,10 +488,12 @@ private string GenerateHtmlfromMsg(Storage.Message msg)
//Initialize HTML to PDF converter with Blink rendering engine
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);
BlinkConverterSettings settings = new BlinkConverterSettings();
- settings.EnableHyperLink = false;
+ settings.EnableHyperLink = true;
+ settings.SinglePageLayout = SinglePageLayout.FitHeight;
//Set command line arguments to run without sandbox.
settings.CommandLineArguments.Add("--no-sandbox");
settings.CommandLineArguments.Add("--disable-setuid-sandbox");
+ settings.Scale = 1.0F;
htmlConverter.ConverterSettings = settings;
//Convert HTML string to PDF
PdfDocument document = htmlConverter.Convert(strHTML, "");
@@ -382,7 +501,7 @@ private string GenerateHtmlfromMsg(Storage.Message msg)
document.Save(output);
document.Close(true);
isConverted = true;
-
+
}
catch (Exception ex)
{
@@ -489,6 +608,15 @@ protected WordDocument GetEmailMetatdata(MsgReader.Outlook.Storage.Message msg)
return doc;
}
+ private static string ReplaceFirstOccurrence(string text, string search, string replace)
+ {
+ var index = text.IndexOf(search, StringComparison.Ordinal);
+ if (index < 0)
+ return text;
+
+ return text.Substring(0, index) + replace + text.Substring(index + search.Length);
+ }
+
protected virtual void Dispose(bool disposing)
{
if (disposing)
diff --git a/api/reviewer_api/models/AnnotationSections.py b/api/reviewer_api/models/AnnotationSections.py
index e5c6152b6..fd7b3815f 100644
--- a/api/reviewer_api/models/AnnotationSections.py
+++ b/api/reviewer_api/models/AnnotationSections.py
@@ -1,4 +1,4 @@
-from .db import db, ma
+from .db import db, ma
from .default_method_result import DefaultMethodResult
from sqlalchemy import or_, and_
from sqlalchemy.orm import aliased
@@ -12,25 +12,30 @@
from reviewer_api.utils.util import split, getbatchconfig
import json
+
class AnnotationSection(db.Model):
- __tablename__ = 'AnnotationSections'
+ __tablename__ = "AnnotationSections"
# Defining the columns
- id = db.Column(db.Integer, primary_key=True,autoincrement=True)
+ id = db.Column(db.Integer, primary_key=True, autoincrement=True)
version = db.Column(db.Integer, primary_key=True, nullable=False)
- foiministryrequestid =db.Column(db.Integer, nullable=True)
+ foiministryrequestid = db.Column(db.Integer, nullable=True)
section = db.Column(JSON, unique=False, nullable=False)
createdby = db.Column(JSON, unique=False, nullable=True)
created_at = db.Column(db.DateTime, default=datetime.now)
updatedby = db.Column(JSON, unique=False, nullable=True)
updated_at = db.Column(db.DateTime, nullable=True)
isactive = db.Column(db.Boolean, unique=False, nullable=False)
- annotationname =db.Column(db.Integer, ForeignKey('Annotations.annotationname'))
+ annotationname = db.Column(db.Integer, ForeignKey("Annotations.annotationname"))
-
@classmethod
def __getsectionkey(cls, _annotationname):
try:
- return db.session.query(AnnotationSection.id, AnnotationSection.version).filter(and_(AnnotationSection.annotationname == _annotationname)).order_by(AnnotationSection.version.desc()).first()
+ return (
+ db.session.query(AnnotationSection.id, AnnotationSection.version)
+ .filter(and_(AnnotationSection.annotationname == _annotationname))
+ .order_by(AnnotationSection.version.desc())
+ .first()
+ )
except Exception as ex:
logging.error(ex)
finally:
@@ -43,9 +48,14 @@ def __getbulksectionkey(cls, _annotationnames):
sql = """select distinct on (annotationname) "annotationname", "version", id
from "AnnotationSections" as2 where annotationname IN :annotationnames
order by annotationname, version desc;"""
- rs = db.session.execute(text(sql), {'annotationnames': tuple(_annotationnames)})
+ rs = db.session.execute(
+ text(sql), {"annotationnames": tuple(_annotationnames)}
+ )
for row in rs:
- apks[row['annotationname']] = {"id": row['id'], "version": row['version']}
+ apks[row["annotationname"]] = {
+ "id": row["id"],
+ "version": row["version"],
+ }
except Exception as ex:
logging.error(ex)
finally:
@@ -53,106 +63,153 @@ def __getbulksectionkey(cls, _annotationnames):
return apks
@classmethod
- def savesections(cls, annots, _foiministryrequestid, userinfo)-> DefaultMethodResult:
+ def savesections(
+ cls, annots, _foiministryrequestid, userinfo
+ ) -> DefaultMethodResult:
begin, size, limit = getbatchconfig()
if len(annots) > 0 and len(annots) < begin:
return cls.__chunksavesections(annots, _foiministryrequestid, userinfo)
elif len(annots) >= begin and len(annots) <= limit:
return cls.__bulksavesections(annots, _foiministryrequestid, userinfo, size)
else:
- return DefaultMethodResult(False, 'Invalid Annotation Section Request', -1)
-
+ return DefaultMethodResult(False, "Invalid Annotation Section Request", -1)
@classmethod
- def __chunksavesections(cls, annots, _foiministryrequestid, userinfo)->DefaultMethodResult:
+ def __chunksavesections(
+ cls, annots, _foiministryrequestid, userinfo
+ ) -> DefaultMethodResult:
successections = []
failedsections = []
try:
for annot in annots:
resp = cls.__savesection(annot, _foiministryrequestid, userinfo)
if resp.success == True:
- successections.append(annot["name"])
+ successections.append(annot["name"])
else:
failedsections.append(annot["name"])
if len(failedsections) < 1:
- return DefaultMethodResult(True, 'Annotation sections are added', ','.join(successections))
+ return DefaultMethodResult(
+ True, "Annotation sections are added", ",".join(successections)
+ )
else:
- return DefaultMethodResult(True, 'Annotation sections are failed', ','.join(failedsections))
+ return DefaultMethodResult(
+ True, "Annotation sections are failed", ",".join(failedsections)
+ )
except Exception as ex:
logging.error(ex)
finally:
db.session.close()
@classmethod
- def __bulksavesections(cls, annots, _foiministryrequestid, userinfo, size=100)->DefaultMethodResult:
- idxannots = []
+ def __bulksavesections(
+ cls, annots, _foiministryrequestid, userinfo, size=100
+ ) -> DefaultMethodResult:
+ idxannots = []
try:
- wkannots = split(annots, size)
+ wkannots = split(annots, size)
for wkannot in wkannots:
- annotnames = [d['name'] for d in wkannot]
- _pkvsections = cls.__getbulksectionkey(annotnames)
- cls.__bulknewsections(wkannot, _pkvsections, _foiministryrequestid, userinfo)
+ annotnames = [d["name"] for d in wkannot]
+ _pkvsections = cls.__getbulksectionkey(annotnames)
+ cls.__bulknewsections(
+ wkannot, _pkvsections, _foiministryrequestid, userinfo
+ )
cls.__bulkarchivesections(annotnames, userinfo)
idxannots.extend(annotnames)
- return DefaultMethodResult(True, 'Annotations added', ','.join(idxannots))
+ return DefaultMethodResult(True, "Annotations added", ",".join(idxannots))
except Exception as ex:
logging.error(ex)
@classmethod
- def __savesection(cls, annot, _foiministryrequestid, userinfo) -> DefaultMethodResult:
+ def __savesection(
+ cls, annot, _foiministryrequestid, userinfo
+ ) -> DefaultMethodResult:
sectkey = cls.__getsectionkey(annot["name"])
if sectkey is None:
return cls.__newsection(annot, _foiministryrequestid, userinfo)
else:
- return cls.__updatesection(annot, _foiministryrequestid, userinfo, sectkey[0], sectkey[1])
-
+ return cls.__updatesection(
+ annot, _foiministryrequestid, userinfo, sectkey[0], sectkey[1]
+ )
@classmethod
- def __newsection(cls, annot, _foiministryrequestid, userinfo) -> DefaultMethodResult:
+ def __newsection(
+ cls, annot, _foiministryrequestid, userinfo
+ ) -> DefaultMethodResult:
try:
- values = [{
- "annotationname": annot["name"],
- "foiministryrequestid": _foiministryrequestid,
- "section": annot["sectionsschema"],
- "version": 1,
- "createdby": userinfo,
- "isactive": True
- }]
+ values = [
+ {
+ "annotationname": annot["name"],
+ "foiministryrequestid": _foiministryrequestid,
+ "section": annot["sectionsschema"],
+ "version": 1,
+ "createdby": userinfo,
+ "isactive": True,
+ }
+ ]
insertstmt = insert(AnnotationSection).values(values)
- upsertstmt = insertstmt.on_conflict_do_update(index_elements=[AnnotationSection.annotationname, AnnotationSection.version], set_={"isactive": False,"updatedby":userinfo,"updated_at":datetime.now()}).returning(AnnotationSection.isactive, AnnotationSection.id, AnnotationSection.version)
+ upsertstmt = insertstmt.on_conflict_do_update(
+ index_elements=[
+ AnnotationSection.annotationname,
+ AnnotationSection.version,
+ ],
+ set_={
+ "isactive": False,
+ "updatedby": userinfo,
+ "updated_at": datetime.now(),
+ },
+ ).returning(
+ AnnotationSection.isactive,
+ AnnotationSection.id,
+ AnnotationSection.version,
+ )
sectproxy = db.session.execute(upsertstmt)
- result = [dict(row) for row in sectproxy]
- db.session.commit()
+ result = [dict(row) for row in sectproxy]
+ db.session.commit()
if len(result) > 0:
- idxsect = result[0]
- if idxsect['isactive'] == False:
- return cls.__updatesection(annot, _foiministryrequestid, userinfo, idxsect['id'], idxsect['version'])
- return DefaultMethodResult(True, 'Annotation Sections are added', annot["name"])
+ idxsect = result[0]
+ if idxsect["isactive"] == False:
+ return cls.__updatesection(
+ annot,
+ _foiministryrequestid,
+ userinfo,
+ idxsect["id"],
+ idxsect["version"],
+ )
+ return DefaultMethodResult(
+ True, "Annotation Sections are added", annot["name"]
+ )
except Exception as ex:
logging.error(ex)
finally:
- db.session.close()
+ db.session.close()
@classmethod
def __bulknewsections(cls, annots, _pkvannots, _foiministryrequestid, userinfo):
datalist = []
idxannots = []
try:
- for annot in annots:
- pkkey = _pkvannots[annot["name"]] if _pkvannots not in (None, {}) else None
- datalist.append({
- "annotationname": annot["name"],
- "foiministryrequestid": _foiministryrequestid,
- "section": annot["sectionsschema"],
- "createdby": userinfo,
- "isactive": True,
- "version": pkkey['version'] + 1 if pkkey is not None and "version" in pkkey else 1,
- "id": pkkey['id'] if pkkey is not None and "id" in pkkey else None
-
- })
+ for annot in annots:
+ pkkey = (
+ _pkvannots[annot["name"]] if _pkvannots not in (None, {}) else None
+ )
+ datalist.append(
+ {
+ "annotationname": annot["name"],
+ "foiministryrequestid": _foiministryrequestid,
+ "section": annot["sectionsschema"],
+ "createdby": userinfo,
+ "isactive": True,
+ "version": pkkey["version"] + 1
+ if pkkey is not None and "version" in pkkey
+ else 1,
+ "id": pkkey["id"]
+ if pkkey is not None and "id" in pkkey
+ else None,
+ }
+ )
idxannots.append(annot["name"])
db.session.bulk_insert_mappings(AnnotationSection, datalist)
- db.session.commit()
+ db.session.commit()
return idxannots
except Exception as ex:
logging.error(ex)
@@ -160,81 +217,107 @@ def __bulknewsections(cls, annots, _pkvannots, _foiministryrequestid, userinfo):
db.session.close()
@classmethod
- def __updatesection(cls, annot, _foiministryrequestid, userinfo, id= None, version=None) -> DefaultMethodResult:
+ def __updatesection(
+ cls, annot, _foiministryrequestid, userinfo, id=None, version=None
+ ) -> DefaultMethodResult:
try:
if id is None or version is None:
- return DefaultMethodResult(True, 'Unable to Save Annotation Section', annot["name"])
- values = [{
- "id" : id,
- "annotationname": annot["name"],
- "foiministryrequestid": _foiministryrequestid,
- "section": annot["sectionsschema"],
- "createdby": userinfo,
- "isactive": True,
- "version": version + 1
- }]
+ return DefaultMethodResult(
+ True, "Unable to Save Annotation Section", annot["name"]
+ )
+ values = [
+ {
+ "id": id,
+ "annotationname": annot["name"],
+ "foiministryrequestid": _foiministryrequestid,
+ "section": annot["sectionsschema"],
+ "createdby": userinfo,
+ "isactive": True,
+ "version": version + 1,
+ }
+ ]
insertstmt = insert(AnnotationSection).values(values)
secttmt = insertstmt.on_conflict_do_nothing()
- db.session.execute(secttmt)
+ db.session.execute(secttmt)
db.session.commit()
- cls.__archivesection(annot["name"], userinfo)
- return DefaultMethodResult(True, 'Annotation sections are updated', annot["name"])
+ cls.__archivesection(annot["name"], userinfo)
+ return DefaultMethodResult(
+ True, "Annotation sections are updated", annot["name"]
+ )
except Exception as ex:
logging.error(ex)
finally:
- db.session.close()
+ db.session.close()
@classmethod
- def __archivesection(cls, _annotationname, userinfo)->DefaultMethodResult:
+ def __archivesection(cls, _annotationname, userinfo) -> DefaultMethodResult:
return cls.__bulkarchivesections([_annotationname], userinfo)
@classmethod
- def __bulkarchivesections(cls, idxannots, userinfo)->DefaultMethodResult:
+ def __bulkarchivesections(cls, idxannots, userinfo) -> DefaultMethodResult:
try:
sql = """update "AnnotationSections" a set isactive = false, updatedby = :userinfo, updated_at=now()
from (select distinct on (annotationname) "annotationname", "version", id
from "AnnotationSections" where annotationname in :idxannots
- order by annotationname, version desc) b
+ order by annotationname, version desc) as b
where a.annotationname = b.annotationname
and a."version" < b.version
and a.isactive = true;"""
- db.session.execute(text(sql), {'idxannots': tuple(idxannots), 'userinfo': json.dumps(userinfo)})
+ db.session.execute(
+ text(sql),
+ {"idxannots": tuple(idxannots), "userinfo": json.dumps(userinfo)},
+ )
db.session.commit()
- return DefaultMethodResult(True, 'Annotation sections are updated', ','.join(idxannots))
+ return DefaultMethodResult(
+ True, "Annotation sections are updated", ",".join(idxannots)
+ )
except Exception as ex:
logging.error(ex)
finally:
db.session.close()
-
@classmethod
- def bulkdeletesections(cls, idxannots, userinfo)->DefaultMethodResult:
+ def bulkdeletesections(cls, idxannots, userinfo) -> DefaultMethodResult:
try:
sql = """update "AnnotationSections" a set isactive = false, updatedby = :userinfo, updated_at=now()
where a.annotationname in :idxannots
and a.isactive = true;"""
- db.session.execute(text(sql), {'idxannots': tuple(idxannots), 'userinfo': json.dumps(userinfo)})
+ db.session.execute(
+ text(sql),
+ {"idxannots": tuple(idxannots), "userinfo": json.dumps(userinfo)},
+ )
db.session.commit()
- return DefaultMethodResult(True, 'Annotation sections are deleted', ','.join(idxannots))
+ return DefaultMethodResult(
+ True, "Annotation sections are deleted", ",".join(idxannots)
+ )
except Exception as ex:
logging.error(ex)
finally:
db.session.close()
@classmethod
- def getsectionmapping(cls, documentid, documentversion):
+ def getsectionmapping(cls, documentid, documentversion):
mapping = []
- try:
+ try:
sql = """select as2.annotationname as "sectionannotationname",
cast("section" AS json) ->> 'redactannotation' as redactannotation,
cast("section" AS json) ->> 'ids' as ids
from "AnnotationSections" as2, "Annotations" a where as2.annotationname = a.annotationname and as2.isactive = true
and a.isactive = true and a.documentid = :documentid and a.documentversion = :documentversion;
"""
- rs = db.session.execute(text(sql), {'documentid': documentid, 'documentversion': documentversion})
-
+ rs = db.session.execute(
+ text(sql),
+ {"documentid": documentid, "documentversion": documentversion},
+ )
+
for row in rs:
- mapping.append({"sectionannotationname":row["sectionannotationname"], "redactannotation":row["redactannotation"], "ids": row["ids"]})
+ mapping.append(
+ {
+ "sectionannotationname": row["sectionannotationname"],
+ "redactannotation": row["redactannotation"],
+ "ids": row["ids"],
+ }
+ )
except Exception as ex:
logging.error(ex)
finally:
@@ -249,18 +332,24 @@ def getsectionmappingbyrequestid(cls, ministryrequestid):
cast("section" AS json) ->> 'redactannotation' as redactannotation,
cast("section" AS json) ->> 'ids' as ids
from "AnnotationSections" as2, "Annotations" a
- join (select distinct on (d.documentid) d.*
- from "Documents" d
- where d.foiministryrequestid = :ministryrequestid
- order by d.documentid, d.version desc) d
+ join (select distinct on (docs.documentid) docs.*
+ from "Documents" docs
+ where docs.foiministryrequestid = :ministryrequestid
+ order by docs.documentid, docs.version desc) as d
on (d.documentid = a.documentid and d.version = a.documentversion)
where as2.annotationname = a.annotationname and a.isactive = true
and as2.foiministryrequestid = :ministryrequestid and as2.isactive = true;
"""
- rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid})
+ rs = db.session.execute(text(sql), {"ministryrequestid": ministryrequestid})
for row in rs:
- mapping.append({"annotationname":row["redactannotation"], "sectionannotation":row["annotationname"], "ids": row["ids"]})
+ mapping.append(
+ {
+ "annotationname": row["redactannotation"],
+ "sectionannotation": row["annotationname"],
+ "ids": row["ids"],
+ }
+ )
except Exception as ex:
logging.error(ex)
finally:
@@ -271,7 +360,16 @@ def getsectionmappingbyrequestid(cls, ministryrequestid):
def get_by_annotationame(cls, _annotationname):
try:
annotation_section_schema = AnnotationSectionSchema(many=False)
- query = db.session.query(AnnotationSection).filter(and_(AnnotationSection.annotationname == _annotationname, AnnotationSection.isactive == True)).first()
+ query = (
+ db.session.query(AnnotationSection)
+ .filter(
+ and_(
+ AnnotationSection.annotationname == _annotationname,
+ AnnotationSection.isactive == True,
+ )
+ )
+ .first()
+ )
return annotation_section_schema.dump(query)
except Exception as ex:
logging.error(ex)
@@ -283,11 +381,27 @@ def get_by_ministryid(cls, ministryrequestid):
try:
annotation_section_schema = AnnotationSectionSchema(many=True)
redaction = aliased(Annotation)
- query = db.session.query(AnnotationSection).join(
- Annotation, Annotation.annotationname == AnnotationSection.annotationname
- ).join(
- redaction, redaction.annotationname == cast(AnnotationSection.section, JSON)['redactannotation'].astext
- ).filter(and_(AnnotationSection.foiministryrequestid == ministryrequestid, AnnotationSection.isactive == True, Annotation.isactive == True, redaction.isactive == True)).all()
+ query = (
+ db.session.query(AnnotationSection)
+ .join(
+ Annotation,
+ Annotation.annotationname == AnnotationSection.annotationname,
+ )
+ .join(
+ redaction,
+ redaction.annotationname
+ == cast(AnnotationSection.section, JSON)["redactannotation"].astext,
+ )
+ .filter(
+ and_(
+ AnnotationSection.foiministryrequestid == ministryrequestid,
+ AnnotationSection.isactive == True,
+ Annotation.isactive == True,
+ redaction.isactive == True,
+ )
+ )
+ .all()
+ )
return annotation_section_schema.dump(query)
except Exception as ex:
logging.error(ex)
@@ -297,7 +411,7 @@ def get_by_ministryid(cls, ministryrequestid):
@classmethod
def getredactedsectionsbyrequest(cls, ministryrequestid):
try:
- sql = '''select section from public."Sections" where sectionid in
+ sql = """select section from public."Sections" where sectionid in
(select distinct (json_array_elements((as1.section::json->>'ids')::json)->>'id')::integer
from public."AnnotationSections" as1
join public."Annotations" a on a.annotationname = as1.annotationname
@@ -308,11 +422,11 @@ def getredactedsectionsbyrequest(cls, ministryrequestid):
and (dd.deleted is null or dd.deleted is false)
and a.isactive = true)
and sectionid != 25
- order by sortorder'''
- rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid})
+ order by sortorder"""
+ rs = db.session.execute(text(sql), {"ministryrequestid": ministryrequestid})
sectionstring = ""
for row in rs:
- sectionstring = sectionstring + row["section"] + ', '
+ sectionstring = sectionstring + row["section"] + ", "
sectionstring = sectionstring[:-2]
return sectionstring
except Exception as ex:
@@ -323,4 +437,13 @@ def getredactedsectionsbyrequest(cls, ministryrequestid):
class AnnotationSectionSchema(ma.Schema):
class Meta:
- fields = ('annotationname', 'foiministryrequestid', 'section', 'id', 'createdby', 'created_at', 'updatedby', 'updated_at')
+ fields = (
+ "annotationname",
+ "foiministryrequestid",
+ "section",
+ "id",
+ "createdby",
+ "created_at",
+ "updatedby",
+ "updated_at",
+ )
diff --git a/api/reviewer_api/models/Annotations.py b/api/reviewer_api/models/Annotations.py
index bf18fef06..eb3511a6d 100644
--- a/api/reviewer_api/models/Annotations.py
+++ b/api/reviewer_api/models/Annotations.py
@@ -1,4 +1,4 @@
-from .db import db, ma
+from .db import db, ma
from .default_method_result import DefaultMethodResult
from sqlalchemy import or_, and_, text
from sqlalchemy.dialects.postgresql import JSON, insert
@@ -8,14 +8,15 @@
import json
from reviewer_api.utils.util import split, getbatchconfig
+
class Annotation(db.Model):
- __tablename__ = 'Annotations'
+ __tablename__ = "Annotations"
# Defining the columns
- annotationid = db.Column(db.Integer, primary_key=True,autoincrement=True)
+ annotationid = db.Column(db.Integer, primary_key=True, autoincrement=True)
version = db.Column(db.Integer, primary_key=True, nullable=False)
annotationname = db.Column(db.String(120), unique=False, nullable=False)
- documentid = db.Column(db.Integer, db.ForeignKey('Documents.documentid'))
- documentversion = db.Column(db.Integer, db.ForeignKey('Documents.version'))
+ documentid = db.Column(db.Integer, db.ForeignKey("Documents.documentid"))
+ documentversion = db.Column(db.Integer, db.ForeignKey("Documents.version"))
annotation = db.Column(db.Text, unique=False, nullable=False)
pagenumber = db.Column(db.Integer, nullable=False)
isactive = db.Column(db.Boolean, unique=False, nullable=False)
@@ -23,17 +24,34 @@ class Annotation(db.Model):
created_at = db.Column(db.DateTime, default=datetime.now)
updatedby = db.Column(JSON, unique=False, nullable=True)
updated_at = db.Column(db.DateTime, nullable=True)
-
- sections = relationship('AnnotationSection', primaryjoin="and_(Annotation.annotationname==AnnotationSection.annotationname)")
- redactionlayerid = db.Column(db.Integer, db.ForeignKey('RedactionLayers.redactionlayerid'))
- redactionlayer = relationship("RedactionLayer", backref=backref("RedactionLayers"), uselist=False)
+ sections = relationship(
+ "AnnotationSection",
+ primaryjoin="and_(Annotation.annotationname==AnnotationSection.annotationname)",
+ )
+ redactionlayerid = db.Column(
+ db.Integer, db.ForeignKey("RedactionLayers.redactionlayerid")
+ )
+ redactionlayer = relationship(
+ "RedactionLayer", backref=backref("RedactionLayers"), uselist=False
+ )
@classmethod
def getannotations(cls, _documentid, _documentversion):
try:
annotation_schema = AnnotationSchema(many=True)
- query = db.session.query(Annotation).filter(and_(Annotation.documentid == _documentid, Annotation.documentversion == _documentversion, Annotation.isactive==True)).order_by(Annotation.annotationid.asc()).all()
+ query = (
+ db.session.query(Annotation)
+ .filter(
+ and_(
+ Annotation.documentid == _documentid,
+ Annotation.documentversion == _documentversion,
+ Annotation.isactive == True,
+ )
+ )
+ .order_by(Annotation.annotationid.asc())
+ .all()
+ )
return annotation_schema.dump(query)
except Exception as ex:
logging.error(ex)
@@ -42,12 +60,12 @@ def getannotations(cls, _documentid, _documentversion):
@classmethod
def getrequestannotations(cls, ministryrequestid, mappedlayerids):
- sql = '''select a.*
+ sql = """select a.*
from "Annotations" a
- join (select distinct on (d.documentid) d.*
- from "Documents" d
- where d.foiministryrequestid = :ministryrequestid
- order by d.documentid, d.version desc) d
+ join (select distinct on (docs.documentid) docs.*
+ from "Documents" docs
+ where docs.foiministryrequestid = :ministryrequestid
+ order by docs.documentid, docs.version desc) as d
on (d.documentid = a.documentid and d.version = a.documentversion)
join "DocumentMaster" dm on dm.documentmasterid = d.documentmasterid
left join "DocumentDeleted" dd on dm.filepath ilike dd.filepath || '%'
@@ -55,70 +73,93 @@ def getrequestannotations(cls, ministryrequestid, mappedlayerids):
and (dd.deleted is false or dd.deleted is null)
and a.redactionlayerid in :_mappedlayerids
and a.isactive = true
- '''
- rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid, '_mappedlayerids':tuple(mappedlayerids)})
+ """
+ rs = db.session.execute(
+ text(sql),
+ {
+ "ministryrequestid": ministryrequestid,
+ "_mappedlayerids": tuple(mappedlayerids),
+ },
+ )
db.session.close()
- return [{
- 'annotationid': row['annotationid'],
- 'annotationname': row['annotationname'],
- 'documentid': row['documentid'],
- 'documentversion': row['documentversion'],
- 'annotation': row['annotation'],
- 'pagenumber': row['pagenumber'],
- 'isactive': row['isactive'],
- 'createdby': row['createdby'],
- 'created_at': row['created_at'],
- 'updatedby': row['updatedby'],
- 'updated_at': row['updated_at']
- } for row in rs]
+ return [
+ {
+ "annotationid": row["annotationid"],
+ "annotationname": row["annotationname"],
+ "documentid": row["documentid"],
+ "documentversion": row["documentversion"],
+ "annotation": row["annotation"],
+ "pagenumber": row["pagenumber"],
+ "isactive": row["isactive"],
+ "createdby": row["createdby"],
+ "created_at": row["created_at"],
+ "updatedby": row["updatedby"],
+ "updated_at": row["updated_at"],
+ }
+ for row in rs
+ ]
@classmethod
def getrequestdivisionannotations(cls, ministryrequestid, divisionid):
- sql = '''
+ sql = """
select a.*
from "Annotations" a
join (
- select distinct on (d.documentid) d.*
- from "Documents" d
- where d.foiministryrequestid = :ministryrequestid
- order by d.documentid, d.version desc
- ) d on (d.documentid = a.documentid and d.version = a.documentversion)
+ select distinct on (docs.documentid) docs.*
+ from "Documents" docs
+ where docs.foiministryrequestid = :ministryrequestid
+ order by docs.documentid, docs.version desc
+ ) as d on (d.documentid = a.documentid and d.version = a.documentversion)
inner join "DocumentMaster" dm on dm.documentmasterid = d.documentmasterid or dm.processingparentid = d.documentmasterid
inner join "DocumentAttributes" da
on (da.documentmasterid = dm.documentmasterid or da.documentmasterid = dm.processingparentid)
and da.isactive = true
and (da.attributes ->> 'divisions')::jsonb @> '[{"divisionid": :divisionid}]'
and a.isactive = true
- '''
- rs = db.session.execute(text(sql), {'ministryrequestid': ministryrequestid, 'divisionid': divisionid})
+ """
+ rs = db.session.execute(
+ text(sql),
+ {"ministryrequestid": ministryrequestid, "divisionid": divisionid},
+ )
db.session.close()
- return [{
- 'annotationid': row['annotationid'],
- 'annotationname': row['annotationname'],
- 'documentid': row['documentid'],
- 'documentversion': row['documentversion'],
- 'annotation': row['annotation'],
- 'pagenumber': row['pagenumber'],
- 'isactive': row['isactive'],
- 'createdby': row['createdby'],
- 'created_at': row['created_at'],
- 'updatedby': row['updatedby'],
- 'updated_at': row['updated_at']
- } for row in rs]
+ return [
+ {
+ "annotationid": row["annotationid"],
+ "annotationname": row["annotationname"],
+ "documentid": row["documentid"],
+ "documentversion": row["documentversion"],
+ "annotation": row["annotation"],
+ "pagenumber": row["pagenumber"],
+ "isactive": row["isactive"],
+ "createdby": row["createdby"],
+ "created_at": row["created_at"],
+ "updatedby": row["updatedby"],
+ "updated_at": row["updated_at"],
+ }
+ for row in rs
+ ]
@classmethod
- def getredactionsbypage(cls, _documentid, _documentversion, _pagenum, redactionlayerid):
+ def getredactionsbypage(
+ cls, _documentid, _documentversion, _pagenum, redactionlayerid
+ ):
try:
annotation_schema = AnnotationSchema(many=True)
- query = db.session.query(Annotation).filter(
- and_(
- Annotation.documentid == _documentid,
- Annotation.documentversion == _documentversion,
- Annotation.isactive==True,
- Annotation.pagenumber == _pagenum-1,
- Annotation.redactionlayerid == redactionlayerid,
- Annotation.annotation.ilike('%