/******************************************************************************************************************* * * Loads the taxa. If a {@link Taxon} is contained in the {@link Intent}, the sub taxa will be loaded and the cache * disabled since there are no taxa with a number of sub taxa so large to create performance problems while sorting. * If no {@code Taxon} is contained in the {@code Intent}, all the taxa with the {@link Rank} bound to this * controller will be loaded; and the cache enabled if the rank is {@code SPECIES} since there can be so many * items to create performance problems when sorting. The latter behaviour also happens if the {@code Intent} * contains a {@code Taxon}, but it's not from the current taxonomy. * * TODO: This management of cache is cumbersome. Using Finders with sorting capabilities could be a solution, * moving all the caching logics to the Finder themselves (and eventually could opaquely implement sorting * based on OpenSesame query that could be fast enough to avoid caching). * ******************************************************************************************************************/ @Nonnull private void loadTaxa (final @Nonnull Intent intent) { taxa.clear(); cacheEnabled = false; try { taxa.addAll(TaxonIntentHelper.getTaxon(intent).findSubTaxa().results()); } catch (NotFoundException e) // no Taxon in the Intent { taxa.addAll(taxonomyPreferences.get().getTaxonomy().findTaxa().withRank(rank).results()); cacheEnabled = rank == Rank.SPECIES; } ensureTaxaAreSorted(); }