@@ -51,6 +51,8 @@ public class IndividualCatalogMongoDBIterator<E> extends AnnotableCatalogMongoDB
5151 private QueryOptions sampleQueryOptions ;
5252
5353 private IndividualMongoDBAdaptor individualDBAdaptor ;
54+ private QueryOptions fatherQueryOptions ;
55+ private QueryOptions motherQueryOptions ;
5456 private Queue <Document > individualListBuffer ;
5557
5658 private Logger logger ;
@@ -76,6 +78,8 @@ public IndividualCatalogMongoDBIterator(MongoDBIterator<Document> mongoCursor, C
7678 this .sampleQueryOptions = createSampleQueryOptions ();
7779
7880 this .individualDBAdaptor = dbAdaptorFactory .getCatalogIndividualDBAdaptor ();
81+ this .fatherQueryOptions = createInnerQueryOptionsForVersionedEntity (options , IndividualDBAdaptor .QueryParams .FATHER .key (), true );
82+ this .motherQueryOptions = createInnerQueryOptionsForVersionedEntity (options , IndividualDBAdaptor .QueryParams .MOTHER .key (), true );
7983
8084 this .individualListBuffer = new LinkedList <>();
8185 this .logger = LoggerFactory .getLogger (IndividualCatalogMongoDBIterator .class );
@@ -108,7 +112,8 @@ public boolean hasNext() {
108112
109113 private void fetchNextBatch () {
110114 Set <String > sampleVersions = new HashSet <>();
111- Map <Long , List <Document >> individualMap = new HashMap <>();
115+ Map <Long , List <Document >> fatherMap = new HashMap <>();
116+ Map <Long , List <Document >> motherMap = new HashMap <>();
112117
113118 // Get next BUFFER_SIZE documents
114119 int counter = 0 ;
@@ -140,47 +145,14 @@ private void fetchNextBatch() {
140145 if (!options .getBoolean (NATIVE_QUERY )) {
141146 // Extract father and mother uids
142147 Document father = (Document ) individualDocument .get (IndividualDBAdaptor .QueryParams .FATHER .key ());
143- addParentToMap (individualMap , father );
148+ addParentToMap (fatherMap , father );
144149 Document mother = (Document ) individualDocument .get (IndividualDBAdaptor .QueryParams .MOTHER .key ());
145- addParentToMap (individualMap , mother );
150+ addParentToMap (motherMap , mother );
146151 }
147152 }
148153
149- if (!individualMap .isEmpty ()) {
150- // Obtain the parents
151-
152- Query query = new Query (SampleDBAdaptor .QueryParams .UID .key (), individualMap .keySet ());
153- QueryOptions queryOptions = new QueryOptions ()
154- .append (NATIVE_QUERY , true )
155- .append (QueryOptions .INCLUDE , Arrays .asList (
156- IndividualDBAdaptor .QueryParams .ID .key (), IndividualDBAdaptor .QueryParams .VERSION .key (),
157- IndividualDBAdaptor .QueryParams .UID .key ()));
158-
159- try {
160- DataResult <Document > individualDataResult ;
161- if (user != null ) {
162- query .put (IndividualDBAdaptor .QueryParams .STUDY_UID .key (), studyUid );
163- individualDataResult = individualDBAdaptor .nativeGet (clientSession , studyUid , query , queryOptions , user );
164- } else {
165- individualDataResult = individualDBAdaptor .nativeGet (clientSession , query , queryOptions );
166- }
167-
168- for (Document individual : individualDataResult .getResults ()) {
169- List <Document > parentList =
170- individualMap .get (((Number ) individual .get (IndividualDBAdaptor .QueryParams .UID .key ())).longValue ());
171- for (Document parentDocument : parentList ) {
172- parentDocument .put (IndividualDBAdaptor .QueryParams .ID .key (),
173- individual .getString (IndividualDBAdaptor .QueryParams .ID .key ()));
174- parentDocument .put (IndividualDBAdaptor .QueryParams .VERSION .key (),
175- individual .getInteger (IndividualDBAdaptor .QueryParams .VERSION .key ()));
176- }
177- }
178-
179- } catch (CatalogDBException | CatalogAuthorizationException | CatalogParameterException e ) {
180- logger .warn ("Could not obtain the parents associated to the individuals: {}" , e .getMessage (), e );
181- }
182-
183- }
154+ obtainParentInformation (fatherMap , fatherQueryOptions );
155+ obtainParentInformation (motherMap , motherQueryOptions );
184156
185157 if (!sampleVersions .isEmpty ()) {
186158 // Obtain all those samples
@@ -237,6 +209,33 @@ private void fetchNextBatch() {
237209 }
238210 }
239211
212+ private void obtainParentInformation (Map <Long , List <Document >> parentMap , QueryOptions queryOptions ) {
213+ if (!parentMap .isEmpty ()) {
214+ // Obtain the parents
215+ Query query = new Query (IndividualDBAdaptor .QueryParams .UID .key (), parentMap .keySet ());
216+
217+ try {
218+ DataResult <Document > individualDataResult ;
219+ if (user != null ) {
220+ query .put (IndividualDBAdaptor .QueryParams .STUDY_UID .key (), studyUid );
221+ individualDataResult = individualDBAdaptor .nativeGet (clientSession , studyUid , query , queryOptions , user );
222+ } else {
223+ individualDataResult = individualDBAdaptor .nativeGet (clientSession , query , queryOptions );
224+ }
225+
226+ for (Document individual : individualDataResult .getResults ()) {
227+ List <Document > parentList =
228+ parentMap .get (((Number ) individual .get (IndividualDBAdaptor .QueryParams .UID .key ())).longValue ());
229+ for (Document parentDocument : parentList ) {
230+ parentDocument .putAll (individual );
231+ }
232+ }
233+ } catch (CatalogDBException | CatalogAuthorizationException | CatalogParameterException e ) {
234+ logger .warn ("Could not obtain the parents associated to the individuals: {}" , e .getMessage (), e );
235+ }
236+ }
237+ }
238+
240239 private void addParentToMap (Map <Long , List <Document >> individualMap , Document parent ) {
241240 if (parent != null && parent .size () > 0 ) {
242241 long uid = ((Number ) parent .get ("uid" )).longValue ();
0 commit comments