View Javadoc
1   package fr.ifremer.reefdb.dao.referential.taxon;
2   
3   /*
4    * #%L
5    * Reef DB :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import com.google.common.collect.Multimap;
27  import fr.ifremer.reefdb.dto.referential.TaxonDTO;
28  import fr.ifremer.reefdb.dto.referential.TaxonomicLevelDTO;
29  import org.springframework.cache.annotation.CacheEvict;
30  import org.springframework.cache.annotation.Cacheable;
31  
32  import javax.annotation.Nonnull;
33  import java.time.LocalDate;
34  import java.util.List;
35  import java.util.Map;
36  
37  /**
38   * <p>ReefDbTaxonNameDao interface.</p>
39   *
40   */
41  public interface ReefDbTaxonNameDao {
42  
43      String TAXON_NAME_BY_ID_CACHE = "taxon_name_by_id";
44      String TAXON_NAMES_BY_IDS_CACHE = "taxon_names_by_ids";
45      String TAXON_NAME_BY_REFERENCE_ID_CACHE = "taxon_name_by_reference_id";
46      String ALL_TAXON_NAMES_CACHE = "all_taxon_names";
47      String TAXON_NAME_BY_TAXON_GROUP_ID_CACHE = "taxon_name_by_taxon_group_id";
48      String COMPOSITE_TAXON_NAMES_BY_TAXON_NAME_ID_CACHE = "composite_taxon_names_by_taxon_name_id";
49      String TAX_REF_BY_TAXON_NAME_ID_CACHE = "tax_ref_by_taxon_name_id";
50      String WORMS_BY_TAXON_NAME_ID_CACHE = "worms_by_taxon_name_id";
51  
52      /**
53       * All taxon names.
54       *
55       * @return a {@link java.util.List} object.
56       */
57      @Cacheable(value = ALL_TAXON_NAMES_CACHE)
58      List<TaxonDTO> getAllTaxonNames();
59  
60      /**
61       * <p>getTaxonNameById.</p>
62       *
63       * @param taxonId a int.
64       * @return a {@link fr.ifremer.reefdb.dto.referential.TaxonDTO} object.
65       */
66      @Cacheable(value = TAXON_NAME_BY_ID_CACHE)
67      TaxonDTO getTaxonNameById(int taxonId);
68  
69      /**
70       * <p>getTaxonNamesByIds.</p>
71       *
72       * @param taxonIds a {@link java.util.List} object.
73       * @return a {@link java.util.List} object.
74       */
75      @Cacheable(value = TAXON_NAMES_BY_IDS_CACHE)
76      List<TaxonDTO> getTaxonNamesByIds(List<Integer> taxonIds);
77  
78      /**
79       * <p>getTaxonNameByReferenceId.</p>
80       *
81       * @param referenceTaxonId a int.
82       * @return a {@link fr.ifremer.reefdb.dto.referential.TaxonDTO} object.
83       */
84      @Cacheable(value = TAXON_NAME_BY_REFERENCE_ID_CACHE)
85      TaxonDTO getTaxonNameByReferenceId(int referenceTaxonId);
86  
87      /**
88       * Get All Taxon Names of the Taxon Group
89       * Beware to reset time on date parameter before call this method
90       *
91       * @return a {@link com.google.common.collect.Multimap} object.
92       * @param date
93       */
94      @Cacheable(value = TAXON_NAME_BY_TAXON_GROUP_ID_CACHE)
95      Multimap<Integer, TaxonDTO> getAllTaxonNamesMapByTaxonGroupId(@Nonnull LocalDate date);
96  
97      /**
98       * <p>findTaxonNamesByCriteria.</p>
99       *
100      * @param levelCode a {@link java.lang.String} object.
101      * @param name a {@link java.lang.String} object.
102      * @param isStrictName a boolean.
103      * @param isLocal      @return lightweight taxon names (without parent, composites and referent taxons)
104      * @return a {@link java.util.List} object.
105      */
106     List<TaxonDTO> findTaxonNamesByCriteria(String levelCode, String name, boolean isStrictName, Boolean isLocal);
107 
108     /**
109      * <p>findFullTaxonNamesByCriteria.</p>
110      *
111      * @param levelCode a {@link java.lang.String} object.
112      * @param name a {@link java.lang.String} object.
113      * @param isStrictName a boolean.
114      * @param isLocal      @return taxon names with complete information (parent, composites, referent taxons)
115      * @return a {@link java.util.List} object.
116      */
117     List<TaxonDTO> findFullTaxonNamesByCriteria(String levelCode, String name, boolean isStrictName, Boolean isLocal);
118 
119     /**
120      * Fill all properties of the taxon list
121      *
122      * @param taxons a {@link java.util.List} object.
123      */
124     void fillTaxonsProperties(List<TaxonDTO> taxons);
125 
126     /**
127      * <p>fillParentAndReferent.</p>
128      *
129      * @param taxon a {@link fr.ifremer.reefdb.dto.referential.TaxonDTO} object.
130      */
131     void fillParentAndReferent(TaxonDTO taxon);
132 
133     /**
134      * <p>fillReferent.</p>
135      *
136      * @param taxons a {@link TaxonDTO} object.
137      */
138     void fillReferents(List<TaxonDTO> taxons);
139 
140     /**
141      * <p>getAllTaxonomicLevels.</p>
142      *
143      * @return a {@link java.util.List} object.
144      */
145     @Cacheable(value = "all_taxonomic_levels")
146     List<TaxonomicLevelDTO> getAllTaxonomicLevels();
147 
148     /**
149      * <p>getCompositeTaxonNames.</p>
150      *
151      * @param taxonNameId a {@link java.lang.Integer} object.
152      * @return a {@link java.util.List} object.
153      */
154     @Cacheable(value = COMPOSITE_TAXON_NAMES_BY_TAXON_NAME_ID_CACHE)
155     List<TaxonDTO> getCompositeTaxonNames(Integer taxonNameId);
156 
157     /**
158      * <p>getTaxRefByTaxonNameId.</p>
159      *
160      * @return a {@link java.util.Map} object.
161      */
162     @Cacheable(value = TAX_REF_BY_TAXON_NAME_ID_CACHE)
163     Map<Integer, String> getTaxRefByTaxonNameId();
164 
165     /**
166      * <p>getWormsByTaxonNameId.</p>
167      *
168      * @return a {@link java.util.Map} object.
169      */
170     @Cacheable(value = WORMS_BY_TAXON_NAME_ID_CACHE)
171     Map<Integer, String> getWormsByTaxonNameId();
172 
173     /**
174      * <p>saveTaxons.</p>
175      *
176      * @param taxons a {@link java.util.List} object.
177      */
178     @CacheEvict(value = {
179             TAXON_NAME_BY_ID_CACHE,
180             TAXON_NAMES_BY_IDS_CACHE,
181             TAXON_NAME_BY_REFERENCE_ID_CACHE,
182             ALL_TAXON_NAMES_CACHE,
183             TAXON_NAME_BY_TAXON_GROUP_ID_CACHE,
184             COMPOSITE_TAXON_NAMES_BY_TAXON_NAME_ID_CACHE
185     }, allEntries = true)
186     void saveTaxons(List<? extends TaxonDTO> taxons);
187 
188     /**
189      * <p>deleteTaxons.</p>
190      *
191      * @param taxonIds a {@link java.util.List} object.
192      */
193     @CacheEvict(value = {
194             TAXON_NAME_BY_ID_CACHE,
195             TAXON_NAMES_BY_IDS_CACHE,
196             TAXON_NAME_BY_REFERENCE_ID_CACHE,
197             ALL_TAXON_NAMES_CACHE,
198             TAXON_NAME_BY_TAXON_GROUP_ID_CACHE,
199             COMPOSITE_TAXON_NAMES_BY_TAXON_NAME_ID_CACHE
200     }, allEntries = true)
201     void deleteTaxons(List<Integer> taxonIds);
202 
203     /**
204      * <p>replaceTemporaryTaxon.</p>
205      *
206      * @param sourceId a {@link java.lang.Integer} object.
207      * @param sourceReferenceId a {@link java.lang.Integer} object.
208      * @param targetId a {@link java.lang.Integer} object.
209      * @param targetReferenceId a {@link java.lang.Integer} object.
210      * @param delete a boolean.
211      */
212     @CacheEvict(value = {
213             TAXON_NAME_BY_ID_CACHE,
214             TAXON_NAMES_BY_IDS_CACHE,
215             TAXON_NAME_BY_REFERENCE_ID_CACHE,
216             ALL_TAXON_NAMES_CACHE,
217             TAXON_NAME_BY_TAXON_GROUP_ID_CACHE,
218             COMPOSITE_TAXON_NAMES_BY_TAXON_NAME_ID_CACHE
219     }, allEntries = true)
220     void replaceTemporaryTaxon(Integer sourceId, Integer sourceReferenceId, Integer targetId, Integer targetReferenceId, boolean delete);
221 
222     /**
223      * <p>isTaxonNameUsedInReferential.</p>
224      *
225      * @param taxonId a int.
226      * @return a boolean.
227      */
228     boolean isTaxonNameUsedInReferential(int taxonId);
229 
230     /**
231      * <p>isReferenceTaxonUsedInReferential.</p>
232      *
233      * @param refTaxonId a int.
234      * @param excludedTaxonNameId a int.
235      * @return a boolean.
236      */
237     boolean isReferenceTaxonUsedInReferential(int refTaxonId, int excludedTaxonNameId);
238 
239     /**
240      * <p>isReferenceTaxonUsedInData.</p>
241      *
242      * @param refTaxonId a int.
243      * @return a boolean.
244      */
245     boolean isReferenceTaxonUsedInData(int refTaxonId);
246 
247     /**
248      * <p>isReferenceTaxonUsedInValidatedData.</p>
249      *
250      * @param refTaxonId a int.
251      * @return a boolean.
252      */
253     boolean isReferenceTaxonUsedInValidatedData(int refTaxonId);
254 }