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

10372 refactor #5070

Draft
wants to merge 118 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
ff513aa
10252: WIP, ideas, etc.
mmarcotte Feb 13, 2024
d2e6f2d
10252: wip; more ideas
mmarcotte Feb 14, 2024
a2cffdf
working on adding more gsi
codyseibert Feb 15, 2024
474bc15
Merge pull request #4658 from flexion/10252-notifications-endpoint-504s
mmarcotte Feb 15, 2024
8220639
10252: wip wip wip
mmarcotte Feb 15, 2024
229ebdd
10252: moving to userid at the end, wip
mmarcotte Feb 15, 2024
bdc1ddb
10252: section messages inbox,sent; completed wip
jtdevos Feb 15, 2024
c27944f
10252: consolidate create and update message to upsertMessage
mmarcotte Feb 15, 2024
150142a
10252 refactored the section outbox; fix issued with replying to mess…
codyseibert Feb 15, 2024
44f5784
Merge pull request #4660 from flexion/10252-notifications-endpoint-504s
mmarcotte Feb 15, 2024
b3451b6
10252: updated getNotificationsInteractor wip
jtdevos Feb 15, 2024
9258746
10252: refactoring to consolidate workitem stuff
mmarcotte Feb 16, 2024
66dd2c0
10252: refactor inbox and outbox for work items
mmarcotte Feb 20, 2024
17ecb67
10252: fix for refactor
mmarcotte Feb 20, 2024
e23db1c
10252: use caseEntity to dictate the properties of a Case that we den…
mmarcotte Feb 20, 2024
ace3e87
10252: remove deprecated files
mmarcotte Feb 21, 2024
3f2f5ef
10252: continue refactoring and consolidation
mmarcotte Feb 21, 2024
22aecb5
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Feb 22, 2024
bf2667c
10252: general users don't have message inboxes
mmarcotte Feb 22, 2024
57c3787
10252: fix upsertMessage and local data
mmarcotte Feb 22, 2024
6dfc854
10252: fix getNotificationsInteractor and add types
mmarcotte Feb 22, 2024
8ec7e13
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Feb 22, 2024
9cbb899
Merge branch '10252-notifications-endpoint-504s' of https://github.co…
mmarcotte Feb 22, 2024
561bf63
10252: fix saveWorkItem test
mmarcotte Feb 22, 2024
4070010
10252: fix tests
mmarcotte Feb 22, 2024
e952036
10252: fix test
mmarcotte Feb 22, 2024
a15bc7e
10252: fix test
mmarcotte Feb 22, 2024
4a423b9
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Feb 23, 2024
daaace1
10252: remove deprecated interactors
mmarcotte Feb 27, 2024
17aed6d
10252: refactor getNotificationsInteractor
mmarcotte Feb 27, 2024
199d622
10252: fix test
mmarcotte Feb 27, 2024
014388c
10252: fix test
mmarcotte Feb 27, 2024
0b08a04
10252: fix integration test
mmarcotte Feb 27, 2024
bbbf788
10252: acquire the section of the user by looking them up in the data…
mmarcotte Feb 27, 2024
0f750e1
10252: fix unit test
mmarcotte Feb 27, 2024
d2ea205
10252: refactor and consolidate
mmarcotte Feb 28, 2024
235a1c2
10252: fix tests
mmarcotte Feb 28, 2024
f6285c1
10252: fix tests
mmarcotte Feb 28, 2024
f567e20
10252: fix unit tests
mmarcotte Feb 29, 2024
a690060
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Feb 29, 2024
06481a1
10252: fix unit test
mmarcotte Feb 29, 2024
26add2d
10252: put work item in petition clerk's outbox
mmarcotte Feb 29, 2024
7964017
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Feb 29, 2024
eb22a4d
10252: fix seed data to get test to pass
mmarcotte Feb 29, 2024
b5b0995
10252: fix test
mmarcotte Feb 29, 2024
473fde7
10252: allow test to dictate what box to use
mmarcotte Feb 29, 2024
5fadb1a
Merge branch '10252-notifications-endpoint-504s' into 10252-notificat…
mmarcotte Feb 29, 2024
e2a2798
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Feb 29, 2024
a4973ad
Merge branch '10252-notifications-endpoint-504s' into 10252-notificat…
mmarcotte Feb 29, 2024
c5edef1
10252: switch to using a dedicated completed box for messages
mmarcotte Mar 1, 2024
256f3f2
10252: fix assigning message to user
mmarcotte Mar 1, 2024
58b4b22
10252: remove gsi4 and gsi5; they are not needed.
mmarcotte Mar 1, 2024
af15e55
10252: fix upsertMessage and its tests
mmarcotte Mar 1, 2024
48a03e5
10252: fix tests
mmarcotte Mar 1, 2024
1a6eebe
10252: fix test; do not include gsi1pk in outbox records
mmarcotte Mar 1, 2024
a937dcc
10252: improve code coverage
mmarcotte Mar 1, 2024
048c8d9
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Mar 5, 2024
fa8c740
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Mar 5, 2024
285d3f2
Merge branch '10252-notifications-endpoint-504s' into 10252-notificat…
mmarcotte Mar 5, 2024
9fc7d60
Merge branch '10252-notifications-endpoint-504s-refactor' into 10252-…
mmarcotte Mar 5, 2024
e6c27fa
10252: rename gsi3pk to gsiSectionBox
mmarcotte Mar 5, 2024
ce8a777
10252: rename gsi2 to gsiUserBox
mmarcotte Mar 5, 2024
6549ef6
10252: restore scannerMockFiles that was inadvertently touched
mmarcotte Mar 5, 2024
2d0eebe
10252: fix name of variable
mmarcotte Mar 6, 2024
7be2391
Merge branch '10252-notifications-endpoint-504s-refactor' into 10252-…
mmarcotte Mar 6, 2024
54a8206
10252: adjust dynamodb access patterns
mmarcotte Mar 6, 2024
509b6ac
Merge pull request #4705 from ustaxcourt/10252-notifications-endpoint…
mmarcotte Mar 6, 2024
80083ef
10252: tweak user in test since getCurrentUser never returns a section
mmarcotte Mar 6, 2024
510e2e0
10252: getCurrentUser does not include the section
mmarcotte Mar 6, 2024
d9c1ade
10252: add type; remove jsdoc
mmarcotte Mar 6, 2024
77a5107
10252: review cleanup
mmarcotte Mar 8, 2024
247d1c3
10252: add types
mmarcotte Mar 8, 2024
b6e3c30
10252: cleanup; have saveWorkItem put something in the outbox
mmarcotte Mar 8, 2024
ab49fd0
10252: add some unit tests
mmarcotte Mar 8, 2024
584cbc9
10252: fix unit test; ensure we are saving a competed work item
mmarcotte Mar 8, 2024
3a4539e
Merge pull request #4704 from ustaxcourt/10252-notifications-endpoint…
mmarcotte Mar 15, 2024
38e4d6e
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Mar 15, 2024
3b6e33f
10252: migrate gsi2pk to gsiUserBox and introduce gsiSectionBox
mmarcotte Mar 15, 2024
354a58e
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Mar 18, 2024
087d690
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Apr 1, 2024
6ade35d
10252: include gsi2pk for now in dynamoTypes
mmarcotte Apr 1, 2024
b56471c
10252: dry up uspertMessage
mmarcotte Apr 1, 2024
66128d6
10252: add migration for messages
mmarcotte Apr 1, 2024
700a834
10252: add gsis to work items migration
mmarcotte Apr 1, 2024
b156fdf
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Apr 1, 2024
1067593
Merge branch '10252-notifications-endpoint-504s' into 10252-migration
mmarcotte Apr 1, 2024
5ee7031
10252: add migration to remove unwanted records
mmarcotte Apr 1, 2024
0f0d163
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
mmarcotte Apr 19, 2024
e7d73c9
Merge branch '10252-notifications-endpoint-504s' of https://github.co…
mmarcotte Apr 19, 2024
712cb04
Partial merge branch '10252-notifications-endpoint-504s'
TomElliottFlexion Jun 18, 2024
088b5e2
10372: pull in getNotificationsInteractor from 10272 branch (thanks M…
TomElliottFlexion Jun 18, 2024
02c10a9
Merge branch '10252-migration' of https://github.com/ustaxcourt/ef-cm…
TomElliottFlexion Jun 18, 2024
9a4f710
10372: add new global indices to dynamo terraform
TomElliottFlexion Jun 18, 2024
2bb1285
Merge branch 'staging' of https://github.com/ustaxcourt/ef-cms into 1…
TomElliottFlexion Jun 18, 2024
2bf51ae
13072: remove tests for interactor that no longer exist
TomElliottFlexion Jun 18, 2024
24013e5
10372: add gsi migrations to migrationsToRun
TomElliottFlexion Jun 18, 2024
7407654
10372: fix migration
TomElliottFlexion Jun 21, 2024
b284db5
10372: add a few types
TomElliottFlexion Jun 21, 2024
6b45be7
10372 - add test coverage for Message
jasonfu9966 Jun 21, 2024
3669189
10372 - WIP add GSIs to messages run-once
jasonfu9966 Jun 21, 2024
5f17427
10372 - add script to remove work item archive records
jasonfu9966 Jun 25, 2024
39e862b
10372 - WIP update add gsis to messages
jasonfu9966 Jun 25, 2024
6402633
10372 - clean up script
jasonfu9966 Jun 25, 2024
6282052
10372 - add script
jasonfu9966 Jun 25, 2024
0fd31a2
Merge branch 'staging' into 10372-refactor
jasonfu9966 Jun 25, 2024
a08f149
10372: missing unit test
TomElliottFlexion Jun 25, 2024
069815b
10372 - add batch write to script
jasonfu9966 Jun 25, 2024
93ee2c6
10372 - optimize a script
jasonfu9966 Jun 25, 2024
8f1a004
10372 - WIP update message script
jasonfu9966 Jun 25, 2024
32eeb32
10372: update query, writes for data migration scripts
TomElliottFlexion Jun 26, 2024
5831748
10372: Zach comments
Jun 26, 2024
61fb915
10372: extract batch writing functions to helper
TomElliottFlexion Jun 27, 2024
82a2bee
10372: WIP refactor add-gsis-to-messages to migrate in batches
TomElliottFlexion Jun 27, 2024
f7aacfc
10372: small script refactor
TomElliottFlexion Jun 27, 2024
ad4e1eb
10372: Remove comments
Jun 28, 2024
541438e
10372: Remove migrations as they are now one time scripts
Jun 28, 2024
b64f869
10372: Update typing
Jun 28, 2024
91550a3
10372: first pass refactoring add-gsis-to-work-items
TomElliottFlexion Jul 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
8 changes: 4 additions & 4 deletions docs/dynamodb-access-patterns.csv
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Access Scenario,PK,SK,GS1PK,GSI2PK
Access Scenario,PK,SK,GS1PK,gsiUserBox,gsiSectionBox
the case deadline object,case-deadline|${DEADLINE_ID},case-deadline|${DEADLINE_ID},
associate a deadline with a case (mapping record),case|${CASE_ID},case-deadline|${DEADLINE_ID},
a case,case|${CASE_ID},case|${CASE_ID},leadCase|${LEAD_CASE_ID}
associate an irs practitioner onto a case,case|${CASE_ID},irsPractitioner|${USER_ID},leadCase|${LEAD_CASE_ID}
associate a private practitioner onto a case,case|${CASE_ID},privatePractitioner|${USER_ID},leadCase|${LEAD_CASE_ID}
associate docket entry on a case,case|${CASE_ID},docket-entry|${DOCKET_ENTRY_ID},
add correspondence to a case,case|${CASE_ID},correspondence|${CORRESPONDENCE_ID},
associate message onto a case,case|${CASE_ID},message|${MESSAGE_ID},message|${MESSAGE_ID}
associate message onto a case,case|${CASE_ID},message|${MESSAGE_ID},message|${MESSAGE_ID},assigneeId|${ASSIGNEE_ID},section|${SECTION}
add a hearing to a case,case|${CASE_ID},hearing|${TRIAL_SESSION_ID},
a work item on a case,case|${CASE_ID},work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID},assigneeId|${ASSIGNEE_ID}
a work item on a case,case|${CASE_ID},work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID},assigneeId|${inbox|inProgress}|${ASSIGNEE_ID},section|${inbox|inProgress}|${SECTION}
docket number generator counter,docketNumberCounter-${YEAR},docketNumberCounter-${YEAR},
how we store the list of trial sessions eligble for a case,eligible-for-trial-case-catalog,LasVegasNevada-H-B-20190816132910-107-19,eligible-for-trial-case-catalog|${CASE_ID}
associate practitioner by bar number for lookup,privatePractitioner|${BAR_NUMBER},user|${userId},
Expand All @@ -26,4 +26,4 @@ associate user with pending case,user|${USER_ID},pending-case|${CASE_ID},
save web socket connection associated with the user,user|${USER_ID},connection|${SOCKET_ID},connection
create a user,user|${USER_ID},user|${USER_ID},
save work items for a user inbox,user|${USER_ID},work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID}
a work item entry,work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID}
a work item entry,work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID}
4 changes: 2 additions & 2 deletions docs/zenhub.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Zenhub
Zenhub is the organizational tool that we use to track stories, bugs, and Devex/Opex work. It integrates with Github Issues on the Flexion fork of the EFMCS repo
Zenhub is the organizational tool that we use to track stories, bugs, and Devex/Opex work. It integrates with Github Issues on the Flexion fork of the EFCMS repo

## Access
To gain write access to our Zenhub board, you must:
- Have a Github account linked to an email you are comfortable using
- Be added as a collaborator on the Flexion fork of the EFMCS repo, by any team member with admin status
- Be added as a collaborator on the Flexion fork of the EFCMS repo, by any team member with admin status
- Be invited to the Zenhub board using the _email_ linked to the aforementioned Github account
- Be given a seat as a licensed member on the Zenhub board
173 changes: 173 additions & 0 deletions scripts/run-once-scripts/add-gsis-to-messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
// usage: npx ts-node --transpile-only scripts/run-once-scripts/add-gsis-to-messages.ts

import { Message } from '../../shared/src/business/entities/Message';
import { createApplicationContext } from '../../web-api/src/applicationContext';
import { calculateTimeToLive } from '../../web-api/src/persistence/dynamo/calculateTimeToLive';
import { TDynamoRecord } from '../../web-api/src/persistence/dynamo/dynamoTypes';
import {
formatResults,
search,
} from '../../web-api/src/persistence/elasticsearch/searchClient';
import { exit } from 'process';
import { get } from 'lodash';
import { updateRecords } from 'scripts/run-once-scripts/scriptHelper';

const applyMessageChanges = ({ items }) => {
const itemsAfter: TDynamoRecord[] = [];
for (const item of items) {
if (!item.completedAt) {
const ttl = calculateTimeToLive({
numDays: 8,
timestamp: item.createdAt!,
});

// add outbox records
itemsAfter.push({
...item,
gsi1pk: undefined,
pk: `message|outbox|user|${item.fromUserId}`,
sk: item.createdAt,
ttl: ttl.expirationTimestamp,
});
itemsAfter.push({
...item,
gsi1pk: undefined,
pk: `message|outbox|section|${item.fromSection}`,
sk: item.createdAt,
ttl: ttl.expirationTimestamp,
});

// add global secondary indexes
item.gsiUserBox = item.toUserId
? `assigneeId|${item.toUserId}`
: undefined;
item.gsiSectionBox = item.toSection
? `section|${item.toSection}`
: undefined;
itemsAfter.push(item);
} else {
const ttl = calculateTimeToLive({
numDays: 8,
timestamp: item.completedAt!,
});

// add completed box records
itemsAfter.push({
...item,
gsi1pk: undefined,
pk: `message|completed|user|${item.completedByUserId}`,
sk: item.completedAt!,
ttl: ttl.expirationTimestamp,
});
itemsAfter.push({
...item,
gsi1pk: undefined,
pk: `message|completed|section|${item.completedBySection}`,
sk: item.completedAt!,
ttl: ttl.expirationTimestamp,
});

// completed message does not get global secondary indexes
itemsAfter.push({
...item,
gsiSectionBox: undefined,
gsiUserBox: undefined,
});
}
}
return itemsAfter;
};

(async function () {
const dryRun = process.argv.slice(2)[0] || true;

const applicationContext = createApplicationContext({});
const searchParameters = {
body: {
query: {
bool: {
must: [{ term: { 'entityName.S': 'Message' } }],
},
},
},
index: 'efcms-message',
size: 10000,
};

const index = searchParameters.index || '';
const query = searchParameters.body?.query || {};
const size = searchParameters.size;

let countQ;
try {
countQ = await applicationContext.getSearchClient().count({
body: {
query,
},
index,
});
} catch (searchError) {
applicationContext.logger.error(searchError);
throw new Error('Search client encountered an error.');
}

const expected = get(countQ, 'body.count', 0);

let i = 0;
let search_after = [0];
while (i < expected) {
let searchResults = [];
const chunk = await applicationContext.getSearchClient().search({
_source: [],
body: {
query,
search_after,
sort: [{ 'createdAt.S': 'asc' }],
},
index,
size,
});
const hits = get(chunk, 'body.hits.hits', []);

if (hits.length > 0) {
searchResults = searchResults.concat(hits);
search_after = hits[hits.length - 1].sort;
}

i += size; // this avoids an endless loop if expected is somehow greater than the sum of all hits

let { results } = formatResults({
hits: {
hits: searchResults,
total: {
value: searchResults.length,
},
},
});

try {
results = results.map(message => {
delete message._score;
delete message.sort;
new Message(message, {
applicationContext,
}).validate();
return message;
});
} catch (e) {
console.log('Error migrating message records:', e);
exit(); //???
}

const migratedItems = applyMessageChanges({ items: results });

if (dryRun != true) {
try {
await updateRecords(applicationContext, migratedItems);
} catch (e) {
console.log('Error writing migrated message records to dynamo:', e);
exit(); //???
}
}
}
})();
148 changes: 148 additions & 0 deletions scripts/run-once-scripts/add-gsis-to-work-items.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// usage: npx ts-node --transpile-only scripts/run-once-scripts/add-gsis-to-work-items.ts

import { createApplicationContext } from '../../web-api/src/applicationContext';
import { scan } from '../../web-api/src/persistence/dynamodbClientService';
import { TDynamoRecord } from '../../web-api/src/persistence/dynamo/dynamoTypes';
import { updateRecords } from 'scripts/run-once-scripts/scriptHelper';
import { get } from 'lodash';
import { formatResults } from '@web-api/persistence/elasticsearch/searchClient';
import { WorkItem } from '@shared/business/entities/WorkItem';
import { exit } from 'process';

// const findWorkItems = async ({ applicationContext }) => {
// const result = await scan({
// ExpressionAttributeValues: {
// ':pk_prefix': 'case|',
// ':sk_prefix': 'work-item|',
// },
// FilterExpression:
// 'begins_with(pk, :pk_prefix) AND begins_with(sk, :sk_prefix)',
// applicationContext,
// });
// return result;
// };

const migrateItems = items => {
for (const item of items) {
if (!item.completedAt && (item.inProgress || item.caseIsInProgress)) {
item.gsiUserBox = item.assigneeId
? `assigneeId|inProgress|${item.assigneeId}`
: undefined;
item.gsiSectionBox = item.section
? `section|inProgress|${item.section}`
: undefined;
} else if (!item.completedAt) {
item.gsiUserBox = item.assigneeId
? `assigneeId|inbox|${item.assigneeId}`
: undefined;
item.gsiSectionBox = item.section
? `section|inbox|${item.section}`
: undefined;
}
item.gsi2pk = undefined;
}

return items as unknown as TDynamoRecord[];
};

(async () => {
const dryRun = process.argv.slice(2)[0] || true;

const applicationContext = createApplicationContext({});
const searchParameters = {
body: {
query: {
bool: {
must: [
{
exists: {
field: 'section.S',
},
},
],
},
},
},
index: 'efcms-work-item',
size: 10000,
};

const index = searchParameters.index || '';
const query = searchParameters.body?.query || {};
const size = searchParameters.size;

let countQ;
try {
countQ = await applicationContext.getSearchClient().count({
body: {
query,
},
index,
});

console.log('countQ', countQ);
} catch (searchError) {
applicationContext.logger.error(searchError);
throw new Error('Search client encountered an error.');
}

const expected = get(countQ, 'body.count', 0);

let i = 0;
let search_after = [0];
while (i < expected) {
let searchResults = [];
const chunk = await applicationContext.getSearchClient().search({
_source: [],
body: {
query,
search_after,
// this is the only indexed date field, can we use it to sort?
sort: [{ 'completedAt.S': 'asc' }],
},
index,
size,
});
const hits = get(chunk, 'body.hits.hits', []);

if (hits.length > 0) {
searchResults = searchResults.concat(hits);
search_after = hits[hits.length - 1].sort;
}

i += size; // this avoids an endless loop if expected is somehow greater than the sum of all hits

let { results } = formatResults({
hits: {
hits: searchResults,
total: {
value: searchResults.length,
},
},
});

try {
results = results.map(workItem => {
delete workItem._score;
delete workItem.sort;
new WorkItem(workItem, {
applicationContext,
}).validate();
return workItem;
});
} catch (e) {
console.log('Error migrating message records:', e);
exit(); //???
}

const migratedItems = migrateItems(results);
if (dryRun != true) {
try {
await updateRecords(applicationContext, migratedItems);
} catch (e) {
console.log('Error writing migrated workItem records to dynamo:', e);
exit(); //???
}
}
}
})();
Loading