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

feat. ta høyde for deltaker id i arena_agreement_migration #1238

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ public Optional<LocalDate> findSluttdato() {
.findFirst();
}

public boolean isTiltakDublett() {
return isDublett(eksternIdTiltak);
}

public boolean isDeltakerDublett() {
return isDublett(eksternIdDeltaker);
public boolean isDublett() {
return isDublett(eksternIdTiltak) || isDublett(eksternIdDeltaker);
}

public Optional<UUID> getEksternIdAsUuid() throws IllegalArgumentException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ArenaAgreementMigration {
@Id
private UUID id;
private Integer tiltakgjennomforingId;
private Integer tiltakdeltakerId;
@Enumerated(EnumType.STRING)
private ArenaAgreementMigrationStatus status;
@Enumerated(EnumType.STRING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.time.LocalDate;

public enum ArenaMigrationAction {
HOPP_OVER,
GJENOPPRETT,
OPPRETT,
OPPDATER,
Expand All @@ -21,14 +20,9 @@ public static ArenaMigrationAction map(ArenaAgreementAggregate agreementAggregat
boolean isSluttdatoInTheFuture = agreementAggregate.findSluttdato()
.map(sluttdato -> sluttdato.isAfter(LocalDate.now())).orElse(false);

if (agreementAggregate.isDeltakerDublett()) {
return HOPP_OVER;
}

if (agreementAggregate.isTiltakDublett()) {
if (agreementAggregate.isDublett()) {
return IGNORER;
}

return switch (deltakerstatuskode) {
case GJENN, TILBUD -> isSluttdatoInTheFuture ? OPPRETT : IGNORER;
case null, default -> IGNORER;
Expand All @@ -46,11 +40,7 @@ public static ArenaMigrationAction map(
boolean isSluttdatoIFremtiden = agreementAggregate.findSluttdato()
.map(sluttdato -> sluttdato.isAfter(LocalDate.now())).orElse(false);

if (agreementAggregate.isDeltakerDublett()) {
return HOPP_OVER;
}

if (agreementAggregate.isTiltakDublett()) {
if (agreementAggregate.isDublett()) {
return IGNORER;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import no.nav.tag.tiltaksgjennomforing.avtale.Avtale;

public sealed interface ArenaMigrationProcessResult {
record Skip(ArenaMigrationAction action) implements ArenaMigrationProcessResult {}
record Ignored(ArenaMigrationAction action) implements ArenaMigrationProcessResult {}
record Completed(ArenaMigrationAction action, Avtale avtale) implements ArenaMigrationProcessResult {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public interface ArenaAgreementMigrationRepository extends JpaRepository<ArenaAg
atg.regDato
)
FROM ArenaTiltakgjennomforing atg
LEFT JOIN ArenaTiltakdeltaker atd ON atd.tiltakgjennomforingId = atg.tiltakgjennomforingId
FULL OUTER JOIN ArenaTiltakdeltaker atd ON atd.tiltakgjennomforingId = atg.tiltakgjennomforingId
LEFT JOIN ArenaOrdsFnr aof ON atd.personId = aof.personId
LEFT JOIN ArenaOrdsArbeidsgiver aoa ON atg.arbgivIdArrangor = aoa.arbgivIdArrangor
WHERE atg.tiltakgjennomforingId NOT IN (SELECT tiltakgjennomforingId FROM ArenaAgreementMigration)
WHERE atg.tiltakgjennomforingId NOT IN (SELECT tiltakgjennomforingId FROM ArenaAgreementMigration) OR
atd.tiltakdeltakerId NOT IN (SELECT tiltakdeltakerId FROM ArenaAgreementMigration)
ORDER BY atd.tiltakgjennomforingId LIMIT 5000
""")
List<ArenaAgreementAggregate> findMigrationAgreementAggregates();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public ArenaAgreementProcessingService(
public void process(ArenaAgreementAggregate agreementAggregate) {
UUID eksternId = agreementAggregate.getEksternIdAsUuid().orElse(null);
Integer tiltaksgjennomforingId = agreementAggregate.getTiltakgjennomforingId();
Integer tiltakdeltakerId = agreementAggregate.getTiltakdeltakerId();

try {
ArenaMigrationProcessResult result = agreementAggregate.getEksternIdAsUuid()
Expand All @@ -99,6 +100,7 @@ public void process(ArenaAgreementAggregate agreementAggregate) {
);
saveMigrationStatus(
tiltaksgjennomforingId,
tiltakdeltakerId,
ArenaAgreementMigrationStatus.COMPLETED,
completed.action(),
eksternId,
Expand All @@ -108,19 +110,18 @@ public void process(ArenaAgreementAggregate agreementAggregate) {
case ArenaMigrationProcessResult.Ignored ignored ->
saveMigrationStatus(
tiltaksgjennomforingId,
tiltakdeltakerId,
ArenaAgreementMigrationStatus.COMPLETED,
ignored.action(),
eksternId,
null
);
case ArenaMigrationProcessResult.Skip skip -> {
// Gjør ingenting
}
}
} catch(Exception e) {
log.error("Feil ved prossesering av avtale fra Arena", e);
saveMigrationStatus(
tiltaksgjennomforingId,
tiltakdeltakerId,
ArenaAgreementMigrationStatus.FAILED,
null,
eksternId,
Expand All @@ -131,6 +132,7 @@ public void process(ArenaAgreementAggregate agreementAggregate) {

private void saveMigrationStatus(
Integer tiltakgjennomforingId,
Integer tiltakdeltakerId,
ArenaAgreementMigrationStatus status,
ArenaMigrationAction action,
UUID eksternId,
Expand All @@ -140,6 +142,7 @@ private void saveMigrationStatus(
ArenaAgreementMigration.builder()
.id(UUID.randomUUID())
.tiltakgjennomforingId(tiltakgjennomforingId)
.tiltakdeltakerId(tiltakdeltakerId)
.status(status)
.action(action)
.avtaleId(agreementId)
Expand All @@ -152,20 +155,14 @@ private void saveMigrationStatus(
private ArenaMigrationProcessResult updateAvtale(Avtale avtale, ArenaAgreementAggregate agreementAggregate) {
ArenaMigrationAction action = ArenaMigrationAction.map(avtale, agreementAggregate);
switch (action) {
case HOPP_OVER -> {
log.info(
"Avtale har deltaker som er duplett i Arena. Hopper over avtalen. Den vil sannsynligvis bli oppdatert senere."
);
return new ArenaMigrationProcessResult.Skip(action);
}
case IGNORER -> {
log.info(
"Avtale med id {} og status {} har tiltakstatus {}, deltakerstatus {} og tiltaket er {} i Arena. Ignorerer avtalen.",
avtale.getId(),
avtale.getStatus(),
agreementAggregate.getTiltakstatuskode(),
agreementAggregate.getDeltakerstatuskode(),
agreementAggregate.isTiltakDublett() ? "dublett" : "ikke dublett"
agreementAggregate.isDublett() ? "dublett" : "ikke dublett"
);
return new ArenaMigrationProcessResult.Ignored(action);
}
Expand Down Expand Up @@ -218,20 +215,13 @@ private ArenaMigrationProcessResult updateAvtale(Avtale avtale, ArenaAgreementAg
private ArenaMigrationProcessResult createAvtale(ArenaAgreementAggregate agreementAggregate) {
ArenaMigrationAction action = ArenaMigrationAction.map(agreementAggregate);

if (ArenaMigrationAction.HOPP_OVER == action) {
log.info(
"Avtale har deltaker som er duplett i Arena. Hopper over avtalen. Den vil sannsynligvis bli oppdatert senere."
);
return new ArenaMigrationProcessResult.Skip(action);
}

if (ArenaMigrationAction.IGNORER == action) {
log.info(
"Avtale har tiltaksstatus {}, deltakerstatus {}, sluttdato {} og er {} i Arena. Ignorerer avtalen.",
agreementAggregate.getTiltakstatuskode(),
agreementAggregate.getDeltakerstatuskode(),
agreementAggregate.findSluttdato().orElse(null),
agreementAggregate.isTiltakDublett() ? "dublett" : "ikke dublett"
agreementAggregate.isDublett() ? "dublett" : "ikke dublett"
);
return new ArenaMigrationProcessResult.Ignored(action);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE arena_agreement_migration ADD COLUMN tiltakdeltaker_id int;

UPDATE arena_agreement_migration aam
SET tiltakdeltaker_id = (
SELECT tiltakdeltaker_id
FROM arena_tiltakdeltaker
WHERE tiltakgjennomforing_id = aam.tiltakgjennomforing_id
LIMIT 1
);

ALTER TABLE arena_agreement_migration
ADD CONSTRAINT arena_agreement_migration_tiltakdeltaker_id_fkey
FOREIGN KEY (tiltakdeltaker_id)
REFERENCES arena_tiltakdeltaker(tiltakdeltaker_id);
Loading