1
1
package no .nav .testnav .dollysearchservice .consumer ;
2
2
3
3
import com .fasterxml .jackson .databind .ObjectMapper ;
4
+ import lombok .extern .slf4j .Slf4j ;
4
5
import no .nav .testnav .dollysearchservice .config .Consumers ;
6
+ import no .nav .testnav .dollysearchservice .consumer .command .OpenSearchCommand ;
5
7
import no .nav .testnav .dollysearchservice .consumer .command .TagsGetCommand ;
6
8
import no .nav .testnav .dollysearchservice .consumer .command .TagsPostCommand ;
9
+ import no .nav .testnav .dollysearchservice .dto .SearchRequest ;
10
+ import no .nav .testnav .dollysearchservice .dto .SearchResponse ;
7
11
import no .nav .testnav .dollysearchservice .dto .TagsOpprettingResponse ;
8
12
import no .nav .testnav .libs .securitycore .domain .ServerProperties ;
9
13
import no .nav .testnav .libs .servletsecurity .exchange .TokenExchange ;
10
14
import org .springframework .stereotype .Service ;
11
15
import org .springframework .web .reactive .function .client .WebClient ;
16
+ import reactor .core .publisher .Flux ;
12
17
import reactor .core .publisher .Mono ;
13
18
14
19
import java .util .List ;
15
20
import java .util .Map ;
16
21
17
22
import static no .nav .testnav .dollysearchservice .consumer .utils .JacksonExchangeStrategyUtil .getJacksonStrategy ;
18
23
24
+ @ Slf4j
19
25
@ Service
20
- public class PdlDataConsumer {
26
+ public class PdlProxyConsumer {
21
27
22
28
private final WebClient webClient ;
23
29
private final TokenExchange tokenExchange ;
24
30
private final ServerProperties serverProperties ;
25
31
26
- public PdlDataConsumer (
32
+ public PdlProxyConsumer (
27
33
TokenExchange tokenExchange ,
28
34
Consumers consumers ,
29
35
ObjectMapper objectMapper ,
@@ -37,6 +43,17 @@ public PdlDataConsumer(
37
43
this .tokenExchange = tokenExchange ;
38
44
}
39
45
46
+ public Flux <SearchResponse > search (SearchRequest request ) {
47
+ return tokenExchange .exchange (serverProperties )
48
+ .flatMapMany (token ->
49
+ new OpenSearchCommand (webClient , request .getQuery ().indices ()[0 ],
50
+ token .getTokenValue (), request .getQuery ().source ().toString ()).call ())
51
+ .map (response -> {
52
+ response .setRequest (request .getRequest ());
53
+ return response ;
54
+ });
55
+ }
56
+
40
57
public Mono <Map <String , List <String >>> getTags (List <String > identer ) {
41
58
42
59
return tokenExchange .exchange (serverProperties )
@@ -48,4 +65,4 @@ public Mono<TagsOpprettingResponse> setTags(List<String> identer) {
48
65
return tokenExchange .exchange (serverProperties )
49
66
.flatMap (token -> new TagsPostCommand (webClient , identer , token .getTokenValue ()).call ());
50
67
}
51
- }
68
+ }
0 commit comments