Skip to content

Commit

Permalink
feat(stages): extraction hellowork (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliebrunetto83 authored Sep 19, 2023
1 parent 8faf728 commit 3ee031d
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ INTERNSHIPS_TRANSFORM_LOG_LEVEL=

INTERNSHIPS_FEATURE_FLIPPING_CHARGEMENT=

INTERNSHIPS_HELLOWORK_DIRECTORY_NAME=
INTERNSHIPS_HELLOWORK_FLUX_URL=
INTERNSHIPS_HELLOWORK_NAME=
INTERNSHIPS_HELLOWORK_RAW_FILE_EXTENSION=
INTERNSHIPS_HELLOWORK_TRANSFORMED_FILE_EXTENSION=

INTERNSHIPS_JOBTEASER_DIRECTORY_NAME=
INTERNSHIPS_JOBTEASER_FLUX_URL=
INTERNSHIPS_JOBTEASER_NAME=
Expand Down
6 changes: 6 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ INTERNSHIPS_TRANSFORM_LOG_LEVEL=debug

INTERNSHIPS_FEATURE_FLIPPING_CHARGEMENT=true

INTERNSHIPS_HELLOWORK_DIRECTORY_NAME=/tmp/
INTERNSHIPS_HELLOWORK_FLUX_URL=https://some.url.com/hellowork
INTERNSHIPS_HELLOWORK_NAME=hellowork
INTERNSHIPS_HELLOWORK_RAW_FILE_EXTENSION=.xml
INTERNSHIPS_HELLOWORK_TRANSFORMED_FILE_EXTENSION=.json

INTERNSHIPS_JOBTEASER_DIRECTORY_NAME=/tmp/
INTERNSHIPS_JOBTEASER_FLUX_URL=https://some.url.com/jobteaser
INTERNSHIPS_JOBTEASER_NAME=jobteaser
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ Démarrer le conteneur (dans l'onglet Resources mettre Qty: 1) web puis l'étein

### Stage

| nom du flux\action | Extract | transform | load |
| :----------------- | :----: | :-------: |:-----:|
| jobteaser | X | X | X |
| stagefr-compresse | X | X | X |
| stagefr-decompresse| X | X | X |
| nom du flux\action | Extract | transform | load |
|:--------------------| :----: | :-------: |:-----:|
| hellowork | X | X | X |
| jobteaser | X | X | X |
| stagefr-compresse | X | X | X |
| stagefr-decompresse | X | X | X |

### Evenement

Expand Down
4 changes: 4 additions & 0 deletions apps/cli/src/command/extract.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import {
ExtractFlowStudapartSubCommand,
} from "@logements/src/extraction/infrastructure/sub-command/extract-flow-studapart.sub-command";

import {
ExtractFlowHelloworkSubCommand,
} from "@stages/src/extraction/infrastructure/sub-command/extract-flow-hellowork.sub-command";
import {
ExtractFlowJobteaserSubCommand,
} from "@stages/src/extraction/infrastructure/sub-command/extract-flow-jobteaser.sub-command";
Expand All @@ -32,6 +35,7 @@ import {
ExtractFlowTousMobilisesSubCommand,
ExtractFlowImmojeuneSubCommand,
ExtractFlowStudapartSubCommand,
ExtractFlowHelloworkSubCommand,
ExtractFlowJobteaserSubCommand,
ExtractFlowStagefrCompressedSubCommand,
ExtractFlowStagefrUncompressedSubCommand,
Expand Down
14 changes: 14 additions & 0 deletions apps/cli/test/cli.module.integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
import {
ChargerFluxStagefrDecompresse,
} from "@stages/src/chargement/application-service/charger-flux-stagefr-decompresse.usecase";
import { ExtraireHellowork } from "@stages/src/extraction/application-service/extraire-hellowork.usecase";
import { ExtraireJobteaser } from "@stages/src/extraction/application-service/extraire-jobteaser.usecase";
import {
ExtraireStagefrCompresse,
Expand All @@ -69,6 +70,7 @@ describe("CliModuleTest", () => {
let cliModule: TestingModule;

context("Lorsque je lance la commande d'extraction", () => {
let extraireHellowork: StubbedClass<ExtraireHellowork>;
let extraireJobteaser: StubbedClass<ExtraireJobteaser>;
let extraireStagefrCompresse: StubbedClass<ExtraireStagefrCompresse>;
let extraireStagefrDecompresse: StubbedClass<ExtraireStagefrDecompresse>;
Expand All @@ -77,6 +79,7 @@ describe("CliModuleTest", () => {
let extraireTousMobilises: StubbedClass<ExtraireFluxEvenementTousMobilises>;

beforeEach(async () => {
extraireHellowork = stubClass(ExtraireHellowork);
extraireJobteaser = stubClass(ExtraireJobteaser);
extraireStagefrCompresse = stubClass(ExtraireStagefrCompresse);
extraireStagefrDecompresse = stubClass(ExtraireStagefrDecompresse);
Expand All @@ -88,6 +91,7 @@ describe("CliModuleTest", () => {
imports: [CliModule, ConfigModule.forRoot({ envFilePath: process.env.NODE_ENV === "test" ? ".env.test" : ".env" })],
})
.overrideProvider(Client).useValue(stubClass(Client))
.overrideProvider(ExtraireHellowork).useValue(extraireHellowork)
.overrideProvider(ExtraireJobteaser).useValue(extraireJobteaser)
.overrideProvider(ExtraireStagefrCompresse).useValue(extraireStagefrCompresse)
.overrideProvider(ExtraireStagefrDecompresse).useValue(extraireStagefrDecompresse)
Expand All @@ -97,6 +101,16 @@ describe("CliModuleTest", () => {
.compile();
});

context("du flux Hellowork", () => {
it("execute la commande", async () => {
// When
await CommandTestFactory.run(cliModule, ["extract", "hellowork"]);

// Then
expect(extraireHellowork.executer).to.have.been.calledOnce;
});
});

context("du flux Jobteaser", () => {
it("execute la commande", async () => {
// When
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export class ConfigurationFactory extends ConfigurationValidator {
EXTRACT_LOG_LEVEL: getOrError("INTERNSHIPS_EXTRACT_LOG_LEVEL") as LogLevel,
FEATURE_FLIPPING_CHARGEMENT: toBoolean(getOrDefault("INTERNSHIPS_FEATURE_FLIPPING_CHARGEMENT", "false")),
FLOWS: [
getOrError("INTERNSHIPS_HELLOWORK_NAME"),
getOrError("INTERNSHIPS_JOBTEASER_NAME"),
getOrError("INTERNSHIPS_STAGEFR_COMPRESSED_NAME"),
getOrError("INTERNSHIPS_STAGEFR_UNCOMPRESSED_NAME"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Usecase } from "@shared/src/application-service/usecase";

import { FluxExtraction } from "@stages/src/extraction/domain/model/flux";
import { ExtraireFluxDomainService } from "@stages/src/extraction/domain/service/extraire-flux.domain-service";

export class ExtraireHellowork implements Usecase {
constructor(private readonly extraireFluxDomainService: ExtraireFluxDomainService) {
}

public executer<T>(flux: Readonly<FluxExtraction>): Promise<void | T> {
return this.extraireFluxDomainService.extraire(flux);
}
}
10 changes: 9 additions & 1 deletion apps/stages/src/extraction/application-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ExtraireFluxDomainService } from "@stages/src/extraction/domain/service
import { FluxRepository } from "@stages/src/extraction/domain/service/flux.repository";
import { Gateways } from "@stages/src/extraction/infrastructure/gateway";

import { ExtraireHellowork } from "./extraire-hellowork.usecase";
import { ExtraireJobteaser } from "./extraire-jobteaser.usecase";
import { ExtraireStagefrCompresse } from "./extraire-stagefr-compresse.usecase";
import { ExtraireStagefrDecompresse } from "./extraire-stagefr-decompresse.usecase";
Expand All @@ -21,6 +22,13 @@ import { ExtraireStagefrDecompresse } from "./extraire-stagefr-decompresse.useca
return new ExtraireFluxDomainService(fluxRepository, dateService);
},
},
{
provide: ExtraireHellowork,
inject: [ExtraireFluxDomainService],
useFactory: (extaireFluxDomainService: ExtraireFluxDomainService): ExtraireHellowork => {
return new ExtraireHellowork(extaireFluxDomainService);
},
},
{
provide: ExtraireJobteaser,
inject: [ExtraireFluxDomainService],
Expand All @@ -43,7 +51,7 @@ import { ExtraireStagefrDecompresse } from "./extraire-stagefr-decompresse.useca
},
},
],
exports: [ExtraireJobteaser, ExtraireStagefrCompresse, ExtraireStagefrDecompresse],
exports: [ExtraireHellowork, ExtraireJobteaser, ExtraireStagefrCompresse, ExtraireStagefrDecompresse],
})
export class Usecases {
}
13 changes: 12 additions & 1 deletion apps/stages/src/extraction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";

import { Usecases } from "@stages/src/extraction/application-service";
import { ExtraireHellowork } from "@stages/src/extraction/application-service/extraire-hellowork.usecase";
import { ExtraireJobteaser } from "@stages/src/extraction/application-service/extraire-jobteaser.usecase";
import {
ExtraireStagefrCompresse,
Expand All @@ -10,6 +11,9 @@ import {
ExtraireStagefrDecompresse,
} from "@stages/src/extraction/application-service/extraire-stagefr-decompresse.usecase";
import { Configuration, ConfigurationFactory } from "@stages/src/extraction/infrastructure/configuration/configuration";
import {
ExtractFlowHelloworkSubCommand,
} from "@stages/src/extraction/infrastructure/sub-command/extract-flow-hellowork.sub-command";
import {
ExtractFlowJobteaserSubCommand,
} from "@stages/src/extraction/infrastructure/sub-command/extract-flow-jobteaser.sub-command";
Expand All @@ -29,6 +33,13 @@ import {
Usecases,
],
providers: [
{
provide: ExtractFlowHelloworkSubCommand,
inject: [ConfigService, ExtraireHellowork],
useFactory: (configurationService: ConfigService, usecase: ExtraireHellowork): ExtractFlowHelloworkSubCommand => {
return new ExtractFlowHelloworkSubCommand(usecase, configurationService.get<Configuration>("stagesExtraction"));
},
},
{
provide: ExtractFlowJobteaserSubCommand,
inject: [ConfigService, ExtraireJobteaser],
Expand All @@ -51,7 +62,7 @@ import {
},
},
],
exports: [ExtractFlowJobteaserSubCommand, ExtractFlowStagefrCompressedSubCommand, ExtractFlowStagefrUncompressedSubCommand],
exports: [ExtractFlowHelloworkSubCommand, ExtractFlowJobteaserSubCommand, ExtractFlowStagefrCompressedSubCommand, ExtractFlowStagefrUncompressedSubCommand],
})
export class Extraction {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type Configuration = {
CONTEXT: string
DOMAINE: Domaine
FLOWS: Array<string>
HELLOWORK: TaskConfiguration
JOBTEASER: TaskConfiguration
LOGGER_LOG_LEVEL: LogLevel
MINIO: MinioConfiguration
Expand All @@ -48,10 +49,17 @@ export class ConfigurationFactory extends ConfigurationValidator {
CONTEXT: "extraction",
DOMAINE: "Stages",
FLOWS: [
getOrError("INTERNSHIPS_HELLOWORK_NAME"),
getOrError("INTERNSHIPS_JOBTEASER_NAME"),
getOrError("INTERNSHIPS_STAGEFR_COMPRESSED_NAME"),
getOrError("INTERNSHIPS_STAGEFR_UNCOMPRESSED_NAME"),
],
HELLOWORK: {
DIRECTORY_NAME: getOrDefault("INTERNSHIPS_HELLOWORK_DIRECTORY_NAME", "hellowork"),
FLUX_URL: getOrError("INTERNSHIPS_HELLOWORK_FLUX_URL"),
NAME: getOrDefault("INTERNSHIPS_HELLOWORK_NAME", "hellowork"),
RAW_FILE_EXTENSION: getOrError("INTERNSHIPS_HELLOWORK_RAW_FILE_EXTENSION"),
},
JOBTEASER: {
DIRECTORY_NAME: getOrDefault("INTERNSHIPS_JOBTEASER_DIRECTORY_NAME", "jobteaser"),
FLUX_URL: getOrError("INTERNSHIPS_JOBTEASER_FLUX_URL"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import {
Logger,
LoggerFactory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export class StagesOnFlowNameStrategy implements FlowStrategy {

public async get(flow: FluxExtraction, logger: Logger): Promise<string> {
switch (flow.nom) {
case this.configuration.HELLOWORK.NAME:
return this.basicFlowHttpClient.pull(flow.url, logger);
case this.configuration.JOBTEASER.NAME:
return this.basicFlowHttpClient.pull(flow.url, logger);
case this.configuration.STAGEFR_COMPRESSED.NAME:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { CommandRunner, SubCommand } from "nest-commander";

import { ExtraireHellowork } from "@stages/src/extraction/application-service/extraire-hellowork.usecase";
import { FluxExtraction } from "@stages/src/extraction/domain/model/flux";
import { Configuration } from "@stages/src/extraction/infrastructure/configuration/configuration";
import { CommandLog } from "@stages/src/extraction/infrastructure/configuration/log.decorator";

@SubCommand({ name: ExtractFlowHelloworkSubCommand.FLOW_NAME })
export class ExtractFlowHelloworkSubCommand extends CommandRunner {
private static readonly FLOW_NAME = "hellowork";

constructor(private readonly usecase: ExtraireHellowork, private readonly configuration: Configuration) {
super();
}

@CommandLog(ExtractFlowHelloworkSubCommand.FLOW_NAME)
public override async run(): Promise<void> {
await this.usecase.executer(
new FluxExtraction(
this.configuration.HELLOWORK.NAME,
this.configuration.HELLOWORK.RAW_FILE_EXTENSION,
this.configuration.MINIO.HISTORY_DIRECTORY_NAME,
this.configuration.HELLOWORK.FLUX_URL,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let flowStrategy: StagesOnFlowNameStrategy;
describe("StagesOnFlowNameStrategyTest", () => {
beforeEach(() => {
const configuration = stubInterface<Configuration>(sinon);
configuration.HELLOWORK.NAME = "hellowork";
configuration.JOBTEASER.NAME = "jobteaser";
configuration.STAGEFR_COMPRESSED.NAME = "stagefr-compresse";
configuration.STAGEFR_UNCOMPRESSED.NAME = "stagefr-decompresse";
Expand All @@ -37,6 +38,19 @@ describe("StagesOnFlowNameStrategyTest", () => {
);
});

context("Lorsque je récupère le contenu du flux Jobteaser", () => {
beforeEach(() => {
flow = new FluxExtraction("hellowork", ".xml", "history", "http://some.url");
});

it("utilise le bon client pour Hellowork", async () => {
await flowStrategy.get(flow, logger);

expect(basicFlowClient.pull).to.have.been.calledOnce;
expect(basicFlowClient.pull).to.have.been.calledWith(url);
});
});

context("Lorsque je récupère le contenu du flux Jobteaser", () => {
beforeEach(() => {
flow = new FluxExtraction("jobteaser", ".xml", "history", "http://some.url");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { expect, StubbedClass, stubClass } from "@test/library";

import { ExtraireHellowork } from "@stages/src/extraction/application-service/extraire-hellowork.usecase";
import { FluxExtraction } from "@stages/src/extraction/domain/model/flux";
import { ExtraireFluxDomainService } from "@stages/src/extraction/domain/service/extraire-flux.domain-service";

const flux: FluxExtraction = new FluxExtraction(
"hellowork",
".xml",
"history",
"http://some.url",
);

let extraireFluxDomainService: StubbedClass<ExtraireFluxDomainService>;
let extraireHellowork: ExtraireHellowork;

describe("ExtraireHelloworkTest", () => {
beforeEach(() => {
extraireFluxDomainService = stubClass(ExtraireFluxDomainService);
extraireHellowork = new ExtraireHellowork(extraireFluxDomainService);
});

context("Lorsque j'extrais le flux en provenant de Hellowork", () => {
it("j'extrais le flux", async () => {
await extraireHellowork.executer(flux);

expect(extraireFluxDomainService.extraire).to.have.been.calledOnce;
expect(extraireFluxDomainService.extraire).to.have.been.calledWith(
new FluxExtraction(
"hellowork",
".xml",
"history",
"http://some.url",
),
);
});
});
});
4 changes: 4 additions & 0 deletions cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"command": "0 7 * * * npm run cli -- extract jobteaser",
"size": "XL"
},
{
"command": "0 4 * * * npm run cli -- extract hellowork",
"size": "XL"
},
{
"command": "30 7 * * * npm run cli -- transform jobteaser",
"size": "XL"
Expand Down

0 comments on commit 3ee031d

Please sign in to comment.