30
30
import no .nav .dolly .service .BestillingService ;
31
31
import no .nav .dolly .service .IdentService ;
32
32
import no .nav .dolly .util .TransactionHelperService ;
33
+ import no .nav .testnav .libs .data .pdlforvalter .v1 .PersonUpdateRequestDTO ;
33
34
import org .apache .commons .lang3 .StringUtils ;
34
35
import org .slf4j .MDC ;
35
36
import org .springframework .stereotype .Service ;
@@ -145,16 +146,26 @@ protected Flux<BestillingProgress> gjenopprettKlienter(DollyPerson dollyPerson,
145
146
.map (ClientFuture ::get );
146
147
}
147
148
149
+ protected void leggIdentTilGruppe (BestillingProgress progress , String beskrivelse ) {
150
+
151
+ leggIdentTilGruppe (null , progress , beskrivelse );
152
+ }
153
+
148
154
protected void leggIdentTilGruppe (String ident , BestillingProgress progress , String beskrivelse ) {
149
155
150
- identService .saveIdentTilGruppe (ident , progress .getBestilling ().getGruppe (), progress .getMaster (), beskrivelse );
151
- log .info ("Ident {} lagt til gruppe {}" , ident , progress .getBestilling ().getGruppe ().getId ());
156
+ identService .saveIdentTilGruppe (isNotBlank (ident ) ? ident : progress .getIdent (), progress .getBestilling ().getGruppe (), progress .getMaster (), beskrivelse );
157
+ log .info ("Ident {} lagt til gruppe {}" , progress .getIdent (), progress .getBestilling ().getGruppe ().getId ());
158
+ }
159
+
160
+ protected Flux <DollyPerson > opprettDollyPerson (BestillingProgress progress , Bruker bruker ) {
161
+
162
+ return opprettDollyPerson (null , progress , bruker );
152
163
}
153
164
154
165
protected Flux <DollyPerson > opprettDollyPerson (String ident , BestillingProgress progress , Bruker bruker ) {
155
166
156
167
return Flux .just (DollyPerson .builder ()
157
- .ident (ident )
168
+ .ident (isNotBlank ( ident ) ? ident : progress . getIdent () )
158
169
.master (progress .getMaster ())
159
170
.tags (Stream .concat (progress .getBestilling ().getGruppe ().getTags ().stream (),
160
171
Stream .of (Tags .DOLLY )
@@ -224,6 +235,11 @@ protected Flux<PdlResponse> opprettPerson(OriginatorUtility.Originator originato
224
235
225
236
protected Flux <String > sendOrdrePerson (BestillingProgress progress , PdlResponse forvalterStatus ) {
226
237
238
+ if (progress .getMaster () == PDL ) {
239
+
240
+ transactionHelperService .persister (progress , BestillingProgress ::setPdlImportStatus , "OK" );
241
+ }
242
+
227
243
if (nonNull (forvalterStatus .getStatus ())) {
228
244
229
245
transactionHelperService .persister (progress , BestillingProgress ::setPdlForvalterStatus ,
@@ -234,12 +250,7 @@ protected Flux<String> sendOrdrePerson(BestillingProgress progress, PdlResponse
234
250
forvalterStatus .getIdent () : "?" );
235
251
}
236
252
237
- if (progress .getMaster () == PDL ) {
238
-
239
- transactionHelperService .persister (progress , BestillingProgress ::setPdlImportStatus , "OK" );
240
- return Flux .just (progress .getIdent ());
241
-
242
- } else if (isNull (forvalterStatus .getStatus ()) || forvalterStatus .getStatus ().is2xxSuccessful ()) {
253
+ if (isNull (forvalterStatus .getStatus ()) || forvalterStatus .getStatus ().is2xxSuccessful ()) {
243
254
244
255
transactionHelperService .persister (progress , BestillingProgress ::setPdlOrdreStatus ,
245
256
"Info: Ordre til PDL startet ..." );
@@ -248,10 +259,12 @@ protected Flux<String> sendOrdrePerson(BestillingProgress progress, PdlResponse
248
259
var status = resultat .getStatus ().is2xxSuccessful () ?
249
260
resultat .getJsonNode () :
250
261
errorStatusDecoder .getErrorText (resultat .getStatus (), resultat .getFeilmelding ());
251
- transactionHelperService .persister (progress , BestillingProgress ::setPdlOrdreStatus , status );
262
+ transactionHelperService .persister (progress , BestillingProgress ::setPdlOrdreStatus ,
263
+ !resultat .isFinnesIkke () ? status : null );
252
264
log .info ("Sendt ordre til PDL for ident {} " , forvalterStatus .getIdent ());
253
265
})
254
- .map (resultat -> resultat .getStatus ().is2xxSuccessful () ? forvalterStatus .getIdent () : "" );
266
+ .map (resultat -> resultat .getStatus ().is2xxSuccessful () || resultat .isFinnesIkke ()
267
+ ? forvalterStatus .getIdent () : "" );
255
268
256
269
} else {
257
270
@@ -282,4 +295,23 @@ protected Flux<RsDollyBestillingRequest> createBestilling(Bestilling bestilling,
282
295
coBestilling .getMiljoer ())
283
296
.build ()));
284
297
}
298
+
299
+ protected Flux <PdlResponse > oppdaterPdlPerson (OriginatorUtility .Originator originator , BestillingProgress progress ) {
300
+
301
+ if (nonNull (originator .getPdlBestilling ()) && nonNull (originator .getPdlBestilling ().getPerson ())) {
302
+
303
+ transactionHelperService .persister (progress , BestillingProgress ::setPdlForvalterStatus ,
304
+ "Info: Oppdatering av person startet ..." );
305
+ return pdlDataConsumer .oppdaterPdl (originator .getIdent (),
306
+ PersonUpdateRequestDTO .builder ()
307
+ .person (originator .getPdlBestilling ().getPerson ())
308
+ .build ())
309
+ .doOnNext (response -> log .info ("Oppdatert person til PDL-forvalter med response {}" , response ));
310
+
311
+ } else {
312
+ return Flux .just (PdlResponse .builder ()
313
+ .ident (originator .getIdent ())
314
+ .build ());
315
+ }
316
+ }
285
317
}
0 commit comments