0
public DetailsResponse common(String customerId, String personId) {
        Capabilities capabilities = new Capabilities();
        Details details = new Details();
        DetailsResponse detailsResponse = new DetailsResponse();
        consume("590204", "4252452")
                .map(items -> items.get(0))
                .flatMap(item -> {
                    return  actions("432432", "1241441")
                            .map(ev -> {
                                 switch (item.getCriticality()) {
                                    case "HIGH":
                                     case "VERY HIGH":
                                         capabilities.setBan_hash("false");
                                        capabilities.setI("false");
                                        capabilities.setK("false");
                                       details.setCriticality(item.getCriticality());
                                        details.setHostname(item.getNames().get(0).getName());
                                        detailsResponse.setCapabilities(capabilities);
                                        detailsResponse.setDetails(details);
                                       
                                        return detailsResponse;
                                     default:
                                        capabilities.setk(ev.get(con.getAlertCapabilitiesAndAssetDetails().getFields().get()));
                                        capabilities.setI(ev.get(con.getAssetDetails().getFields().get()));
                                        capabilities.setl(ev.get(con.getAlertCapabilitiesAndAssetDetails().getFields().get()));
                                        details.setCriticality(item.getCriticality());
                                        details.setHostname(item.getNames().get(0).getName());
                                        detailsResponse.setCapabilities(capabilities);
                                        capabilitiesAndAssetDetailsResponse.setDetails(asset);
                                        detailsResponse.setDeviceid("");
                                        
                                        return detailsResponse;
                                }
                            });
                }).subscribe();
         return detailsResponse;
    }

Problem here is how to return the value returned by lamda inside the map as methods return value as the scope of value returned by lamda remains inside the lamda scope not the method scope.

SRP
  • 3
  • 3
  • Also how can I use switchifempty after method call consume which is creating problem in passing item value to the second step – SRP Dec 18 '20 at 21:46
  • im sorry, but i have no idea what you are asking since im guessing english is not your main language, could you please clarify even more what your question is. – Toerktumlare Dec 18 '20 at 22:30
  • @Toerktumlare No nothing like that ,hopefully pinpointed question for above related issue is value returned by lamda inside map cannot be used to return from method as the value returned by lamda remains inside lamda scope .Hope that clarifies the question?? – SRP Dec 19 '20 at 18:36

1 Answers1

0

you can use zipWith to combine both results and you will get returned a tuple2 or you can use zipWhen if you need request one to complete before request two.

public Mono<DetailsResponse> common(String customerId, String personId) {
    return consume("590204", "4252452").zipWith(actions("432432", "1241441"))
            .flatMap(responses -> {
                final item = responses.getT1();
                final ev = responses.getT2();

                final Capabilities capabilities = new Capabilities();
                final Details details = new Details();
                final DetailsResponse detailsResponse = new DetailsResponse();

                switch (item.getCriticality()) {
                    case "HIGH":
                    case "VERY HIGH":
                        ...
                    return detailsResponse;
                    default:
                        ...                  
                    return detailsResponse;
                }
            });
}
Toerktumlare
  • 12,548
  • 3
  • 35
  • 54
  • Thank you @Toerktumlare that really helped as i am new to this reactor and the stuff. I used zipwith and tuple2 getting the first record for checking the criticality condition. – SRP Dec 19 '20 at 21:28
  • Extending this ,to make it little more complicate ,if i want to have switchifempty condtion after line return consume("5", "42").zipWith(actions("43", "124"))
 below,same problem how it can be done ```return consume(customerId, deviceId) /.switchIfEmpty(Mono.defer(() -> { actionsPermissions("PR00002997", "PR0000000028479").map(ev -> { ev.get(0); ...... return capabilitiesAndAssetDetailsResponse; }); return capabilitiesAndAssetDetailsResponse; })); ``` – SRP Dec 19 '20 at 21:43