I have two database calls one returning a Flux and another returning a Mono
The LegacyPerson class contains an legacyPersonId and a name. The PersonKey class contains and legacyPersonId and a PersonID
I want to get as result an Mono<List> where the Person class contains an legacyPersonId and an PersonId. So i have to determine the id for every legacyPerson in the flux without blocking.
class LegacyPerson {
Integer legacyId;
String name;
}
@Builder
class Person {
UUID id;
Integer legacyId;
String name;
}
class PersonKey {
UUID id;
Integer legacyId;
}
two repositories:
@Repository
public interface RepositoryKey extends ReactiveCrudRepository<PersonKey, UUID> {
Mono<PersonKey> findByPensioennummer(Integer pensioennummer);
}
@Repository
public interface RepositoryPerson extends ReactiveCrudRepository<LegacyPerson, UUID> {
Flux<LegacyPerson> findByName(String name);
}
This is what i have tried
class Service {
RepositoryKey repKey;
RepositoryPerson repPerson;
public Mono<List<Person>> getPersons(String name) {
Flux<LegacyPerson> legacyPersonFlux = repPerson.findByName(name);
legacyPersonFlux.map(person -> map(repKey.findByPensioennummer(person.legacyId), person));
}
private Person map(UUID id, LegacyPerson legacyPerson) {
return Person.builder().id(id).name(legacyPerson.name).legacyId(legacyPerson.legacyId).build();
}
}
I get an error that the map method expects an UUID an not an Mono . I can change it to Mono but I don't want to change the Id in my domain object Person.
Any help would be greatly appreciated!