feat: add brief concept party classification
This commit is contained in:
@@ -10,6 +10,8 @@ function mapped(ids: IdMap, sourceId: string, label: string) {
|
||||
}
|
||||
|
||||
export async function clearBoard(client: PoolClient, boardId: string) {
|
||||
await client.query('DELETE FROM osint.brief_concepts WHERE board_id=$1', [boardId])
|
||||
await client.query('DELETE FROM osint.level_briefs WHERE board_id=$1', [boardId])
|
||||
await client.query('DELETE FROM osint.metadata_fields WHERE board_id=$1', [boardId])
|
||||
await client.query('DELETE FROM osint.exhibits WHERE board_id=$1', [boardId])
|
||||
await client.query('UPDATE osint.boards SET revision=0,updated_at=NOW() WHERE id=$1', [boardId])
|
||||
@@ -65,6 +67,25 @@ export async function cloneBoard(client: PoolClient, sourceBoardId: string, targ
|
||||
'INSERT INTO osint.event_exhibits (exhibit_id,title,narrative_text,occurred_at) VALUES ($1,$2,$3,$4)',
|
||||
[mapped(exhibitIds, row.exhibit_id, 'event'), row.title, row.narrative_text, row.occurred_at])
|
||||
|
||||
const parties = await client.query<{ exhibit_id: string; party_kind: string; display_name: string; summary: string }>(
|
||||
`SELECT p.* FROM osint.party_exhibits p JOIN osint.exhibits e ON e.id=p.exhibit_id WHERE e.board_id=$1`, [sourceBoardId])
|
||||
for (const row of parties.rows) await client.query(
|
||||
'INSERT INTO osint.party_exhibits (exhibit_id,party_kind,display_name,summary) VALUES ($1,$2,$3,$4)',
|
||||
[mapped(exhibitIds, row.exhibit_id, 'party'), row.party_kind, row.display_name, row.summary])
|
||||
const people = await client.query<{ exhibit_id: string; given_name: string | null; family_name: string | null }>(
|
||||
`SELECT p.* FROM osint.person_parties p JOIN osint.exhibits e ON e.id=p.exhibit_id WHERE e.board_id=$1`, [sourceBoardId])
|
||||
for (const row of people.rows) await client.query('INSERT INTO osint.person_parties (exhibit_id,given_name,family_name) VALUES ($1,$2,$3)',
|
||||
[mapped(exhibitIds, row.exhibit_id, 'person'), row.given_name, row.family_name])
|
||||
const organizations = await client.query<{ exhibit_id: string; organization_kind: string }>(
|
||||
`SELECT o.* FROM osint.organization_parties o JOIN osint.exhibits e ON e.id=o.exhibit_id WHERE e.board_id=$1`, [sourceBoardId])
|
||||
for (const row of organizations.rows) await client.query('INSERT INTO osint.organization_parties (exhibit_id,organization_kind) VALUES ($1,$2)',
|
||||
[mapped(exhibitIds, row.exhibit_id, 'organization'), row.organization_kind])
|
||||
const aliases = await client.query<{ party_exhibit_id: string; alias: string; sort_order: number }>(
|
||||
`SELECT a.party_exhibit_id,a.alias,a.sort_order FROM osint.party_aliases a JOIN osint.exhibits e ON e.id=a.party_exhibit_id
|
||||
WHERE e.board_id=$1 ORDER BY a.sort_order`, [sourceBoardId])
|
||||
for (const row of aliases.rows) await client.query('INSERT INTO osint.party_aliases (id,party_exhibit_id,alias,sort_order) VALUES ($1,$2,$3,$4)',
|
||||
[randomUUID(), mapped(exhibitIds, row.party_exhibit_id, 'party alias'), row.alias, row.sort_order])
|
||||
|
||||
const blocks = await client.query<{ document_exhibit_id: string; sort_order: number; content: string }>(
|
||||
`SELECT b.document_exhibit_id,b.sort_order,b.content FROM osint.document_content_blocks b
|
||||
JOIN osint.exhibits e ON e.id=b.document_exhibit_id WHERE e.board_id=$1 ORDER BY b.sort_order`, [sourceBoardId])
|
||||
@@ -113,6 +134,18 @@ export async function cloneBoard(client: PoolClient, sourceBoardId: string, targ
|
||||
(board_id,event_exhibit_id,evidence_exhibit_id,sort_order,note) VALUES ($1,$2,$3,$4,$5)`,
|
||||
[targetBoardId, mapped(exhibitIds, row.event_exhibit_id, 'event'), mapped(exhibitIds, row.evidence_exhibit_id, 'event evidence'), row.sort_order, row.note])
|
||||
|
||||
const partyEvidence = await client.query<{ party_exhibit_id: string; evidence_exhibit_id: string; sort_order: number; note: string | null }>(
|
||||
'SELECT party_exhibit_id,evidence_exhibit_id,sort_order,note FROM osint.party_evidence WHERE board_id=$1', [sourceBoardId])
|
||||
for (const row of partyEvidence.rows) await client.query(`INSERT INTO osint.party_evidence
|
||||
(board_id,party_exhibit_id,evidence_exhibit_id,sort_order,note) VALUES ($1,$2,$3,$4,$5)`,
|
||||
[targetBoardId, mapped(exhibitIds, row.party_exhibit_id, 'party'), mapped(exhibitIds, row.evidence_exhibit_id, 'party evidence'), row.sort_order, row.note])
|
||||
const partyRelationships = await client.query<{ relationship_type_id: string; from_party_exhibit_id: string; to_party_exhibit_id: string; note: string | null }>(
|
||||
'SELECT relationship_type_id,from_party_exhibit_id,to_party_exhibit_id,note FROM osint.party_relationships WHERE board_id=$1', [sourceBoardId])
|
||||
for (const row of partyRelationships.rows) await client.query(`INSERT INTO osint.party_relationships
|
||||
(id,board_id,relationship_type_id,from_party_exhibit_id,to_party_exhibit_id,note) VALUES ($1,$2,$3,$4,$5,$6)`,
|
||||
[randomUUID(), targetBoardId, row.relationship_type_id, mapped(exhibitIds, row.from_party_exhibit_id, 'related party'),
|
||||
mapped(exhibitIds, row.to_party_exhibit_id, 'related party'), row.note])
|
||||
|
||||
const connections = await client.query<{ connection_type_id: string; from_exhibit_id: string; to_exhibit_id: string; label: string | null }>(
|
||||
'SELECT connection_type_id,from_exhibit_id,to_exhibit_id,label FROM osint.exhibit_connections WHERE board_id=$1', [sourceBoardId])
|
||||
for (const row of connections.rows) await client.query(`INSERT INTO osint.exhibit_connections
|
||||
@@ -127,5 +160,15 @@ export async function cloneBoard(client: PoolClient, sourceBoardId: string, targ
|
||||
[mapped(exhibitIds, row.exhibit_id, 'sourced exhibit'), mapped(exhibitIds, row.source_document_exhibit_id, 'source document'),
|
||||
row.source_region_id ? mapped(regionIds, row.source_region_id, 'source region') : null])
|
||||
|
||||
const brief = await client.query<{ body: string }>('SELECT body FROM osint.level_briefs WHERE board_id=$1', [sourceBoardId])
|
||||
if (brief.rows[0]) await client.query('INSERT INTO osint.level_briefs (board_id,body) VALUES ($1,$2)', [targetBoardId, brief.rows[0].body])
|
||||
const concepts = await client.query<{
|
||||
id: string; label: string; context_text: string; sort_order: number; expected_party_kind: string | null; resolved_party_exhibit_id: string | null
|
||||
}>('SELECT id,label,context_text,sort_order,expected_party_kind,resolved_party_exhibit_id FROM osint.brief_concepts WHERE board_id=$1 ORDER BY sort_order,id', [sourceBoardId])
|
||||
for (const row of concepts.rows) await client.query(`INSERT INTO osint.brief_concepts
|
||||
(id,board_id,origin_concept_id,label,context_text,sort_order,expected_party_kind,resolved_party_exhibit_id) VALUES ($1,$2,$3,$4,$5,$6,$7,$8)`,
|
||||
[randomUUID(), targetBoardId, row.id, row.label, row.context_text, row.sort_order, row.expected_party_kind,
|
||||
row.resolved_party_exhibit_id ? mapped(exhibitIds, row.resolved_party_exhibit_id, 'resolved party') : null])
|
||||
|
||||
return exhibitIds
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user