Skip to content

Commit

Permalink
fix deserialization and date field for journalpost, and cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Battlestad committed Apr 13, 2023
1 parent c1293f4 commit d08f017
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public EgrunnervervJournalpostInstanceToDispatch map(SakResource sakResource, Lo
.tittel(journalpostResource.getTittel())
.dokumentDato(
journalpostResource
.getDokumentetsDato()
.getOpprettetDato()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime()
Expand Down
60 changes: 31 additions & 29 deletions src/main/java/no/fintlabs/InstanceConsumerConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,72 +147,74 @@ public ConcurrentMessageListenerContainer<String, InstanceToDispatchEntity> inst
).createContainer(topic);
}

private Optional<InstanceToDispatchEntity> storeJournalpostInstanceToDispatch(
private Optional<InstanceToDispatchEntity> storeSakInstanceToDispatch(
String tableName,
String sourceApplicationInstanceId,
String archiveInstanceId
) throws JsonProcessingException {
String[] splitArchiveInstanceId = archiveInstanceId.split("-");
String caseId = splitArchiveInstanceId[0];
Long journalpostNummer = Long.parseLong(
splitArchiveInstanceId[1]
.replace("[", "")
.replace("]", "")
);
SakResource sakResource = caseRequestService.getByMappeId(caseId).orElseThrow();
EgrunnervervJournalpostInstanceToDispatch egrunnervervJournalpostInstanceToDispatch =
journalpostInstanceToDispatchMappingService.map(sakResource, journalpostNummer);
SakResource sakResource = caseRequestService.getByMappeId(archiveInstanceId).orElseThrow();

EgrunnervervSakInstanceToDispatch egrunnervervSakInstanceToDispatch = EgrunnervervSakInstanceToDispatch.builder()
.arkivnummer(archiveInstanceId)
.opprettelse_i_elements_fullfort(
sakResource
.getOpprettetDato()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime()
.format(DateTimeFormatter.ofPattern(EGRUNNERVERV_DATETIME_FORMAT))
)
.build();

String uri = UriComponentsBuilder.newInstance()
.pathSegment(
tableName,
sourceApplicationInstanceId
)
.queryParam("sysparm_fields", "arkivnummer")
.queryParam("sysparm_query_no_domain", "true")
.toUriString();

InstanceToDispatchEntity instanceToDispatchEntity = InstanceToDispatchEntity.builder()
.sourceApplicationInstanceId(sourceApplicationInstanceId)
.instanceToDispatch(objectMapper.writeValueAsString(egrunnervervJournalpostInstanceToDispatch))
.classType(EgrunnervervJournalpostInstanceToDispatch.class)
.instanceToDispatch(objectMapper.writeValueAsString(egrunnervervSakInstanceToDispatch))
.classType(EgrunnervervSakInstanceToDispatch.class)
.uri(uri)
.build();

instanceToDispatchEntityRepository.save(instanceToDispatchEntity);
return Optional.of(instanceToDispatchEntity);
}

private Optional<InstanceToDispatchEntity> storeSakInstanceToDispatch(
private Optional<InstanceToDispatchEntity> storeJournalpostInstanceToDispatch(
String tableName,
String sourceApplicationInstanceId,
String archiveInstanceId
) throws JsonProcessingException {
SakResource sakResource = caseRequestService.getByMappeId(archiveInstanceId).orElseThrow();

EgrunnervervSakInstanceToDispatch egrunnervervSakInstanceToDispatch = EgrunnervervSakInstanceToDispatch.builder()
.arkivnummer(archiveInstanceId)
.opprettelse_i_elements_fullfort(
sakResource
.getOpprettetDato()
.toInstant()
.atZone(ZoneId.systemDefault())
.toLocalDateTime()
.format(DateTimeFormatter.ofPattern(EGRUNNERVERV_DATETIME_FORMAT))
)
.build();
String[] splitArchiveInstanceId = archiveInstanceId.split("-");
String caseId = splitArchiveInstanceId[0];
Long journalpostNummer = Long.parseLong(
splitArchiveInstanceId[1]
.replace("[", "")
.replace("]", "")
);
SakResource sakResource = caseRequestService.getByMappeId(caseId).orElseThrow();
EgrunnervervJournalpostInstanceToDispatch egrunnervervJournalpostInstanceToDispatch =
journalpostInstanceToDispatchMappingService.map(sakResource, journalpostNummer);

String uri = UriComponentsBuilder.newInstance()
.pathSegment(
tableName,
sourceApplicationInstanceId
)
.queryParam("sysparm_fields", "journalpostid")
.queryParam("sysparm_query_no_domain", "true")
.toUriString();

InstanceToDispatchEntity instanceToDispatchEntity = InstanceToDispatchEntity.builder()
.sourceApplicationInstanceId(sourceApplicationInstanceId)
.instanceToDispatch(objectMapper.writeValueAsString(egrunnervervSakInstanceToDispatch))
.classType(EgrunnervervSakInstanceToDispatch.class)
.instanceToDispatch(objectMapper.writeValueAsString(egrunnervervJournalpostInstanceToDispatch))
.classType(EgrunnervervJournalpostInstanceToDispatch.class)
.uri(uri)
.build();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/no/fintlabs/WebClientRequestService.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public void dispatchInstance(InstanceToDispatchEntity instanceToDispatchEntity)
Object instanceToDispatch;
instanceToDispatch = objectMapper.readValue(instanceToDispatchEntity.getInstanceToDispatch(), instanceToDispatchEntity.getClassType());

log.debug("instanceToDispatch=" + instanceToDispatchEntity.getInstanceToDispatch());

webClient.patch()
.uri(instanceToDispatchEntity.getUri())
.body(Mono.just(instanceToDispatch), instanceToDispatchEntity.getClassType())
Expand All @@ -44,7 +46,6 @@ public void dispatchInstance(InstanceToDispatchEntity instanceToDispatchEntity)
.publishOn(Schedulers.boundedElastic())
.doOnSuccess(success -> {
log.info("success {}", success);
log.debug("instanceToDispatch="+instanceToDispatchEntity.getInstanceToDispatch());
instanceToDispatchEntityRepository.delete(instanceToDispatchEntity);
})
.doOnError(error -> log.error("Error msg from webclient: " + error.getMessage()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

@Getter
@Builder
@ToString
@Jacksonized
public class EgrunnervervJournalpostInstanceToDispatch {
private final String journalpostnr;
private final String tittel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import lombok.Builder;
import lombok.Getter;
import lombok.ToString;
import lombok.extern.jackson.Jacksonized;

@Getter
@Builder
@ToString
@Jacksonized
public class EgrunnervervSakInstanceToDispatch {
private final String arkivnummer;
private final String opprettelse_i_elements_fullfort;
Expand Down

0 comments on commit d08f017

Please sign in to comment.