java - RxJava. Correct way to generate ViewObject by few sources -


i have 2 entity classes, stores in sqlite: userentity , sessioninfoentity:

public class userentity{     private long id;     private string username;     // .... }  public class sessioninfoentity{     private long id;      private date beginsessiondate;     private date endsessiondate;     // .... } 

user can have many sessions (one-to-many relation).

i have repository, provides necessary methods data (rxjava observables) sqlite database:

public class myrepository{     public observable<list<userentity>> getallusers(){/* ... */}     public observable<sessioninfoentity> getlastsessioninfoforuser(long userid){/* ... */} // returns info of last session user id=userid } 

i need generate next viewobject each user, using myrepository's methods , rxjava:

public class userviewobject {     private string username;     private integer lastsessiondurationinhours;     // .... } 

in turns out need call getlastsessioninfoforuser() each user in order create userviewobject.

question: how can generate userviewobject using rxjava correctly?

i'm trying start doing this way:

myrepository             .getallusers()             .flatmap(lst -> observable.from(lst))             .flatmap(ve -> getlastsessioninfoforuser(ve.getid())             .map(lse -> /* ?????  */) // in operator lose access current user => can't generate userviewobject, because haven't access ve.getusername() method 

p.s.: can't write method in myrepository, returns object whole information.

p.p.s.: in future, new methods added related user entity (like getlastsessioninfoforuser() method).

you can add map in last flatmap. have access ve.

myrepository         .getallusers()         .flatmap(lst -> observable.from(lst))         .flatmap(ve -> getlastsessioninfoforuser(ve.getid()).map(lse -> /* ... */)) 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -