Skip to content

Commit

Permalink
feat. fjerne arena-tiltakssak
Browse files Browse the repository at this point in the history
Topicen til tiltakssak i arena har bare en retention på 90 dager,
mens tiltaksgjennomføring har 5 år. Vi har egentlig ikke noe behov for
data som ligger i tiltakssak, derfor kan vi fjerne denne og bare lese
tiltaksgjennomforinger.
  • Loading branch information
eirikv committed Nov 27, 2024
1 parent 8c85430 commit 89611f0
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 764 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@
public class ArenaKafkaProperties {
private String tiltakdeltakerEndretTopic;
private String tiltakgjennomforingEndretTopic;
private String tiltakssakEndretTopic;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.ArenaKafkaMessage;
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.ArenaTiltakdeltaker;
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.ArenaTiltakgjennomforing;
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.ArenaTiltakssak;
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.Operation;
import no.nav.tag.tiltaksgjennomforing.arena.models.migration.ArenaAgreementAggregate;
import no.nav.tag.tiltaksgjennomforing.arena.service.ArenaAgreementService;
Expand Down Expand Up @@ -63,22 +62,6 @@ public ResponseEntity<?> tiltakgjennomforingEndret(
}
}

@PostMapping("/tiltakssak-endret")
public ResponseEntity<?> tiltakssakEndret(
@RequestBody ArenaKafkaMessage melding
) {
try {
JsonNode payload = Operation.DELETE.getOperation().equals(melding.opType()) ? melding.before() : melding.after();
ArenaTiltakssak tiltaksakEndret = objectMapper.treeToValue(payload, ArenaTiltakssak.class);

String id = tiltaksakEndret.getSakId().toString();
arenaMockKafkaTemplate.send(arenaKafkaProperties.getTiltakssakEndretTopic(), id, melding);
return ResponseEntity.noContent().build();
} catch (Exception e) {
return ResponseEntity.badRequest().body(e.getCause().getMessage());
}
}

@PostMapping("/tiltakdeltaker-endret")
public ResponseEntity<?> tiltakdeltakerEndret(
@RequestBody ArenaKafkaMessage melding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,4 @@ public void arenaTiltakdeltakerEndret(ConsumerRecord<String, String> record) {
arenaEventProcessingService.create(record.key(), record.value());
}
}

@KafkaListener(topics = "${tiltaksgjennomforing.arena.kafka.tiltakssak-endret-topic}", containerFactory = "arenaContainerFactory")
public void arenaTiltaksakEndret(ConsumerRecord<String, String> record) {
if (featureToggleService.isEnabled(FeatureToggle.ARENA_KAFKA)) {
log.info("Mottatt melding for {}: {}", arenaKafkaProperties.getTiltakssakEndretTopic(), record.key());
arenaEventProcessingService.create(record.key(), record.value());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
@AllArgsConstructor
public enum ArenaTable {
TILTAKDELTAKER("SIAMO.TILTAKDELTAKER"),
TILTAKGJENNOMFORING("SIAMO.TILTAKGJENNOMFORING"),
TILTAKSAK("SIAMO.SAK");
TILTAKGJENNOMFORING("SIAMO.TILTAKGJENNOMFORING");

private final String table;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ArenaAgreementMigrationRepository extends JpaRepository<ArenaAg
@Query("""
SELECT
new ArenaAgreementAggregate(
ats.sakId,
atg.sakId,
atg.tiltakgjennomforingId,
atd.tiltakdeltakerId,
aof.personId,
Expand All @@ -31,10 +31,9 @@ public interface ArenaAgreementMigrationRepository extends JpaRepository<ArenaAg
atd.deltakerstatuskode,
atd.datoFra,
atd.datoTil,
ats.regDato
atg.regDato
)
FROM ArenaTiltakgjennomforing atg
LEFT JOIN ArenaTiltakssak ats ON atg.sakId = ats.sakId
LEFT 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ public interface ArenaEventRepository extends JpaRepository<ArenaEvent, UUID> {
FROM ArenaEvent ae
WHERE ae.status = 'RETRY'
ORDER BY (CASE
WHEN ae.arenaTable = 'SIAMO.SAK' THEN 0
WHEN ae.arenaTable = 'SIAMO.TILTAKGJENNOMFORING' THEN 1
WHEN ae.arenaTable = 'SIAMO.TILTAKDELTAKER' THEN 2
ELSE 3
WHEN ae.arenaTable = 'SIAMO.TILTAKGJENNOMFORING' THEN 0
WHEN ae.arenaTable = 'SIAMO.TILTAKDELTAKER' THEN 1
ELSE 2
END) ASC,
ae.retryCount ASC
LIMIT 1000
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,17 @@ public class ArenaEventProcessingService {
private final ObjectMapper objectMapper;
private final ArenaEventRepository arenaEventRepository;
private final TiltakgjennomforingArenaEventProcessingService tiltakgjennomforingArenaEventService;
private final TiltaksakArenaEventProcessingService tiltaksakArenaEventService;
private final TiltakdeltakerArenaEventProcessingService tiltakdeltakerArenaEventService;

public ArenaEventProcessingService(
ObjectMapper objectMapper,
ArenaEventRepository arenaEventRepository,
TiltakgjennomforingArenaEventProcessingService tiltakgjennomforingArenaEventService,
TiltaksakArenaEventProcessingService tiltaksakArenaEventService,
TiltakdeltakerArenaEventProcessingService tiltakdeltakerArenaEventService
) {
this.objectMapper = objectMapper;
this.arenaEventRepository = arenaEventRepository;
this.tiltakgjennomforingArenaEventService = tiltakgjennomforingArenaEventService;
this.tiltaksakArenaEventService = tiltaksakArenaEventService;
this.tiltakdeltakerArenaEventService = tiltakdeltakerArenaEventService;
}

Expand Down Expand Up @@ -157,7 +154,6 @@ public void process(ArenaEvent arenaEvent) {
try {
var result = switch (arenaEvent.getArenaTable()) {
case TILTAKGJENNOMFORING -> tiltakgjennomforingArenaEventService.process(arenaEvent);
case TILTAKSAK -> tiltaksakArenaEventService.process(arenaEvent);
case TILTAKDELTAKER -> tiltakdeltakerArenaEventService.process(arenaEvent);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.ArenaTable;
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.ArenaTiltakgjennomforing;
import no.nav.tag.tiltaksgjennomforing.arena.models.arena.Operation;
import no.nav.tag.tiltaksgjennomforing.arena.models.event.ArenaEvent;
import no.nav.tag.tiltaksgjennomforing.arena.models.event.ArenaEventStatus;
import no.nav.tag.tiltaksgjennomforing.arena.repository.ArenaEventRepository;
import no.nav.tag.tiltaksgjennomforing.arena.repository.ArenaTiltakgjennomforingRepository;
import no.nav.tag.tiltaksgjennomforing.arena.repository.ArenaTiltakssakRepository;
import org.springframework.stereotype.Service;

@Slf4j
Expand All @@ -19,46 +16,21 @@ public class TiltakgjennomforingArenaEventProcessingService implements IArenaEve

private final ObjectMapper objectMapper;
private final ArenaTiltakgjennomforingRepository tiltakgjennomforingRepository;
private final ArenaTiltakssakRepository tiltakssakRepository;
private final ArenaOrdsService ordsService;
private final ArenaEventRepository eventRepository;

public TiltakgjennomforingArenaEventProcessingService(
ArenaEventRepository eventRepository,
ArenaOrdsService ordsService,
ArenaTiltakgjennomforingRepository tiltakgjennomforingRepository,
ArenaTiltakssakRepository tiltakssakRepository,
ObjectMapper objectMapper
) {
this.eventRepository = eventRepository;
this.objectMapper = objectMapper;
this.ordsService = ordsService;
this.tiltakgjennomforingRepository = tiltakgjennomforingRepository;
this.tiltakssakRepository = tiltakssakRepository;
}

public ArenaEventStatus process(ArenaEvent arenaEvent) throws JsonProcessingException {
ArenaTiltakgjennomforing tiltakgjennomforing = this.objectMapper.treeToValue(arenaEvent.getPayload(), ArenaTiltakgjennomforing.class);

boolean isTiltaksakIgnored = eventRepository.findByArenaIdAndArenaTable(
tiltakgjennomforing.getSakId().toString(),
ArenaTable.TILTAKSAK.getTable()
)
.map((tiltak) -> ArenaEventStatus.IGNORED == tiltak.getStatus())
.orElse(false);

if (isTiltaksakIgnored) {
log.info("Arena-event ignorert fordi tilhørende tiltaksak er ignorert");

delete(
tiltakgjennomforing,
() -> log.info("Sletter tidligere håndtert tiltak som nå skal ignoreres")
);
deleteArbeidsgiver(tiltakgjennomforing.getArbgivIdArrangor());

return ArenaEventStatus.IGNORED;
}

if (!tiltakgjennomforing.isArbeidstrening()) {
log.info("Arena-event ignorert fordi den ikke er arbeidstrening");
delete(
Expand All @@ -79,12 +51,6 @@ public ArenaEventStatus process(ArenaEvent arenaEvent) throws JsonProcessingExce
return ArenaEventStatus.DONE;
}

boolean tiltakssakExists = tiltakssakRepository.existsById(tiltakgjennomforing.getSakId());
if (!tiltakssakExists) {
log.info("Arena-event settes på vent; tilhørende tiltakssak er ikke prossesert ennå");
return ArenaEventStatus.RETRY;
}

ordsService.fetchArbeidsgiver(tiltakgjennomforing.getArbgivIdArrangor());
tiltakgjennomforingRepository.save(tiltakgjennomforing);

Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion src/main/resources/config/application-dev-fss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ tiltaksgjennomforing:
kafka:
tiltakdeltaker-endret-topic: 'teamarenanais.aapen-arena-tiltakdeltakerendret-v1-q2'
tiltakgjennomforing-endret-topic: 'teamarenanais.aapen-arena-tiltakgjennomforingendret-v1-q2'
tiltakssak-endret-topic: 'teamarenanais.aapen-arena-tiltakssakendret-v1-q2'
ords:
url: https://arena-ords-q2.nais.preprod.local
client-id: ${ARENA_ORDS_CLIENT_ID}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/config/application-dev-gcp-labs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ tiltaksgjennomforing:
kafka:
tiltakdeltaker-endret-topic: 'teamarenanais.aapen-arena-tiltakdeltakerendret-v1-q2'
tiltakgjennomforing-endret-topic: 'teamarenanais.aapen-arena-tiltakgjennomforingendret-v1-q2'
tiltakssak-endret-topic: 'teamarenanais.aapen-arena-tiltakssakendret-v1-q2'
ords:
url: http://tiltaksgjennomforing-wiremock/arena-ords
client-id: client
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/config/application-prod-fss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ tiltaksgjennomforing:
kafka:
tiltakdeltaker-endret-topic: 'teamarenanais.aapen-arena-tiltakdeltakerendret-v1-p'
tiltakgjennomforing-endret-topic: 'teamarenanais.aapen-arena-tiltakgjennomforingendret-v1-p'
tiltakssak-endret-topic: 'teamarenanais.aapen-arena-tiltakssakendret-v1-p'
ords:
url: https://arena-ords.nais.adeo.no
client-id: ${ARENA_ORDS_CLIENT_ID}
Expand Down
Loading

0 comments on commit 89611f0

Please sign in to comment.