Skip to content

Commit

Permalink
Merge pull request #93 from bcgov/feature/3.6.0
Browse files Browse the repository at this point in the history
Feature/3.6.0
  • Loading branch information
dpitk2222 authored Oct 31, 2024
2 parents 8ac373c + 47a3a42 commit ea05e90
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cirras-underwriting-liquibase/changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
{ "include": {"file": "scripts/03_00_xx/03_01_01/00/cirras.cuws.03_01_01_00.drop.ddl.json"} },
{ "include": {"file": "scripts/03_00_xx/03_02_00/00/cirras.cuws.03_02_00_00.ddl.json"} },
{ "include": {"file": "scripts/03_00_xx/03_03_00/00/cirras.cuws.03_03_00_00.ddl.json"} },
{ "include": {"file": "scripts/03_00_xx/03_05_00/00/cirras.cuws.03_05_00_00.ddl.json"} },
{ "include": {"file": "scripts/03_00_xx/03_05_00/00/cirras.cuws.03_05_00_00.dml.json"} },
{ "include": {"file": "scripts/03_00_xx/03_05_00/01/cirras.cuws.03_05_00_01.ddl.json"} },
{ "include": {"file": "scripts/03_00_xx/03_05_00/01/cirras.cuws.03_05_00_01.dml.json"} },
{ "include": {"file": "scripts/03_00_xx/03_06_00/00/cirras.cuws.03_06_00_00.ddl.json"} }
]
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
-- Database: cirras${ENV}
-- Database: pituw${ENV}

-- DROP DATABASE "cirras${ENV}";
-- DROP DATABASE "pituw${ENV}";

CREATE DATABASE "cirras${ENV}"
CREATE DATABASE "pituw${ENV}"
WITH
OWNER = postgres
TABLESPACE = pg_default
CONNECTION LIMIT = -1;

COMMENT ON DATABASE "cirras${ENV}"
IS 'cirras${ENV} database containing schemas used by cirras applications and services.';
COMMENT ON DATABASE "pituw${ENV}"
IS 'pituw${ENV} database containing schemas used by production insurance applications and services.';

GRANT TEMPORARY, CONNECT ON DATABASE "cirras${ENV}" TO PUBLIC;
GRANT TEMPORARY, CONNECT ON DATABASE "pituw${ENV}" TO PUBLIC;

GRANT ALL ON DATABASE "cirras${ENV}" TO postgres;
GRANT ALL ON DATABASE "pituw${ENV}" TO postgres;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--The database needs to be renamed.

DEV: pituwdev
QA: pituwqa
DLVR: pituwdlvr
TEST: pituwtest
PROD: pituwprod

--Before running the rename statement, shutdown these apis:
- UW API
- Jasper API

--Rename sql has to be run: ALTER DATABASE old_database_name RENAME TO new_database_name;

DEV: ALTER DATABASE cirrasdev RENAME TO pituwdev;
QA: ALTER DATABASE cirrasqa RENAME TO pituwqa;
DLVR: ALTER DATABASE cirrasdlvr RENAME TO pituwdlvr;
TEST: ALTER DATABASE cirrastest RENAME TO pituwtest;
PROD: ALTER DATABASE cirrasprod RENAME TO pituwprod;


Possible Error if there are sessions using the database:
There are X other sessions using the database.database "cirras_dev" is being accessed by other users
ERROR: database "cirrasdev" is being accessed by other users
SQL state: 55006

Solution: SELECT pg_terminate_backend( pid ) FROM pg_stat_activity WHERE pid <> pg_backend_pid( ) AND datname = 'cirrasdev'; //WHERE cirrasdev is the old database name
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ <h2>Forage Field Inventory</h2>
matTooltip="Please enter seeding year"
(keypress)="numberOnly($event)"
(keydown)="navigateUpDown($event, 3)"
(blur)="isMyFormDirty()"
(blur)="checkPlantInsurability(fieldIndex, plantingIndex, invSeededIndex);isMyFormDirty();"
maxlength="4">
</mat-form-field>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ForageInventoryComponentModel } from './forage-inventory.component.mode
import { INVENTORY_COMPONENT_ID } from 'src/app/store/inventory/inventory.state';
import { ActivatedRoute, ParamMap, Router } from '@angular/router';
import { FormArray, FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { CROP_COMMODITY_UNSPECIFIED, INSURANCE_PLAN, PLANT_DURATION } from 'src/app/utils/constants';
import { CROP_COMMODITY_UNSPECIFIED, INSURANCE_PLAN, PLANT_DURATION, PLANT_INSURABILITY_TYPE_CODE } from 'src/app/utils/constants';
import { CropVarietyCommodityType, InventorySeededForage, InventoryUnseeded, UnderwritingComment } from '@cirras/cirras-underwriting-api';
import { addUwCommentsObject, areDatesNotEqual, areNotEqual, makeNumberOnly, makeTitleCase } from 'src/app/utils';
import { AddNewFormField, CropVarietyOptionsType, addAnnualFieldObject, addPlantingObject, addSeededForagesObject, deleteFormField, deleteNewFormField, dragField, fieldHasInventory, getInventorySeededForagesObjForSave, isLinkedFieldCommon, isLinkedPlantingCommon, isThereAnyCommentForField, linkedFieldTooltipCommon, linkedPlantingTooltipCommon, navigateUpDownTextbox, openAddEditLandPopup, roundUpDecimalAcres, updateComments } from '../inventory-common';
Expand Down Expand Up @@ -197,8 +197,8 @@ export class ForageInventoryComponent extends BaseComponent implements OnChanges
fldPlantings.push( self.fb.group(
addPlantingObject(pltg.cropYear, pltg.fieldId, pltg.insurancePlanId, pltg.inventoryFieldGuid,
pltg.lastYearCropCommodityId, pltg.lastYearCropCommodityName, pltg.lastYearCropVarietyId, pltg.lastYearCropVarietyName,
pltg.plantingNumber, pltg.isHiddenOnPrintoutInd,
pltg.inventoryUnseeded, null, new FormArray ([]), pltgInventorySeededForages ) ) )
pltg.plantingNumber, pltg.isHiddenOnPrintoutInd, null,
pltg.inventoryUnseeded, new FormArray ([]), pltgInventorySeededForages ) ) )
}

)
Expand Down Expand Up @@ -347,7 +347,8 @@ export class ForageInventoryComponent extends BaseComponent implements OnChanges
} else {
invSeeded.controls['seedingDate'].setValue(null)
invSeeded.controls['acresToBeSeeded'].setValue(null)
// populate plant insurability is done on focus of the plant insurability dropdown
// check plant insurability in case something was selected there
this.checkPlantInsurability(fieldIndex, plantingIndex, invSeededIndex)
}
}
}
Expand Down Expand Up @@ -385,43 +386,94 @@ export class ForageInventoryComponent extends BaseComponent implements OnChanges
return variety;
}

private getVarietySddYear(fieldIndex: any, plantingIndex: any, invSeededIndex: any) {

const flds: FormArray = this.viewModel.formGroup.controls.fields as FormArray;
const pltg = flds.controls[fieldIndex]['controls']['plantings'].value.controls[plantingIndex];
const invSeeded = pltg.controls['inventorySeededForages'].value.controls[invSeededIndex];

let year = -1;

if (invSeeded.controls['seedingYear'] && invSeeded.controls['seedingYear'].value) {
year = invSeeded.controls['seedingYear'].value
}

return year
}

setPlantInsurability(fieldIndex, plantingIndex, invSeededIndex) {

let variety = this.getVariety(fieldIndex, plantingIndex, invSeededIndex);

let yearSdd = this.getVarietySddYear(fieldIndex, plantingIndex, invSeededIndex); // this is either the year(seedingDate) or seedingYear

let plantInsurabilityOptionsLocal = this.plantInsurabilityOptions.find(x => x.fieldIndex == fieldIndex && x.plantingIndex == plantingIndex && x.invSeededIndex == invSeededIndex)

if (plantInsurabilityOptionsLocal) {

plantInsurabilityOptionsLocal.options = this.setPlantingInsurabilityOptionsByVariety(variety)
plantInsurabilityOptionsLocal.options = this.setPlantingInsurabilityOptionsByVarietyAndSddYearOrDate(variety, yearSdd)

} else {
// add an entry
this.plantInsurabilityOptions.push({
fieldIndex: fieldIndex,
plantingIndex: plantingIndex,
invSeededIndex: invSeededIndex,
options: this.setPlantingInsurabilityOptionsByVariety(variety)
options: this.setPlantingInsurabilityOptionsByVarietyAndSddYearOrDate(variety, yearSdd)
})
}
}

setPlantingInsurabilityOptionsByVariety(variety){
setPlantingInsurabilityOptionsByVarietyAndSddYearOrDate(variety, yearSdd){

var self = this
let options = []

if ( variety && variety.isPlantInsurableInd == true) {

variety.cropVarietyPlantInsurabilities.forEach( p => {
options.push({
code: p.plantInsurabilityTypeCode,
description: p.description
})
// add the year logic
if (self.isPlantInsurabilityAllowed(yearSdd, p.plantInsurabilityTypeCode)) {
options.push({
code: p.plantInsurabilityTypeCode,
description: p.description
})
}

})
}
return options
}

isPlantInsurabilityAllowed(yearSdd, pitc){
//Insurability is only enabled if there is a seeded year/date
if (yearSdd < 0) {
return false
}

// EST 1 coverage can only be selected with a seeded year of the CURRENT Plan year.
if ( yearSdd == this.inventoryContract.cropYear && pitc == PLANT_INSURABILITY_TYPE_CODE.Establishment1) {
return true
}

// EST 2 & Winter 1 coverage is only applicable to Seeded dates of the Previous plan year
if ( yearSdd == this.inventoryContract.cropYear - 1
&& (pitc == PLANT_INSURABILITY_TYPE_CODE.Establishment2 || pitc == PLANT_INSURABILITY_TYPE_CODE.WinterSurvival1)) {
return true
}

// Winter 2 coverage is applicable to Seeding dates 2 years prior to the Current Plan year
if ( yearSdd == this.inventoryContract.cropYear - 2 && pitc == PLANT_INSURABILITY_TYPE_CODE.WinterSurvival2) {
return true
}

// Winter 3 coverage is applicable to Seeding dates 3 years prior to the Current Plan year
if (yearSdd == this.inventoryContract.cropYear - 3 && pitc == PLANT_INSURABILITY_TYPE_CODE.WinterSurvival3) {
return true
}

return false //
}

getPlantInsurabilityOptions(fieldIndex, plantingIndex, invSeededIndex) {
let options = []
this.plantInsurabilityOptions.forEach( x => {
Expand Down Expand Up @@ -453,6 +505,37 @@ export class ForageInventoryComponent extends BaseComponent implements OnChanges
}
}

checkPlantInsurability(fieldIndex, plantingIndex, invSeededIndex) {
const flds: FormArray = this.viewModel.formGroup.controls.fields as FormArray;
const pltg = flds.controls[fieldIndex]['controls']['plantings'].value.controls[plantingIndex];
const invSeeded = pltg.controls['inventorySeededForages'].value.controls[invSeededIndex];

let cropVarietyId = invSeeded.controls['cropVarietyCtrl'].value.cropVarietyId
let seedingYear = invSeeded.controls['seedingYear'].value
let plantInsurabilityTypeCode = invSeeded.controls['plantInsurabilityTypeCode'].value

let isPitcAllowed = false

if ( cropVarietyId && seedingYear && plantInsurabilityTypeCode) {

let variety = this.getVarietyById(cropVarietyId)
if ( variety && variety.isPlantInsurableInd == true) {

let elem = variety.cropVarietyPlantInsurabilities.find( x => x.plantInsurabilityTypeCode == plantInsurabilityTypeCode)

if (elem && this.isPlantInsurabilityAllowed(seedingYear,plantInsurabilityTypeCode)) {
isPitcAllowed = true
}
}
}

if ( isPitcAllowed == false) {
invSeeded.controls['plantInsurabilityTypeCode'].setValue(null)
}

}


setStyles(){

let styles = {
Expand Down Expand Up @@ -1497,6 +1580,9 @@ isFormValid() {
const pltg = flds.controls[fieldIndex]['controls']['plantings'].value.controls[plantingIndex]
const invSeeded = pltg.controls['inventorySeededForages'].value.controls[invSeededIndex]

// clear the selected plant insurability as it may change
invSeeded.controls['plantInsurabilityTypeCode'].setValue(null)

if (event.target.value && new Date(event.target.value).toString() == 'Invalid Date') {
alert("The Seeding Date is invalid and it will not be saved.")
invSeeded.controls['seedingDate'].nativeElement.style.backgroundColor = 'yellow'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,16 +1203,24 @@ onDeleteField(field) {
if ( frmPlanting.value.deletedByUserInd == true ||
areNotEqual(lastYearCropCommodityId, originalPlanting.lastYearCropCommodityId) ||
areNotEqual(lastYearCropVarietyId, originalPlanting.lastYearCropVarietyId) ||
areNotEqual(frmPlanting.value.acresToBeSeeded, originalPlanting.inventoryUnseeded.acresToBeSeeded) ||
areNotEqual(frmPlanting.value.cropCommodityId, originalPlanting.inventoryUnseeded.cropCommodityId) ||
areNotEqual(frmPlanting.value.cropVarietyId, originalPlanting.inventoryUnseeded.cropVarietyId) ||
areNotEqual(frmPlanting.value.isUnseededInsurableInd, originalPlanting.inventoryUnseeded.isUnseededInsurableInd) ||
areNotEqual(frmPlanting.value.isHiddenOnPrintoutInd, originalPlanting.isHiddenOnPrintoutInd)
) {

return true
}

if ( originalPlanting.inventoryUnseeded &&
(frmPlanting.value.deletedByUserInd == true ||
areNotEqual(frmPlanting.value.acresToBeSeeded, originalPlanting.inventoryUnseeded.acresToBeSeeded) ||
areNotEqual(frmPlanting.value.cropCommodityId, originalPlanting.inventoryUnseeded.cropCommodityId) ||
areNotEqual(frmPlanting.value.cropVarietyId, originalPlanting.inventoryUnseeded.cropVarietyId) ||
areNotEqual(frmPlanting.value.isUnseededInsurableInd, originalPlanting.inventoryUnseeded.isUnseededInsurableInd)
)
) {

return true
}


// now check inventory seeded grains
for (let n = 0; n < frmPlanting.value.inventorySeededGrains.controls.length; n++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface CropCommodityVarietyOptionsType {

export function addPlantingObject(cropYear, fieldId, insurancePlanId, inventoryFieldGuid, lastYearCropCommodityId,
lastYearCropCommodityName, lastYearCropVarietyId, lastYearCropVarietyName, plantingNumber, isHiddenOnPrintoutInd, underseededInventorySeededForageGuid,
inventoryUnseeded: InventoryUnseeded, inventorySeededGrains: FormArray, inventorySeededForages: FormArray,) {
inventoryUnseeded: InventoryUnseeded, inventorySeededGrains: FormArray, inventorySeededForages: FormArray) {

return {
cropYear: [ cropYear ],
Expand All @@ -44,8 +44,10 @@ export function addPlantingObject(cropYear, fieldId, insurancePlanId, inventoryF
cropCommodityName: [ (inventoryUnseeded && inventoryUnseeded.cropCommodityName) ? inventoryUnseeded.cropCommodityName : CROP_COMMODITY_UNSPECIFIED.NAME ],
cropVarietyId: [ (inventoryUnseeded && inventoryUnseeded.cropVarietyId) ? inventoryUnseeded.cropVarietyId : CROP_COMMODITY_UNSPECIFIED.ID ],
cropVarietyName: [ (inventoryUnseeded && inventoryUnseeded.cropVarietyName) ? inventoryUnseeded.cropVarietyName : CROP_COMMODITY_UNSPECIFIED.NAME ],
cropCommodityVarietyId: [ `${inventoryUnseeded.cropCommodityId||0}_${inventoryUnseeded.cropVarietyId||0}` ],
cropCommodityVarietyName: [ inventoryUnseeded.cropVarietyName ? inventoryUnseeded.cropVarietyName : inventoryUnseeded.cropCommodityName ],
cropCommodityVarietyId: [ `${(inventoryUnseeded && inventoryUnseeded.cropCommodityId)||0}_${(inventoryUnseeded && inventoryUnseeded.cropVarietyId)||0}` ],
cropCommodityVarietyName: [ inventoryUnseeded ?
(inventoryUnseeded.cropVarietyName ? inventoryUnseeded.cropVarietyName : inventoryUnseeded.cropCommodityName)
: '' ],
deletedByUserInd: [ (inventoryUnseeded && inventoryUnseeded.deletedByUserInd) ? inventoryUnseeded.deletedByUserInd : false ],
isUnseededInsurableInd: [ (!inventoryUnseeded || inventoryUnseeded.isUnseededInsurableInd == undefined) ? true : inventoryUnseeded.isUnseededInsurableInd], // defaults to true
isHiddenOnPrintoutInd: [ isHiddenOnPrintoutInd ],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export const LINK_PLANTING_TYPE = {

export const PLANT_INSURABILITY_TYPE_CODE ={
Establishment1: "E1",
// Establishment2: "E2",
// WinterSurvival1: "W1",
// WinterSurvival2: "W2",
// WinterSurvival3: "W3",
Establishment2: "E2",
WinterSurvival1: "W1",
WinterSurvival2: "W2",
WinterSurvival3: "W3",
}
2 changes: 1 addition & 1 deletion openshift/cirras-underwriting-api-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data:
WEBADE_USERNAME: '#{WEBADE_USERNAME}#'
CIRRAS_UNDERWRITING_REST_SECRET: '#{CIRRAS_UNDERWRITING_REST_SECRET}#'
POSTGRES_URL: >-
jdbc:postgresql://crunchy-postgres-#{ENV}#-pgbouncer.#{NAMESPACE}#.svc.cluster.local/cirras#{ENV}#
jdbc:postgresql://crunchy-postgres-#{ENV}#-pgbouncer.#{NAMESPACE}#.svc.cluster.local/pituw#{ENV}#
WEBADE_PASSWORD: '#{WEBADE_PASSWORD}#'
WEBADE_GET_TOKEN_URL: '#{WEBADE_GET_TOKEN_URL}#'
WEBADE_OAUTH2_AUTHORIZE_URL: '#{WEBADE_OAUTH2_AUTHORIZE_URL}#'
Expand Down
2 changes: 1 addition & 1 deletion openshift/cirras-underwriting-liquibase-configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ immutable: false
data:
LIQUIBASE_COMMAND_USERNAME: '#{POSTGRES_ADMIN_USERNAME}#'
LIQUIBASE_COMMAND_PASSWORD: '#{POSTGRES_ADMIN_PASSWORD}#'
LIQUIBASE_COMMAND_URL: jdbc:postgresql://crunchy-postgres-#{ENV}#-pgbouncer.#{NAMESPACE}#.svc.cluster.local/cirras#{ENV}#
LIQUIBASE_COMMAND_URL: jdbc:postgresql://crunchy-postgres-#{ENV}#-pgbouncer.#{NAMESPACE}#.svc.cluster.local/pituw#{ENV}#
POSTGRES_PROXY_USER_PASSWORD: '#{POSTGRES_PROXY_USER_PASSWORD}#'
POSTGRES_READ_ONLY_PASSWORD: '#{POSTGRES_READ_ONLY_PASSWORD}#'

0 comments on commit ea05e90

Please sign in to comment.