diff --git a/packages/courDeCassation/src/connector/fetcher/sderFetcher.ts b/packages/courDeCassation/src/connector/fetcher/sderFetcher.ts index d55604561..35b63c164 100644 --- a/packages/courDeCassation/src/connector/fetcher/sderFetcher.ts +++ b/packages/courDeCassation/src/connector/fetcher/sderFetcher.ts @@ -23,7 +23,7 @@ const sderFetcher = { }: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }) { const courtDecisions = await sderApi.fetchDecisionsToPseudonymiseBetween({ startDate, @@ -46,7 +46,7 @@ const sderFetcher = { }: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }) { const courtDecisions = await sderApi.fetchDecisionsToPseudonymiseBetweenDateCreation( { diff --git a/packages/courDeCassation/src/connector/mapper/extractors/extractRoute/extractRoute.ts b/packages/courDeCassation/src/connector/mapper/extractors/extractRoute/extractRoute.ts index 8811bedde..437714bf2 100644 --- a/packages/courDeCassation/src/connector/mapper/extractors/extractRoute/extractRoute.ts +++ b/packages/courDeCassation/src/connector/mapper/extractors/extractRoute/extractRoute.ts @@ -3,6 +3,7 @@ import { documentType } from '@label/core'; import { extractRouteForJurica } from './extractRouteForJurica'; import { extractRouteForJurinet } from './extractRouteForJurinet'; import { extractRouteForJuritj } from './extractRouteForJuritj'; +import { extractRouteForJuritcom } from './extractRouteForJuritcom'; export { extractRoute }; @@ -25,31 +26,32 @@ function extractRoute( ): documentType['route'] { let route: documentType['route'] = 'default'; - switch (source) { - case 'jurinet': - try { - route = extractRouteForJurinet({ ...routeInfos }); - } catch (e) { - logger.error({ operationName: 'extractRouteForJurinet', msg: `${e}` }); - route = 'exhaustive'; - } - break; - case 'jurica': - try { - route = extractRouteForJurica({ ...routeInfos }); - } catch (e) { - logger.error({ operationName: 'extractRouteForJurica', msg: `${e}` }); - route = 'exhaustive'; - } - break; - case 'juritj': - try { - route = extractRouteForJuritj({ ...routeInfos }); - } catch (e) { - logger.error({ operationName: 'extractRouteForJuritj', msg: `${e}` }); - route = 'exhaustive'; - } - break; + // TODO : use dbsder-api-types + enum Sources { + CC = 'jurinet', + CA = 'jurica', + TJ = 'juritj', + TCOM = 'juritcom', + } + + const extractRouteFunctions = { + [Sources.CC]: extractRouteForJurinet, + [Sources.CA]: extractRouteForJurica, + [Sources.TJ]: extractRouteForJuritj, + [Sources.TCOM]: extractRouteForJuritcom, + }; + + try { + if (source in extractRouteFunctions) { + route = extractRouteFunctions[source as Sources]({ + ...routeInfos, + }); + } else { + throw new Error('Source non prise en charge'); + } + } catch (e) { + logger.error({ operationName: `extractRouteFor ${source}`, msg: `${e}` }); + route = 'exhaustive'; } if ( diff --git a/packages/courDeCassation/src/connector/mapper/extractors/extractRoute/extractRouteForJuritcom.ts b/packages/courDeCassation/src/connector/mapper/extractors/extractRoute/extractRouteForJuritcom.ts new file mode 100644 index 000000000..c1da2c044 --- /dev/null +++ b/packages/courDeCassation/src/connector/mapper/extractors/extractRoute/extractRouteForJuritcom.ts @@ -0,0 +1,18 @@ +import { documentType } from '@label/core'; + +export { extractRouteForJuritcom }; + +function extractRouteForJuritcom({}: { + session: documentType['decisionMetadata']['session']; + solution: documentType['decisionMetadata']['solution']; + parties: documentType['decisionMetadata']['parties']; + publicationCategory: documentType['publicationCategory']; + chamberName: documentType['decisionMetadata']['chamberName']; + civilMatterCode: documentType['decisionMetadata']['civilMatterCode']; + civilCaseCode: documentType['decisionMetadata']['civilCaseCode']; + criminalCaseCode: documentType['decisionMetadata']['criminalCaseCode']; + NACCode: documentType['decisionMetadata']['NACCode']; + endCaseCode: documentType['decisionMetadata']['endCaseCode']; +}): documentType['route'] { + return 'exhaustive'; +} diff --git a/packages/courDeCassation/src/scripts/autoImportDocumentsFromSder.ts b/packages/courDeCassation/src/scripts/autoImportDocumentsFromSder.ts index 938f221e9..cf9149550 100644 --- a/packages/courDeCassation/src/scripts/autoImportDocumentsFromSder.ts +++ b/packages/courDeCassation/src/scripts/autoImportDocumentsFromSder.ts @@ -56,7 +56,7 @@ function parseArgv() { sources: { demandOption: false, description: - 'sources (jurinet, jurica or juritj) of the decisions you want to import', + 'sources (jurinet, jurica, juritj or juritcom) of the decisions you want to import', type: 'string', }, }) diff --git a/packages/courDeCassation/src/scripts/importSpecificDocumentFromSder.ts b/packages/courDeCassation/src/scripts/importSpecificDocumentFromSder.ts index 70ffe5b47..cca7a23d7 100644 --- a/packages/courDeCassation/src/scripts/importSpecificDocumentFromSder.ts +++ b/packages/courDeCassation/src/scripts/importSpecificDocumentFromSder.ts @@ -44,7 +44,7 @@ function parseArgv() { source: { demandOption: true, description: - 'source (jurinet, jurica or juritj) of the document you want to import', + 'source (jurinet, jurica, juritj, juritcom) of the document you want to import', type: 'string', }, keepLabelTreatments: { diff --git a/packages/courDeCassation/src/sderApi/sderApiType.ts b/packages/courDeCassation/src/sderApi/sderApiType.ts index 78ff3a6ee..d44ddc429 100644 --- a/packages/courDeCassation/src/sderApi/sderApiType.ts +++ b/packages/courDeCassation/src/sderApi/sderApiType.ts @@ -15,12 +15,12 @@ type sderApiType = { fetchDecisionsToPseudonymiseBetween: (param: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }) => Promise>; fetchDecisionsToPseudonymiseBetweenDateCreation: (param: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }) => Promise>; fetchCourtDecisionBySourceIdAndSourceName: (param: { sourceId: decisionType['sourceId']; diff --git a/packages/generic/backend/src/lib/connector/buildConnector.ts b/packages/generic/backend/src/lib/connector/buildConnector.ts index c41e2c890..b161e34b7 100644 --- a/packages/generic/backend/src/lib/connector/buildConnector.ts +++ b/packages/generic/backend/src/lib/connector/buildConnector.ts @@ -19,7 +19,13 @@ import { buildPreAssignator } from '../preAssignator'; export { buildConnector }; -// define sources enum to import documents from alla sources +// TODO : use dbsder-api-types ? +enum Sources { + CC = 'jurinet', + CA = 'jurica', + TJ = 'juritj', + TCOM = 'juritcom', +} function buildConnector(connectorConfig: connectorConfigType) { return { @@ -252,37 +258,31 @@ function buildConnector(connectorConfig: connectorConfigType) { const endDate = new Date(dateBuilder.daysAgo(daysAgo)); try { const newCourtDecisions: decisionType[] = []; - if (!sources || sources.includes('jurinet')) { - const newJurinetDecisions = await connectorConfig.fetchDecisionsToPseudonymiseBetween( - { - startDate, - endDate, - source: 'jurinet', - }, - ); - newJurinetDecisions && newCourtDecisions.push(...newJurinetDecisions); - } - if (!sources || sources.includes('jurica')) { - const newJuricaDecisions = await connectorConfig.fetchDecisionsToPseudonymiseBetween( - { - startDate, - endDate, - source: 'jurica', - }, - ); - newJuricaDecisions && newCourtDecisions.push(...newJuricaDecisions); - } - if (!sources || sources.includes('juritj')) { - const newJuritjDecisions = await connectorConfig.fetchDecisionsToPseudonymiseBetween( - { - startDate, - endDate, - source: 'juritj', - }, - ); - newJuritjDecisions && newCourtDecisions.push(...newJuritjDecisions); + if (sources) { + sources.forEach(async (source) => { + const newDecisionsForSource = await connectorConfig.fetchDecisionsToPseudonymiseBetween( + { + startDate, + endDate, + source: source, + }, + ); + newDecisionsForSource && + newCourtDecisions.push(...newDecisionsForSource); + }); + } else { + for (const source of Object.values(Sources)) { + const newDecisionsForSource = await connectorConfig.fetchDecisionsToPseudonymiseBetween( + { + startDate, + endDate, + source: source, + }, + ); + newDecisionsForSource && + newCourtDecisions.push(...newDecisionsForSource); + } } - logger.log({ operationName: 'importNewDocuments', msg: `${newCourtDecisions.length} ${ @@ -446,110 +446,43 @@ function buildConnector(connectorConfig: connectorConfigType) { }); const newCourtDecisions = []; - try { - logger.log({ - operationName: 'importDocumentsSinceOrBetween', - msg: `Fetching ${connectorConfig.name} jurinet documents...`, - }); - const newJurinetCourtDecisions = - (byDateCreation - ? await connectorConfig.fetchDecisionsToPseudonymiseBetweenDateCreation( - { - startDate: new Date(dateBuilder.daysAgo(fromDaysAgo)), - endDate: toDaysAgo - ? new Date(dateBuilder.daysAgo(toDaysAgo)) - : new Date(), - source: 'jurinet', - }, - ) - : await connectorConfig.fetchDecisionsToPseudonymiseBetween({ - startDate: new Date(dateBuilder.daysAgo(fromDaysAgo)), - endDate: toDaysAgo - ? new Date(dateBuilder.daysAgo(toDaysAgo)) - : new Date(), - source: 'jurinet', - })) ?? []; - logger.log({ - operationName: 'importDocumentsSinceOrBetween', - msg: `${newJurinetCourtDecisions.length} ${connectorConfig.name} court decisions fetched from jurinet!`, - }); - newCourtDecisions.push(...newJurinetCourtDecisions); - } catch (error) { - logger.error({ - operationName: 'importDocumentsSinceOrBetween', - msg: 'Error', - data: error as Record, - }); - } - try { - logger.log({ - operationName: 'importDocumentsSinceOrBetween', - msg: `Fetching ${connectorConfig.name} jurica documents...`, - }); - const newJuricaCourtDecisions = - (byDateCreation - ? await connectorConfig.fetchDecisionsToPseudonymiseBetweenDateCreation( - { - startDate: new Date(dateBuilder.daysAgo(fromDaysAgo)), - endDate: toDaysAgo - ? new Date(dateBuilder.daysAgo(toDaysAgo)) - : new Date(), - source: 'jurica', - }, - ) - : await connectorConfig.fetchDecisionsToPseudonymiseBetween({ - startDate: new Date(dateBuilder.daysAgo(fromDaysAgo)), - endDate: toDaysAgo - ? new Date(dateBuilder.daysAgo(toDaysAgo)) - : new Date(), - source: 'jurica', - })) ?? []; - logger.log({ - operationName: 'importDocumentsSinceOrBetween', - msg: `${newJuricaCourtDecisions.length} ${connectorConfig.name} court decisions fetched from jurica!`, - }); - newCourtDecisions.push(...newJuricaCourtDecisions); - } catch (error) { - logger.error({ - operationName: 'importDocumentsSinceOrBetween', - msg: 'Error', - data: error as Record, - }); - } - try { - logger.log({ - operationName: 'importDocumentsSinceOrBetween', - msg: `Fetching ${connectorConfig.name} juritj documents...`, - }); - const newJuritjCourtDecisions = - (byDateCreation - ? await connectorConfig.fetchDecisionsToPseudonymiseBetweenDateCreation( - { + + for (const source of Object.values(Sources)) { + try { + logger.log({ + operationName: 'importDocumentsSinceOrBetween', + msg: `Fetching ${connectorConfig.name} ${source} documents...`, + }); + const newCourtDecisionsBySource = + (byDateCreation + ? await connectorConfig.fetchDecisionsToPseudonymiseBetweenDateCreation( + { + startDate: new Date(dateBuilder.daysAgo(fromDaysAgo)), + endDate: toDaysAgo + ? new Date(dateBuilder.daysAgo(toDaysAgo)) + : new Date(), + source: source, + }, + ) + : await connectorConfig.fetchDecisionsToPseudonymiseBetween({ startDate: new Date(dateBuilder.daysAgo(fromDaysAgo)), endDate: toDaysAgo ? new Date(dateBuilder.daysAgo(toDaysAgo)) : new Date(), - source: 'juritj', - }, - ) - : await connectorConfig.fetchDecisionsToPseudonymiseBetween({ - startDate: new Date(dateBuilder.daysAgo(fromDaysAgo)), - endDate: toDaysAgo - ? new Date(dateBuilder.daysAgo(toDaysAgo)) - : new Date(), - source: 'juritj', - })) ?? []; - logger.log({ - operationName: 'importDocumentsSinceOrBetween', - msg: `${newJuritjCourtDecisions.length} ${connectorConfig.name} court decisions fetched from juritj!`, - }); - newCourtDecisions.push(...newJuritjCourtDecisions); - } catch (error) { - logger.error({ - operationName: 'importDocumentsSinceOrBetween', - msg: 'Error', - data: error as Record, - }); + source: source, + })) ?? []; + logger.log({ + operationName: 'importDocumentsSinceOrBetween', + msg: `${newCourtDecisionsBySource.length} ${connectorConfig.name} court decisions fetched from ${source}!`, + }); + newCourtDecisions.push(...newCourtDecisionsBySource); + } catch (error) { + logger.error({ + operationName: 'importDocumentsSinceOrBetween', + msg: 'Error', + data: error as Record, + }); + } } const documents = [] as documentType[]; for (const courtDecision of newCourtDecisions) { @@ -594,86 +527,35 @@ function buildConnector(connectorConfig: connectorConfigType) { )} & chambers=${chambers.join(',')}`, }); const newCourtDecisions = []; - try { - logger.log({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: `Fetching ${connectorConfig.name} jurinet documents...`, - }); - const newJurinetCourtDecisions = - (await connectorConfig.fetchAllDecisionsBySourceAndJurisdictionsAndChambersBetween( - { - startDate: from, - endDate: to, - source: 'jurinet', - jurisdictions, - chambers, - }, - )) ?? []; - logger.log({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: `${newJurinetCourtDecisions.length} ${connectorConfig.name} court decisions fetched from jurinet!`, - }); - newCourtDecisions.push(...newJurinetCourtDecisions); - } catch (error) { - logger.error({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: 'Error', - data: error as Record, - }); - } - try { - logger.log({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: `Fetching ${connectorConfig.name} jurica documents...`, - }); - const newJuricaCourtDecisions = - (await connectorConfig.fetchAllDecisionsBySourceAndJurisdictionsAndChambersBetween( - { - startDate: from, - endDate: to, - source: 'jurica', - jurisdictions, - chambers, - }, - )) ?? []; - logger.log({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: `${newJuricaCourtDecisions.length} ${connectorConfig.name} court decisions fetched from jurica!`, - }); - newCourtDecisions.push(...newJuricaCourtDecisions); - logger.log({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: `Fetching ${connectorConfig.name} juritj documents...`, - }); - } catch (error) { - logger.error({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: 'Error', - data: error as Record, - }); - } - try { - const newJuritjCourtDecisions = - (await connectorConfig.fetchAllDecisionsBySourceAndJurisdictionsAndChambersBetween( - { - startDate: from, - endDate: to, - source: 'juritj', - jurisdictions, - chambers, - }, - )) ?? []; - logger.log({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: `${newJuritjCourtDecisions.length} ${connectorConfig.name} court decisions fetched from juritj!`, - }); - newCourtDecisions.push(...newJuritjCourtDecisions); - } catch (error) { - logger.error({ - operationName: 'importDocumentsByJurisdictionBetween', - msg: 'Error', - data: error as Record, - }); + + for (const source of Object.values(Sources)) { + try { + logger.log({ + operationName: 'importDocumentsByJurisdictionBetween', + msg: `Fetching ${connectorConfig.name} ${source} documents...`, + }); + const newCourtDecisionsBySource = + (await connectorConfig.fetchAllDecisionsBySourceAndJurisdictionsAndChambersBetween( + { + startDate: from, + endDate: to, + source: source, + jurisdictions, + chambers, + }, + )) ?? []; + logger.log({ + operationName: 'importDocumentsByJurisdictionBetween', + msg: `${newCourtDecisionsBySource.length} ${connectorConfig.name} court decisions fetched from ${source}!`, + }); + newCourtDecisions.push(...newCourtDecisionsBySource); + } catch (error) { + logger.error({ + operationName: 'importDocumentsByJurisdictionBetween', + msg: 'Error', + data: error as Record, + }); + } } const documents = [] as documentType[]; for (const courtDecision of newCourtDecisions) { diff --git a/packages/generic/backend/src/lib/connector/buildFakeConnector.ts b/packages/generic/backend/src/lib/connector/buildFakeConnector.ts index 1b4300fca..5b0341d84 100644 --- a/packages/generic/backend/src/lib/connector/buildFakeConnector.ts +++ b/packages/generic/backend/src/lib/connector/buildFakeConnector.ts @@ -98,7 +98,7 @@ async function buildFakeConnectorWithNDecisions( }: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }) { return courtDecisions.filter((courtDecision) => { if (!courtDecision.dateDecision) { @@ -120,7 +120,7 @@ async function buildFakeConnectorWithNDecisions( }: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }) { return courtDecisions.filter((courtDecision) => { if (!courtDecision.dateCreation) { diff --git a/packages/generic/backend/src/lib/connector/connectorConfigType.ts b/packages/generic/backend/src/lib/connector/connectorConfigType.ts index c054fef56..1b96b8e5b 100644 --- a/packages/generic/backend/src/lib/connector/connectorConfigType.ts +++ b/packages/generic/backend/src/lib/connector/connectorConfigType.ts @@ -8,7 +8,7 @@ type connectorConfigType = { fetchAllDecisionsBySourceAndJurisdictionsAndChambersBetween: (param: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; jurisdictions: string[]; chambers: string[]; }) => Promise; @@ -23,12 +23,12 @@ type connectorConfigType = { fetchDecisionsToPseudonymiseBetween(param: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }): Promise; fetchDecisionsToPseudonymiseBetweenDateCreation(param: { startDate: Date; endDate: Date; - source: 'jurinet' | 'jurica' | 'juritj'; + source: string; }): Promise; updateDocumentsLoadedStatus: (param: { documents: documentType[]; diff --git a/packages/generic/backend/src/modules/statistic/service/fetchExtremumDates/fetchExtremumDates.ts b/packages/generic/backend/src/modules/statistic/service/fetchExtremumDates/fetchExtremumDates.ts index 9cf04764e..545543414 100644 --- a/packages/generic/backend/src/modules/statistic/service/fetchExtremumDates/fetchExtremumDates.ts +++ b/packages/generic/backend/src/modules/statistic/service/fetchExtremumDates/fetchExtremumDates.ts @@ -7,8 +7,9 @@ async function fetchExtremumDates() { const statisticRepository = buildStatisticRepository(); const treatmentRepository = buildTreatmentRepository(); + // find all available sources or use dbsder-api-types const extremumDatesInStatistics = await statisticRepository.findExtremumTreatmentDateBySources( - ['jurinet', 'jurica', 'juritj'], + ['jurinet', 'jurica', 'juritj', 'juritcom'], ); const extremumDatesInTreatments = await treatmentRepository.findExtremumLastUpdateDateBySources( diff --git a/packages/generic/client/src/pages/Admin/PreAssignDocuments/AddPreAssignationDrawer/AddPreAssignationDrawer.tsx b/packages/generic/client/src/pages/Admin/PreAssignDocuments/AddPreAssignationDrawer/AddPreAssignationDrawer.tsx index 6d738709c..079224f66 100644 --- a/packages/generic/client/src/pages/Admin/PreAssignDocuments/AddPreAssignationDrawer/AddPreAssignationDrawer.tsx +++ b/packages/generic/client/src/pages/Admin/PreAssignDocuments/AddPreAssignationDrawer/AddPreAssignationDrawer.tsx @@ -17,7 +17,8 @@ export { AddWorkingUserDrawer }; const FIELD_WIDTH = 400; const DRAWER_WIDTH = 600; -const sources = ['jurinet', 'jurica', 'juritj']; +// use dbsder-api-types ? +const sources = ['jurinet', 'jurica', 'juritj', 'juritom']; type formErrorType = { source?: boolean;