Skip to content

Commit

Permalink
feat. ta høyde for deltaker id i arena_agreement_migration
Browse files Browse the repository at this point in the history
Det kan være flere deltakere på et tiltak. Derfor må vi ta høyde for dette.
  • Loading branch information
eirikv committed Dec 11, 2024
1 parent 59019d0 commit 7cdc665
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
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 @@ -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,6 +110,7 @@ public void process(ArenaAgreementAggregate agreementAggregate) {
case ArenaMigrationProcessResult.Ignored ignored ->
saveMigrationStatus(
tiltaksgjennomforingId,
tiltakdeltakerId,
ArenaAgreementMigrationStatus.COMPLETED,
ignored.action(),
eksternId,
Expand All @@ -121,6 +124,7 @@ public void process(ArenaAgreementAggregate agreementAggregate) {
log.error("Feil ved prossesering av avtale fra Arena", e);
saveMigrationStatus(
tiltaksgjennomforingId,
tiltakdeltakerId,
ArenaAgreementMigrationStatus.FAILED,
null,
eksternId,
Expand All @@ -131,6 +135,7 @@ public void process(ArenaAgreementAggregate agreementAggregate) {

private void saveMigrationStatus(
Integer tiltakgjennomforingId,
Integer tiltakdeltakerId,
ArenaAgreementMigrationStatus status,
ArenaMigrationAction action,
UUID eksternId,
Expand All @@ -140,6 +145,7 @@ private void saveMigrationStatus(
ArenaAgreementMigration.builder()
.id(UUID.randomUUID())
.tiltakgjennomforingId(tiltakgjennomforingId)
.tiltakdeltakerId(tiltakdeltakerId)
.status(status)
.action(action)
.avtaleId(agreementId)
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);

0 comments on commit 7cdc665

Please sign in to comment.