-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formation): transformation fiches formations initiales
- Loading branch information
Showing
21 changed files
with
806 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { Module } from "@nestjs/common"; | ||
|
||
import { Extraction } from "./extraction"; | ||
import { Extraction } from "@formations-initiales/src/extraction"; | ||
import { Transformation } from "@formations-initiales/src/transformation/infrastructure"; | ||
|
||
@Module({ | ||
imports: [Extraction], | ||
exports: [Extraction], | ||
imports: [Extraction, Transformation], | ||
exports: [Extraction, Transformation], | ||
}) | ||
export class FormationsInitiales { | ||
} |
35 changes: 35 additions & 0 deletions
35
apps/formations-initiales/src/transformation/application-service/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Module } from "@nestjs/common"; | ||
|
||
import { | ||
TransformerFluxOnisep, | ||
} from "@formations-initiales/src/transformation/application-service/transformer-flux-onisep.usecase"; | ||
import { | ||
FormationsInitialesRepository, | ||
} from "@formations-initiales/src/transformation/domain/service/formations-initiales.repository"; | ||
import { Convertir } from "@formations-initiales/src/transformation/domain/service/onisep/convertir.domain-service"; | ||
import { Gateways } from "@formations-initiales/src/transformation/infrastructure/gateway"; | ||
|
||
import { Shared } from "@shared/src"; | ||
|
||
@Module({ | ||
imports: [Gateways, Shared], | ||
providers: [{ | ||
provide: Convertir, | ||
inject: [], | ||
useFactory: (): Convertir => { | ||
return new Convertir(); | ||
}, | ||
}, { | ||
provide: TransformerFluxOnisep, | ||
inject: [ | ||
"FormationsInitialesRepository", | ||
Convertir, | ||
], | ||
useFactory: (formationsInitialesRepository: FormationsInitialesRepository, convertirDomainService: Convertir): TransformerFluxOnisep => { | ||
return new TransformerFluxOnisep(formationsInitialesRepository, convertirDomainService); | ||
}, | ||
}], | ||
exports: [TransformerFluxOnisep], | ||
}) | ||
export class Usecases { | ||
} |
22 changes: 22 additions & 0 deletions
22
...tions-initiales/src/transformation/application-service/transformer-flux-onisep.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { FluxTransformation } from "@formations-initiales/src/transformation/domain/model/flux"; | ||
import { Onisep } from "@formations-initiales/src/transformation/domain/model/onisep"; | ||
import { | ||
FormationsInitialesRepository, | ||
} from "@formations-initiales/src/transformation/domain/service/formations-initiales.repository"; | ||
import { Convertir } from "@formations-initiales/src/transformation/domain/service/onisep/convertir.domain-service"; | ||
|
||
import { Usecase } from "@shared/src/application-service/usecase"; | ||
|
||
export class TransformerFluxOnisep implements Usecase { | ||
constructor( | ||
private readonly formationsInitialesRepository: FormationsInitialesRepository, | ||
private readonly convertir: Convertir, | ||
) { | ||
} | ||
|
||
public async executer(flux: FluxTransformation): Promise<void> { | ||
const contenuDuFlux = await this.formationsInitialesRepository.recuperer<Onisep.Contenu>(flux); | ||
|
||
await this.formationsInitialesRepository.sauvegarder(this.convertir.depuisOnisep(contenuDuFlux), flux); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
apps/formations-initiales/src/transformation/domain/model/1jeune1solution/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export namespace UnJeuneUneSolution { | ||
export type FormationInitiale = { | ||
identifiant: string | ||
intitule: string | ||
duree: string | ||
certification: string | ||
niveauEtudesVise: string | ||
description: string | ||
attendusParcoursup: string | ||
conditionsAcces: string | ||
poursuiteEtudes: string | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
apps/formations-initiales/src/transformation/domain/model/flux.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Flux } from "@shared/src/domain/model/flux"; | ||
|
||
export class FluxTransformation extends Flux { | ||
constructor( | ||
nom: string, | ||
public readonly dossierHistorisation: string, | ||
public readonly extensionFichierBrut: string, | ||
public readonly extensionFichierTransforme: string | ||
) { | ||
super(nom, extensionFichierBrut); | ||
this.dossierHistorisation = dossierHistorisation; | ||
this.extensionFichierBrut = extensionFichierBrut; | ||
this.extensionFichierTransforme = extensionFichierTransforme; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
apps/formations-initiales/src/transformation/domain/model/onisep/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export namespace Onisep { | ||
export type Contenu = { | ||
formations: { formation: Array<Formation> } | ||
} | ||
export type Formation = { | ||
identifiant: string | ||
libelle_complet: string | ||
duree_formation: string | ||
niveau_certification: string | ||
niveau_etudes: { libelle: string } | ||
descriptif_format_court: string | ||
attendus: string | ||
descriptif_acces: string | ||
descriptif_poursuite_etudes: string | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...formations-initiales/src/transformation/domain/service/formations-initiales.repository.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { UnJeuneUneSolution } from "@formations-initiales/src/transformation/domain/model/1jeune1solution"; | ||
import { FluxTransformation } from "@formations-initiales/src/transformation/domain/model/flux"; | ||
|
||
export interface FormationsInitialesRepository { | ||
recuperer<T>(flux: FluxTransformation): Promise<T>; | ||
sauvegarder(formationInitiales: Array<UnJeuneUneSolution.FormationInitiale>, flux: FluxTransformation): Promise<void>; | ||
} |
20 changes: 20 additions & 0 deletions
20
...formations-initiales/src/transformation/domain/service/onisep/convertir.domain-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { UnJeuneUneSolution } from "@formations-initiales//src/transformation/domain/model/1jeune1solution"; | ||
import { Onisep } from "@formations-initiales/src/transformation/domain/model/onisep"; | ||
|
||
export class Convertir { | ||
public depuisOnisep(formations: Onisep.Contenu): Array<UnJeuneUneSolution.FormationInitiale> { | ||
return formations.formations.formation.map((formation) => { | ||
return { | ||
identifiant: formation.identifiant, | ||
intitule: formation.libelle_complet, | ||
duree: formation.duree_formation, | ||
certification: formation.niveau_certification, | ||
niveauEtudesVise: formation.niveau_etudes.libelle, | ||
description: formation.descriptif_format_court, | ||
attendusParcoursup: formation.attendus, | ||
conditionsAcces: formation.descriptif_acces, | ||
poursuiteEtudes: formation.descriptif_poursuite_etudes, | ||
}; | ||
}); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
apps/formations-initiales/src/transformation/infrastructure/configuration/configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { | ||
ConfigurationValidator, | ||
Environment, | ||
SentryConfiguration, | ||
} from "@shared/src/infrastructure/configuration/configuration"; | ||
import { Domaine, LogLevel } from "@shared/src/infrastructure/configuration/logger"; | ||
|
||
type MinioConfiguration = { | ||
ACCESS_KEY: string | ||
HISTORY_DIRECTORY_NAME: string | ||
PORT: number | ||
RAW_BUCKET_NAME: string | ||
SECRET_KEY: string | ||
URL: string | ||
TRANSFORMED_BUCKET_NAME: string | ||
} | ||
|
||
type TaskConfiguration = { | ||
DIRECTORY_NAME: string | ||
FLUX_URL: string | ||
NAME: string | ||
RAW_FILE_EXTENSION: string | ||
TRANSFORMED_FILE_EXTENSION: string | ||
} | ||
|
||
export type Configuration = { | ||
CONTEXT: string | ||
DOMAINE: Domaine | ||
FLOWS: Array<string> | ||
ONISEP: TaskConfiguration | ||
LOGGER_LOG_LEVEL: LogLevel | ||
MINIO: MinioConfiguration | ||
NODE_ENV: Environment | ||
SENTRY: SentryConfiguration | ||
TEMPORARY_DIRECTORY_PATH: string | ||
} | ||
|
||
export class ConfigurationFactory extends ConfigurationValidator { | ||
public static createRoot(): { formationsInitialesTransformation: Configuration } { | ||
return { formationsInitialesTransformation: ConfigurationFactory.create() }; | ||
} | ||
|
||
public static create(): Configuration { | ||
const { getOrError, getOrDefault } = ConfigurationFactory; | ||
const DEFAULT_RAW_BUCKET_NAME = "raw"; | ||
const DEFAULT_MINIO_PORT = "9000"; | ||
const DEFAULT_ONISEP_NAME = "onisep"; | ||
const DEFAULT_LOG_LEVEL = "debug"; | ||
const DEFAULT_HISTORY_DIRECTORY_NAME = "history"; | ||
|
||
return { | ||
CONTEXT: "formations-initiales/transformation", | ||
DOMAINE: "Formations initiales", | ||
FLOWS: [ | ||
getOrError("FORMATIONS_INITIALES_ONISEP_NAME"), | ||
], | ||
ONISEP: { | ||
DIRECTORY_NAME: getOrDefault("FORMATIONS_INITIALES_ONISEP_DIRECTORY_NAME", DEFAULT_ONISEP_NAME), | ||
FLUX_URL: getOrError("FORMATIONS_INITIALES_ONISEP_FLUX_URL"), | ||
NAME: getOrDefault("FORMATIONS_INITIALES_ONISEP_NAME", DEFAULT_ONISEP_NAME), | ||
RAW_FILE_EXTENSION: getOrDefault("FORMATIONS_INITIALES_ONISEP_RAW_FILE_EXTENSION", "xml"), | ||
TRANSFORMED_FILE_EXTENSION: getOrDefault("FORMATIONS_INITIALES_ONISEP_TRANSFORMED_FILE_EXTENSION", "json"), | ||
}, | ||
LOGGER_LOG_LEVEL: getOrDefault("LOGGER_LOG_LEVEL", DEFAULT_LOG_LEVEL) as LogLevel, | ||
MINIO: { | ||
ACCESS_KEY: getOrError("MINIO_ACCESS_KEY"), | ||
HISTORY_DIRECTORY_NAME: getOrDefault("MINIO_HISTORY_DIRECTORY_NAME", DEFAULT_HISTORY_DIRECTORY_NAME), | ||
PORT: Number(getOrDefault("MINIO_PORT", DEFAULT_MINIO_PORT)), | ||
RAW_BUCKET_NAME: getOrDefault("EVENTS_MINIO_RAW_BUCKET_NAME", DEFAULT_RAW_BUCKET_NAME), | ||
SECRET_KEY: getOrError("MINIO_SECRET_KEY"), | ||
URL: getOrError("MINIO_URL"), | ||
TRANSFORMED_BUCKET_NAME: getOrError("EVENTS_MINIO_TRANSFORMED_BUCKET_NAME"), | ||
}, | ||
NODE_ENV: getOrError("NODE_ENV") as Environment, | ||
SENTRY: { | ||
DSN: getOrError("SENTRY_DSN"), | ||
PROJECT: getOrError("npm_package_name"), | ||
RELEASE: getOrError("npm_package_version"), | ||
}, | ||
TEMPORARY_DIRECTORY_PATH: getOrError("TEMPORARY_DIRECTORY_PATH"), | ||
}; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
apps/formations-initiales/src/transformation/infrastructure/configuration/log.decorator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { | ||
ConfigurationFactory, | ||
} from "@formations-initiales/src/transformation/infrastructure/configuration/configuration"; | ||
import { | ||
FormationsInitialesTransformationLoggerStrategy, | ||
} from "@formations-initiales/src/transformation/infrastructure/configuration/logger-strategy"; | ||
|
||
const configuration = ConfigurationFactory.create(); | ||
const loggerStrategy = new FormationsInitialesTransformationLoggerStrategy(configuration); | ||
|
||
export function CommandLog(flowName: string): (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor { | ||
return function (target: unknown, propertyKey: string, descriptor: TypedPropertyDescriptor<() => Promise<void>>): PropertyDescriptor { | ||
const originalMethod = descriptor.value; | ||
|
||
descriptor.value = async function (...args: []): Promise<void> { | ||
try { | ||
loggerStrategy.get(flowName).info(`Starting to transform [${flowName}] flow`); | ||
await originalMethod.apply(this, args); | ||
} catch (e) { | ||
loggerStrategy.get(flowName).fatal({ msg: (<Error>e).message, extra: { stack: (<Error>e).stack } }); | ||
} finally { | ||
loggerStrategy.get(flowName).info(`End of transforming from [${flowName}] flow`); | ||
} | ||
}; | ||
|
||
return descriptor; | ||
}; | ||
} |
36 changes: 36 additions & 0 deletions
36
apps/formations-initiales/src/transformation/infrastructure/configuration/logger-strategy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Configuration } from "@formations-initiales/src/transformation/infrastructure/configuration/configuration"; | ||
|
||
import { | ||
Logger, | ||
LoggerFactory, | ||
LoggerStrategy, | ||
LoggerStrategyError, | ||
} from "@shared/src/infrastructure/configuration/logger"; | ||
|
||
export class FormationsInitialesTransformationLoggerStrategy implements LoggerStrategy { | ||
private readonly loggers: Map<string, Logger>; | ||
|
||
constructor(configuration: Configuration) { | ||
const loggerFactory = new LoggerFactory( | ||
configuration.SENTRY.DSN, | ||
configuration.SENTRY.PROJECT, | ||
configuration.SENTRY.RELEASE, | ||
configuration.NODE_ENV, | ||
configuration.CONTEXT, | ||
configuration.LOGGER_LOG_LEVEL, | ||
configuration.DOMAINE, | ||
); | ||
this.loggers = new Map(); | ||
configuration.FLOWS.forEach((flow) => { | ||
this.loggers.set(flow, loggerFactory.create({ name: flow })); | ||
}); | ||
} | ||
|
||
get(flowName: string): Logger { | ||
const logger = this.loggers.get(flowName); | ||
if (logger) { | ||
return logger; | ||
} | ||
throw new LoggerStrategyError(flowName); | ||
} | ||
} |
Oops, something went wrong.