Skip to content

Commit 3c2dbc7

Browse files
authored
Bugfix/bestillingsstatus issues (#4221)
* - Refactor BestillingStatusMappingStrategy to improve bestilling status mapping logic - Introduce UtledFagsystemResolver for determining relevant systems based on BestilteKriterier - Enhance error handling for JSON parsing in bestilling status mapping - Add utility methods for extracting bestilling criteria JSON and resolving systems #deploy-test-dolly-backend * - Handle errors in deployOrganisasjon by setting bestilling feil status - Rename UtledFagsystemResolver to UtledFagsystemUtil for consistency - Improve error logging in OrganisasjonController during gjenopprett process #deploy-test-dolly-backend * - Update deployOrganisasjon error handling to log errors and set bestilling feil status - Refactor gjenopprett method in OrganisasjonController for improved readability and error handling #deploy-test-dolly-backend * - Add brukerId to the bestilling creation process in OrganisasjonBestillingService #deploy-test-dolly-backend * - Deploy dev #deploy-test-dolly-backend * - Refactor BestillingProgresjon to use sorted status list instead of merged status - Simplify status handling in BestillingStatus by using statuser directly - Remove unused getExpectedFagsystemer and mergeStatusWithExpected functions from fagsystemUtils - Optimize manglerFagsystemdata checks in PersonVisning for better readability #deploy-test-dolly-frontend * - Deploy backend #deploy-test-dolly-backend * - Refactor tests in calculateProgress to use a consistent statusList variable - Update polling interval in useVersionCheck from 60 seconds to 2 minutes #deploy-test-dolly-frontend * - Add UtledFagsystemUtilTest to cover various scenarios for resolving system types - Implement tests for BestilteKriterier and their interactions with different data types - Ensure no duplicates in resolved system types #deploy-test-dolly-backend * - Refactor GjenopprettBestilling to improve organization of imports and variable naming - Update submitForm to utilize global mutate for handling new bestilling data - Enhance logic for handling erOrganisasjon condition in submitForm #deploy-test-dolly-frontend * - Simplify title assignment logic in BestillingProgresjon component - Refactor filtrerNyeBestillinger to improve readability and performance in StatusListe component - Update onFinishBestilling and lukkBestilling to use functional state updates for better state management - Change key prop in ikkeFerdig mapping to use bestilling.id for uniqueness - Add 'enhetstype' to the list of valid environments in MiljoVelger - Remove unnecessary initial loading checks in useOrgBestillingStream #deploy-test-dolly-frontend * - Deploy backend #deploy-test-dolly-backend * - Add sorting functionality for status lists in UtledFagsystemUtil - Implement priority order for system types in fagsystemUtils - Update BestillingProgresjon to include finished and stopped flags in onFinishBestilling callback #deploy-test-dolly-backend * - Deploy #deploy-test-dolly-frontend * - Update logic for adding new orders in GjenopprettBestilling component to prevent duplicates - Ensure new orders are only added if they do not already exist in the current list #deploy-test-dolly-frontend * - Update bestillingStatusMapper to handle potential undefined values in system statuser - Ensure flatMap safely processes statuser by providing a fallback to an empty array #deploy-test-dolly-frontend * - Deploy #deploy-test-dolly-frontend * - Refactor deployment logic in OrganisasjonClient to streamline error handling - Replace nested subscription with a more concise chaining approach for better readability #deploy-test-dolly-backend * - Update BestillingController to format status output with detailed messages for each status - Modify UtledFagsystemUtil to include additional condition for removing PDL_FORVALTER based on new identifier checks #deploy-test-dolly-backend * Deploy #deploy-test-dolly-backend #deploy-test-dolly-frontend * BestillingStatus fix #deploy-test-dolly-backend * BestillingStatus fix v2 #deploy-test-dolly-backend * BestillingStatus fix v2 #deploy-test-dolly-frontend * Fix missing newline at end of file in application starter classes #deploy-test-dolly-frontend #deploy-test-dolly-backend * Refactor BestillingController and UtledFagsystemUtil to use nonNull and isNotBlank checks * Deploy #deploy-test-dolly-backend * Fix BestillingStatus to correctly handle antallIdenter for organizations #deploy-test-dolly-frontend * Fix: Add missing newline at end of file in application starter classes #deploy-test-dolly-frontend #deploy-test-dolly-backend * Deploy #deploy-test-dolly-frontend #deploy-test-dolly-backend * Fix: Add support for resolving derived systems in Bestilling and related services #deploy-test-dolly-backend * Fix: Update BestillingController and BestillingService to use new method for fetching Bestilling with derived systems - Refactor fetchBestillingById calls to fetchBestillingByIdMedUtlededeFagsystemer in BestillingController - Add fetchBestillingByIdMedUtlededeFagsystemer method in BestillingService for better handling of derived systems #deploy-test-dolly-backend * Fix: Update BestillingStatus to handle derived system cases - Introduce isGjenopprett flag to determine if the bestilling is derived - Adjust logic to conditionally display antallBestilteIdenter based on isGjenopprett - Update rendering of identer count to reflect derived system status #deploy-test-dolly-frontend * - Deploy #deploy-test-dolly-backend #deploy-test-dolly-frontend #deploy-dolly-proxy * - Deploy #deploy-test-dolly-backend #deploy-test-dolly-frontend #deploy-dolly-proxy * - Update BestillingServiceTest to mock new repository methods for fetching Bestillinger by Ident and GruppeId. - Refactor BestillingStatus component to filter out transient status messages from the display. #deploy-test-dolly-backend #deploy-test-dolly-frontend * - Fix: Update logic in UtledFagsystemUtil to correctly add PDLIMPORT when restoring a Bestilling. - Refactor: Remove unused filterImportSubSteps function from fagsystemUtils.ts and simplify sorting logic. #deploy-test-dolly-backend #deploy-test-dolly-frontend * - Refactor: Adjust formatting in calculateProgress.test.ts for consistency - Refactor: Update fagsystemUtils.ts for improved readability and maintainability - Enhance: Ensure filterImportSubSteps correctly filters based on PDLIMPORT presence #deploy-test-dolly-frontend * - Refactor: Remove unused filterImportSubSteps function from fagsystemUtils.ts - Update: Export mapStatusrapport function in MiljoeStatus.tsx for better accessibility - Fix: Adjust logic in BestillingStatus.tsx to correctly handle 'ferdig' status in conditional checks - Clean up: Remove commented-out test cases for filterImportSubSteps in calculateProgress.test.ts #deploy-test-dolly-frontend * - Refactor: Simplify status icon logic in BestillingStatus component - Enhance: Improve handling of OK and error statuses with new utility functions - Update: Adjust rendering of status messages and identifiers for better clarity #deploy-test-dolly-frontend * Refactor: Improve formatting and structure in BestillingStatus component - Standardize spacing and indentation for better readability - Update rendering logic for status icons and messages - Enhance error handling display for better user feedback #deploy-test-dolly-frontend * - Add PEN_FORVALTER to the list of constants in UtledFagsystemUtil #deploy-test-dolly-backend * - Update test description for sortFagsystemer to reflect functionality - Refactor BestillingStatus component to use isErrorMessage for error handling - Remove unused IN_PROGRESS_MESSAGES and simplify status checks in fagsystemUtils #deploy-test-dolly-frontend * - Changed progress text from 'Oppretter' to 'Opprettet' in calculateProgress.test.ts - Update progress calculation logic to reflect correct values in fagsystemUtils.ts #deploy-test-dolly-backend #deploy-test-dolly-frontend * - Add tests to ensure fagsystems are preserved during SSE events in useBestillingStream - Implement logic to use final backend state on completion without placeholders - Refactor error and warning message handling in BestillingStatus and related components - Update bestillingHarFeil function to check for both error and warning messages - Improve key assignment in TitleValue components for better rendering #deploy-test-dolly-frontend #deploy-test-dolly-backend * - Update error message in BestillingStatus.tsx to use correct singular/plural form for 'ident' #deploy-test-dolly-frontend #deploy-test-dolly-backend
1 parent 25e3046 commit 3c2dbc7

28 files changed

Lines changed: 1499 additions & 936 deletions

File tree

apps/dolly-backend/src/main/java/no/nav/dolly/bestilling/organisasjonforvalter/OrganisasjonClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ public Mono<Void> gjenopprett(DeployRequest request, OrganisasjonBestilling best
8686
.organisasjonsforvalterStatus(miljoer.stream().map(env -> env + ":Deployer").collect(Collectors.joining(",")))
8787
.build())
8888
.doOnNext(saved -> bestillingEventPublisher.publishOrg(bestilling.getId()))
89-
.then(deployOrganisasjon(request.getOrgnumre(), bestilling, miljoer));
89+
.then(deployOrganisasjon(request.getOrgnumre(), bestilling, miljoer))
90+
.onErrorResume(throwable ->
91+
organisasjonBestillingService.setBestillingFeil(bestilling.getId(), errorStatusDecoder.decodeThrowable(throwable))
92+
.then(organisasjonProgressService.setBestillingFeil(bestilling.getId(), errorStatusDecoder.decodeThrowable(throwable))));
9093
}
9194

9295
public void release(List<String> ignored) {

apps/dolly-backend/src/main/java/no/nav/dolly/domain/jpa/Bestilling.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public class Bestilling implements Serializable {
8686
@Column("nav_syntetisk_ident")
8787
private Boolean navSyntetiskIdent;
8888

89+
@Transient
90+
private String utlededeFagsystemer;
91+
8992
@Transient
9093
private List<BestillingProgress> progresser;
9194

apps/dolly-backend/src/main/java/no/nav/dolly/mapper/strategy/BestillingStatusMappingStrategy.java

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@
88
import no.nav.dolly.domain.jpa.Bestilling;
99
import no.nav.dolly.domain.jpa.BestillingProgress;
1010
import no.nav.dolly.domain.jpa.OrganisasjonBestilling;
11+
import no.nav.dolly.domain.resultset.BestilteKriterier;
12+
import no.nav.dolly.domain.resultset.RsStatusRapport;
1113
import no.nav.dolly.domain.resultset.entity.bestilling.RsBestillingStatus;
1214
import no.nav.dolly.domain.resultset.entity.bruker.RsBrukerUtenFavoritter;
1315
import no.nav.dolly.mapper.MappingStrategy;
16+
import no.nav.dolly.util.UtledFagsystemUtil;
1417
import org.springframework.http.HttpStatus;
1518
import org.springframework.stereotype.Component;
1619
import org.springframework.web.server.ResponseStatusException;
1720
import tools.jackson.core.JacksonException;
1821
import tools.jackson.databind.ObjectMapper;
1922

23+
import java.util.List;
24+
import java.util.stream.Collectors;
25+
2026
import static java.util.Objects.isNull;
2127
import static no.nav.dolly.bestilling.service.DollyBestillingService.getEnvironments;
2228
import static no.nav.dolly.mapper.AnnenFeilStatusMapper.buildAnnenFeilStatusMap;
@@ -50,6 +56,7 @@
5056
import static no.nav.dolly.mapper.BestillingUdiStubStatusMapper.buildUdiStubStatusMap;
5157
import static no.nav.dolly.mapper.BestillingYrkesskadeStatusMapper.buildYrkesskadeStatusMap;
5258
import static org.apache.commons.lang3.StringUtils.isBlank;
59+
import static org.apache.commons.lang3.StringUtils.isNotBlank;
5360

5461
@Slf4j
5562
@Component
@@ -67,11 +74,10 @@ public void register(MapperFactory factory) {
6774
public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus, MappingContext context) {
6875

6976
var ident = (String) context.getProperty("ident");
77+
var bestKriterierJson = getBestKriterierJson(bestilling);
78+
7079
try {
71-
bestillingStatus.setBestilling(
72-
objectMapper.readTree(isNull(bestilling.getBestKriterier()) ||
73-
EMPTY_JSON.equals(bestilling.getBestKriterier()) ? EMPTY_JSON :
74-
bestilling.getBestKriterier()));
80+
bestillingStatus.setBestilling(objectMapper.readTree(bestKriterierJson));
7581
} catch (JacksonException e) {
7682
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getOriginalMessage());
7783
}
@@ -118,6 +124,12 @@ public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus,
118124
bestillingStatus.getStatus().addAll(buildTpsMessagingStatusMap(progresser));
119125
bestillingStatus.getStatus().addAll(buildAnnenFeilStatusMap(progresser));
120126
bestillingStatus.getStatus().addAll(buildKelvinAapStatusMap(progresser));
127+
128+
if (!bestilling.isFerdig()) {
129+
utledFagsystemer(bestillingStatus, bestKriterierJson, bestilling);
130+
}
131+
132+
UtledFagsystemUtil.sortStatusList(bestillingStatus.getStatus(), RsStatusRapport::getId);
121133
}
122134
})
123135
.exclude("bruker")
@@ -136,4 +148,35 @@ public void mapAtoB(OrganisasjonBestilling bestilling, RsBestillingStatus bestil
136148
.register();
137149

138150
}
151+
152+
private String getBestKriterierJson(Bestilling bestilling) {
153+
154+
return isNull(bestilling.getBestKriterier()) || EMPTY_JSON.equals(bestilling.getBestKriterier())
155+
? EMPTY_JSON
156+
: bestilling.getBestKriterier();
157+
}
158+
159+
private void utledFagsystemer(RsBestillingStatus bestillingStatus, String bestKriterierJson, Bestilling bestilling) {
160+
161+
try {
162+
var utledteFagsystemer = isNotBlank(bestilling.getUtlededeFagsystemer())
163+
? UtledFagsystemUtil.deserialize(bestilling.getUtlededeFagsystemer())
164+
: UtledFagsystemUtil.resolve(objectMapper.readValue(bestKriterierJson, BestilteKriterier.class), bestilling);
165+
166+
var eksisterendeIds = bestillingStatus.getStatus().stream()
167+
.map(RsStatusRapport::getId)
168+
.collect(Collectors.toSet());
169+
170+
utledteFagsystemer.stream()
171+
.filter(type -> !eksisterendeIds.contains(type))
172+
.map(type -> RsStatusRapport.builder()
173+
.id(type)
174+
.navn(type.getBeskrivelse())
175+
.statuser(List.of())
176+
.build())
177+
.forEach(bestillingStatus.getStatus()::add);
178+
} catch (JacksonException e) {
179+
log.warn("Kunne ikke utlede fagsystemer fra bestKriterier: {}", e.getOriginalMessage());
180+
}
181+
}
139182
}

apps/dolly-backend/src/main/java/no/nav/dolly/provider/BestillingController.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
import java.time.Duration;
3131
import java.util.Set;
3232

33+
import static java.util.Objects.nonNull;
3334
import static no.nav.dolly.config.CachingConfig.CACHE_BESTILLING;
3435
import static no.nav.dolly.config.CachingConfig.CACHE_GRUPPE;
3536
import static org.apache.commons.lang3.BooleanUtils.isTrue;
37+
import static org.apache.commons.lang3.StringUtils.isNotBlank;
3638

3739
@Slf4j
3840
@Transactional
@@ -144,7 +146,7 @@ public Mono<RsBestillingStatus> gjenopprettBestilling(@PathVariable("bestillingI
144146
public Flux<ServerSentEvent<RsBestillingStatus>> streamBestillingStatus(
145147
@PathVariable("bestillingId") Long bestillingId) {
146148

147-
return bestillingService.fetchBestillingById(bestillingId)
149+
return bestillingService.fetchBestillingByIdMedUtlededeFagsystemer(bestillingId)
148150
.map(bestilling -> mapperFacade.map(bestilling, RsBestillingStatus.class))
149151
.flatMapMany(initial -> {
150152
var initialSse = toBestillingSse(initial);
@@ -155,7 +157,7 @@ public Flux<ServerSentEvent<RsBestillingStatus>> streamBestillingStatus(
155157

156158
var updates = bestillingEventPublisher.subscribe(bestillingId)
157159
.sample(Duration.ofMillis(200))
158-
.concatMap(id -> bestillingService.fetchBestillingById(bestillingId)
160+
.concatMap(id -> bestillingService.fetchBestillingByIdMedUtlededeFagsystemer(bestillingId)
159161
.map(bestilling -> mapperFacade.map(bestilling, RsBestillingStatus.class))
160162
.timeout(Duration.ofSeconds(5))
161163
.onErrorResume(e -> {
@@ -164,7 +166,7 @@ public Flux<ServerSentEvent<RsBestillingStatus>> streamBestillingStatus(
164166
}));
165167

166168
var fallbackCheck = Flux.interval(Duration.ofSeconds(3), Duration.ofSeconds(3))
167-
.concatMap(tick -> bestillingService.fetchBestillingById(bestillingId)
169+
.concatMap(tick -> bestillingService.fetchBestillingByIdMedUtlededeFagsystemer(bestillingId)
168170
.map(bestilling -> mapperFacade.map(bestilling, RsBestillingStatus.class))
169171
.timeout(Duration.ofSeconds(5))
170172
.onErrorResume(e -> Mono.empty()));
@@ -181,8 +183,12 @@ private String statusFingerprint(RsBestillingStatus status) {
181183
return status.isFerdig() + ":"
182184
+ status.getAntallLevert() + ":"
183185
+ status.getSistOppdatert() + ":"
184-
+ (status.getFeil() != null ? status.getFeil().length() : 0) + ":"
185-
+ status.getStatus().size();
186+
+ (isNotBlank(status.getFeil()) ? status.getFeil().length() : 0) + ":"
187+
+ status.getStatus().stream()
188+
.map(s -> s.getId() + "=" + (nonNull(s.getStatuser()) && !s.getStatuser().isEmpty()
189+
? s.getStatuser().getFirst().getMelding()
190+
: ""))
191+
.collect(java.util.stream.Collectors.joining(","));
186192
}
187193

188194
private ServerSentEvent<RsBestillingStatus> toBestillingSse(RsBestillingStatus status) {

apps/dolly-backend/src/main/java/no/nav/dolly/provider/OrganisasjonController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.swagger.v3.oas.annotations.Operation;
44
import io.swagger.v3.oas.annotations.Parameter;
55
import lombok.RequiredArgsConstructor;
6+
import lombok.extern.slf4j.Slf4j;
67
import no.nav.dolly.bestilling.organisasjonforvalter.OrganisasjonClient;
78
import no.nav.dolly.bestilling.organisasjonforvalter.domain.DeployRequest;
89
import no.nav.dolly.bestilling.organisasjonforvalter.domain.OrganisasjonDetaljer;
@@ -21,6 +22,7 @@
2122

2223
import static no.nav.dolly.provider.OrganisasjonBestillingController.getStatus;
2324

25+
@Slf4j
2426
@RestController
2527
@RequiredArgsConstructor
2628
@RequestMapping(value = "api/v1/organisasjon")

0 commit comments

Comments
 (0)