Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev rook #893

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f050b95
Integration with document services to generate redaction summary.
Jan 25, 2024
409c9ed
Draft commit.
Jan 25, 2024
4a129c6
Draft commit.
Jan 25, 2024
f92ddbc
Draft commit.
Jan 25, 2024
ca79f79
Merge branch 'dev-rook' into dev-rook-DV-3676
Jan 26, 2024
342f5ba
pagecountservice initial changes
Jan 30, 2024
ad498d2
pagecountservice dedupe related initial changes
Jan 30, 2024
f92b503
changes to calculate the pagecount
Jan 31, 2024
636cc82
fix to the column name
Jan 31, 2024
a2985a4
Update version in package-lock files to fix vulnerabilities
Feb 2, 2024
9aaff48
Merge pull request #749 from bcgov/dev-rook-4777-shiva
antsand Feb 5, 2024
c45e1d7
pagecount calculation changes
Feb 7, 2024
893147a
Update packages version
Feb 7, 2024
1cf80a0
Merge pull request #753 from bcgov/dev-rook-4777-shiva
antsand Feb 7, 2024
727965d
Merge branch 'main-DV-4403' into dev-rook-DV-3676
Feb 8, 2024
4f0cf5a
created separate service for PageCountCalulator
Feb 9, 2024
d4352d2
Merge branch 'main' into dev-rook-DV-3676
Feb 9, 2024
2abdcc7
Merge branch 'dev-rook' into dev-rook-DV-3676
Feb 9, 2024
c25a1a1
removed codes related to redactionsummary
Feb 9, 2024
1edbe6d
sample.env changes
Feb 9, 2024
094b170
Merge pull request #758 from bcgov/dev-rook-DV-3676
divyav-aot Feb 9, 2024
ecfd719
github wf for pagecountcalculator
Feb 9, 2024
1617b30
Merge pull request #759 from bcgov/dev-rook-DV-3676
divyav-aot Feb 9, 2024
891ecdb
fix to githib WF
Feb 9, 2024
e68a0a3
Merge pull request #761 from bcgov/dev-rook-DV-3676
divyav-aot Feb 9, 2024
3fc126b
wf update
Feb 9, 2024
fe22d88
Merge pull request #762 from bcgov/dev-rook-DV-3676
divyav-aot Feb 9, 2024
4b4aea4
adding debug statements
Feb 12, 2024
5a96939
Merge pull request #769 from bcgov/dev-rook-DV-3676
divyav-aot Feb 12, 2024
4804072
adding debug statements
Feb 12, 2024
aaf6fc2
adding debug statements
Feb 12, 2024
0f638ce
Merge pull request #770 from bcgov/dev-rook-DV-3676
divyav-aot Feb 12, 2024
756fa85
adding debug statements
Feb 12, 2024
6769572
Merge pull request #771 from bcgov/dev-rook-DV-3676
divyav-aot Feb 12, 2024
c7ca5a5
removed debug statements
Feb 12, 2024
b5754c3
Merge pull request #775 from bcgov/dev-rook-DV-3676
divyav-aot Feb 12, 2024
976dfce
added debug statements
Feb 12, 2024
357d994
Merge pull request #776 from bcgov/dev-rook-DV-3676
divyav-aot Feb 12, 2024
2c6c83f
code refactored
Feb 13, 2024
767fa39
redline stitching - SetDirty() error with stampPageNumberRedline fixed
Feb 13, 2024
6732b54
Merge pull request #781 from bcgov/dev-rook-DV-3676
divyav-aot Feb 13, 2024
0bb3059
redline stitching - SetDirty() error with stampPageNumberRedline fixed
Feb 14, 2024
f9cda53
pagestamping error fixed
Feb 15, 2024
d24f9b1
Merge pull request #801 from bcgov/dev-rook-DV-3676
divyav-aot Feb 15, 2024
a2406b1
Merge branch 'dev' into dev-rook-DV-3676-dev
Mar 1, 2024
53ef1ca
Merge branch 'dev-DV-cronjob' into dev-rook-DV-3676-dev
Mar 1, 2024
a813532
Merge pull request #837 from bcgov/dev-rook-DV-3676-dev
divyav-aot Mar 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/pagecountcalculator-cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: PageCountCalculator CD


on:
push:
branches:
- dev
- main
- dev-marshal
- test-marshal
- dev-rook
- test-rook
paths:
- "computingservices/PageCountCalculator/**"
- ".github/workflows/pagecountcalculator-cd.yml"

defaults:
run:
shell: bash
working-directory: ./computingservices/PageCountCalculator

env:
APP_NAME: "reviewer-pagecountcalculator"
TOOLS_NAME: "${{secrets.OPENSHIFT4_REPOSITORY}}"

jobs:
pagecountcalculator-cd-by-push:
runs-on: ubuntu-20.04

if: github.event_name == 'push' && github.repository == 'bcgov/foi-docreviewer'
steps:
- uses: actions/checkout@v2
- name: Set ENV variables for dev branch
if: ${{ github.ref_name == 'dev' }}
shell: bash
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=dev" >> $GITHUB_ENV
echo "BRANCH_NAME=dev" >> $GITHUB_ENV
echo "ENV_NAME=dev" >> $GITHUB_ENV

- name: Set ENV variables for main branch
if: ${{ github.ref_name == 'main' }}
shell: bash
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=test" >> $GITHUB_ENV
echo "BRANCH_NAME=main" >> $GITHUB_ENV
echo "ENV_NAME=test" >> $GITHUB_ENV

- name: Set ENV variables for dev-marshal branch
if: ${{ github.ref_name == 'dev-marshal' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=dev-marshal" >> $GITHUB_ENV
echo "BRANCH_NAME=dev-marshal" >> $GITHUB_ENV
echo "ENV_NAME=dev" >> $GITHUB_ENV

- name: Set ENV variables for test-marshal branch
if: ${{ github.ref_name == 'test-marshal' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=test-marshal" >> $GITHUB_ENV
echo "BRANCH_NAME=test-marshal" >> $GITHUB_ENV
echo "ENV_NAME=test" >> $GITHUB_ENV

- name: Set ENV variables for dev-rook branch
if: ${{ github.ref_name == 'dev-rook' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=dev-rook" >> $GITHUB_ENV
echo "BRANCH_NAME=dev-rook" >> $GITHUB_ENV
echo "ENV_NAME=dev" >> $GITHUB_ENV
echo "ENV_TAG_NAME=rook" >> $GITHUB_ENV

- name: Set ENV variables for test-rook branch
if: ${{ github.ref_name == 'test-rook' }}
run: |
echo "For ${{ github.ref_name }} branch"
echo "TAG_NAME=test-rook" >> $GITHUB_ENV
echo "BRANCH_NAME=test-rook" >> $GITHUB_ENV
echo "ENV_NAME=test" >> $GITHUB_ENV
echo "ENV_TAG_NAME=rook" >> $GITHUB_ENV

- name: Login Openshift
shell: bash
run: |
oc login --server=${{secrets.OPENSHIFT4_LOGIN_REGISTRY}} --token=${{secrets.OPENSHIFT4_SA_TOKEN}}

- name: Tools project
shell: bash
run: |
oc project ${{ env.TOOLS_NAME }}-tools

- name: Build from ${{ env.BRANCH_NAME }} branch
shell: bash
run: |
oc patch bc/${{ env.APP_NAME }}-build -p '{"spec":{"source":{"contextDir":"/computingservices/PageCountCalculator","git":{"ref":"${{ env.BRANCH_NAME }}"}}}}'

- name: Start Build Openshift
shell: bash
run: |
oc start-build ${{ env.APP_NAME }}-build --wait

- name: Tag+Deploy for ${{ env.TAG_NAME }}
shell: bash
run: |
oc tag ${{ env.APP_NAME }}:latest ${{ env.APP_NAME }}:${{ env.TAG_NAME }}

# - name: Watch new rollout (trigger by image change in Openshift)
# shell: bash
# run: |
# oc rollout status dc/${{ env.APP_NAME }}-{{ env.ENV_TAG_NAME }} -n ${{ env.TOOLS_NAME }}-${{ env.ENV_NAME }} -w
54 changes: 54 additions & 0 deletions .github/workflows/pagecountcalculator-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: PageCountCalculator CI


on:
pull_request:
branches:
- main
- dev
- dev-marshal
- test-marshal
- dev-rook
- test-rook
paths:
- "computingservices/PageCountCalculator/**"

defaults:
run:
shell: bash
working-directory: ./computingservices/PageCountCalculator

jobs:
docker-build-check:
runs-on: ubuntu-20.04
name: Build dockerfile to ensure it works

steps:
- uses: actions/checkout@v2
- name: docker build to check strictness
id: docker-build
run: |
docker build -f Dockerfile.local .

python-build-check:
runs-on: ubuntu-20.04
name: Build python to ensure it works

strategy:
matrix:
# python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi


1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ computingservices/poc/env/*
computingservices/DedupeServices/env/*
computingservices/PDFStitchServices/env/*
computingservices/ZippingServices/env/*
computingservices/PageCountCalculator/env/*


################################################################################
Expand Down
36 changes: 36 additions & 0 deletions api/migrations/versions/c787e6d82903_PageCalculatorJob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""empty message

Revision ID: c787e6d82903
Revises: 549893ea9059
Create Date: 2024-02-06 15:12:03.310271

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql


# revision identifiers, used by Alembic.
revision = 'c787e6d82903'
down_revision = '549893ea9059'
branch_labels = None
depends_on = None


def upgrade():
op.create_table('PageCalculatorJob',
sa.Column('pagecalculatorjobid', sa.Integer(), primary_key=True, autoincrement=True, nullable=False),
sa.Column('version', sa.Integer(), nullable=False),
sa.Column('ministryrequestid', sa.Integer(), nullable=False),
sa.Column('inputmessage', postgresql.JSON(astext_type=sa.Text()), nullable=False),
sa.Column('pagecount', postgresql.JSON(astext_type=sa.Text()), nullable=True),
sa.Column('status', sa.String(length=120), nullable=False),
sa.Column('message', sa.Text, nullable=True),
sa.Column('createdat', sa.TIMESTAMP, nullable=False, server_default=sa.func.now()),
sa.Column('createdby', sa.String(length=120), nullable=True),
sa.PrimaryKeyConstraint('pagecalculatorjobid', 'version')
)


def downgrade():
op.drop_table('PageCalculatorJob')
51 changes: 51 additions & 0 deletions api/reviewer_api/models/PageCalculatorJob.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from .db import db, ma
from datetime import datetime as datetime2
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy import func, and_
from .default_method_result import DefaultMethodResult
import logging


class PageCalculatorJob(db.Model):
__tablename__ = "PageCalculatorJob"
# Defining the columns
pagecalculatorjobid = db.Column(db.Integer, primary_key=True, autoincrement=True)
version = db.Column(db.Integer, primary_key=True, nullable=False)
ministryrequestid = db.Column(db.Integer, nullable=False)
inputmessage = db.Column(JSON, nullable=False)
pagecount = db.Column(JSON, nullable=True)
status = db.Column(db.String(120), nullable=False)
message = db.Column(db.Text, nullable=True)
createdat = db.Column(db.DateTime, default=datetime2.now, nullable=False)
createdby = db.Column(db.String(120), nullable=False)

@classmethod
def insert(cls, row):
try:
db.session.add(row)
db.session.commit()
return DefaultMethodResult(
True,
"PageCalculatorJob recorded for ministryrequestid: {0}".format(
row.ministryrequestid
),
row.pagecalculatorjobid,
)
except Exception as ex:
logging.error(ex)
finally:
db.session.close()

class PageCalculatorJobSchema(ma.Schema):
class Meta:
fields = (
"pagecalculatorjobid",
"version",
"ministryrequestid",
"inputmessage",
"pagecount",
"status",
"message",
"createdat",
"createdby",
)
21 changes: 21 additions & 0 deletions api/reviewer_api/resources/jobstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,26 @@ def get(requestid, category):
return {'status': False, 'message': CUSTOM_KEYERROR_MESSAGE + str(error)}, 400
except BusinessException as exception:
return {'status': exception.status_code, 'message':exception.message}, 500

# this is for inflight request pagecount calculation option 2
@cors_preflight('POST,OPTIONS')
@API.route('/pagecalculatorjobstatus')
class AddPageCalculatorJobStatus(Resource):
"""Insert entries into job record table.
"""
@staticmethod
# @TRACER.trace()
@cross_origin(origins=allowedorigins())
@auth.require
def post():
try:
requestjson = request.get_json()
result = jobrecordservice().insertpagecalculatorjobstatus(requestjson, AuthHelper.getuserid())
respcode = 200 if result.success == True else 500
return {'status': result.success, 'message':result.message,'id':result.identifier}, respcode
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


24 changes: 20 additions & 4 deletions api/reviewer_api/services/documentservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
from reviewer_api.models.DocumentMaster import DocumentMaster
from reviewer_api.models.FileConversionJob import FileConversionJob
from reviewer_api.models.DeduplicationJob import DeduplicationJob
from reviewer_api.models.PageCalculatorJob import PageCalculatorJob
from datetime import datetime as datetime2, timezone
from os import path
from reviewer_api.models.DocumentDeleted import DocumentDeleted
import json
from reviewer_api.utils.util import pstformat
from reviewer_api.models.DocumentAttributes import DocumentAttributes
from reviewer_api.services.pdfstitchpackageservice import pdfstitchpackageservice
from reviewer_api.services.external.eventqueueproducerservice import eventqueueproducerservice
import requests
from reviewer_api.auth import auth, AuthHelper
from os import getenv
from reviewer_api.utils.enums import StateName

requestapiurl = getenv("FOI_REQ_MANAGEMENT_API_URL")

pagecalculatorstreamkey = getenv("PAGECALCULATOR_STREAM_KEY")

class documentservice:
def getdedupestatus(self, requestid):
Expand All @@ -39,7 +41,6 @@ def getdedupestatus(self, requestid):
record["attachments"] = self.__getattachments(
records, record["documentmasterid"], []
)

# Duplicate check
finalresults = []
(
Expand Down Expand Up @@ -354,7 +355,7 @@ def __getuploadedrecord(self, records, masterid):

def deletedocument(self, payload, userid):
"""Inserts document into list of deleted documents"""
return DocumentDeleted.create(
result = DocumentDeleted.create(
[
DocumentDeleted(
filepath=path.splitext(filepath)[0],
Expand All @@ -366,6 +367,22 @@ def deletedocument(self, payload, userid):
for filepath in payload["filepaths"]
]
)
if result.success:
streamobject = {
'ministryrequestid': payload["ministryrequestid"]
}
row = PageCalculatorJob(
version=1,
ministryrequestid=payload["ministryrequestid"],
inputmessage=streamobject,
status='pushedtostream',
createdby='delete'
)
job = PageCalculatorJob.insert(row)
streamobject["jobid"] = job.identifier
streamobject["createdby"] = 'delete'
eventqueueproducerservice().add(pagecalculatorstreamkey, streamobject)
return result

def updatedocumentattributes(self, payload, userid):
"""update document attributes"""
Expand Down Expand Up @@ -418,7 +435,6 @@ def getdocuments(self, requestid,bcgovcode):
for document in self.getdedupestatus(requestid)
}
attachments = []

for documentid in documents:
_attachments = documents[documentid].pop("attachments", [])
for attachment in _attachments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from os import getenv


class zipperproducerservice:
class eventqueueproducerservice:
"""This class is reserved for integration with event queue (currently redis streams)."""

host = os.getenv("ZIPPER_REDIS_HOST")
Expand All @@ -25,4 +25,4 @@ def add(self, payload):
return DefaultMethodResult(False, err, -1)

def __streamkey(self):
return getenv("ZIPPER_STREAM_KEY")
return getenv("ZIPPER_STREAM_KEY")
Loading
Loading