1 package fr.ifremer.tutti.persistence.service.referential;
2
3 /*
4 * #%L
5 * Tutti :: Persistence
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2012 - 2014 Ifremer
10 * %%
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, either version 3 of the
14 * License, or (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 General Public
22 * License along with this program. If not, see
23 * <http://www.gnu.org/licenses/gpl-3.0.html>.
24 * #L%
25 */
26
27 import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor;
28 import fr.ifremer.tutti.persistence.entities.referential.Species;
29 import org.springframework.cache.annotation.CacheEvict;
30 import org.springframework.cache.annotation.Cacheable;
31 import org.springframework.transaction.annotation.Transactional;
32
33 import java.util.Collection;
34 import java.util.List;
35 import java.util.Map;
36
37 /**
38 * Created on 11/3/14.
39 *
40 * @author Tony Chemit - chemit@codelutin.com
41 * @since 3.8
42 */
43 @Transactional(readOnly = true)
44 public interface SpeciesPersistenceService extends TuttiPersistenceServiceImplementor {
45
46 /**
47 * @return all referent species
48 * @since 0.3
49 */
50 @Cacheable(value = "referentSpecies")
51 List<Species> getAllReferentSpecies();
52
53 @Cacheable(value = "referentSpeciesWithObsoletes")
54 List<Species> getAllReferentSpeciesWithObsoletes();
55
56 /**
57 * @return all species
58 * @since 0.3
59 */
60 @Cacheable(value = "species")
61 List<Species> getAllSpecies();
62
63 /**
64 * Obtain a species given his referenceTaxonId.
65 *
66 * @param referenceTaxonId id of the reference taxon of the species to load
67 * @return the species or {@code null} if not found.
68 * @see Species#getReferenceTaxonId()
69 * @see Species#getRefTaxCode()
70 * @since 0.3
71 */
72 @Cacheable(value = "referentSpeciesById", key = "#referenceTaxonId")
73 Species getSpeciesByReferenceTaxonId(Integer referenceTaxonId);
74
75 /**
76 * Obtain a species with external code as vernacular code given his referenceTaxonId.
77 *
78 * <strong>Note:</strong> {@link Species#getRefTaxCode()} will not be
79 * filled by with method.
80 *
81 * @param referenceTaxonId id of the reference taxon of the species to load
82 * @return the species or {@code null} if not found.
83 * @see Species#getReferenceTaxonId()
84 * @see Species#getVernacularCode()
85 * @since 2.0
86 */
87 @Cacheable(value = "referentSpeciesByIdVernacular", key = "#referenceTaxonId")
88 Species getSpeciesByReferenceTaxonIdWithVernacularCode(Integer referenceTaxonId);
89
90 /**
91 * @return the dictionnary of obsolete referent taxon (key: old id, value : new id)
92 * @since 4.2
93 */
94 @Cacheable(value = "obsoleteReferentTaxons")
95 Map<Integer, Integer> getAllObsoleteReferentTaxons();
96
97 /**
98 * Check if the temporary species with the given {@code referenceTaxonId} is used.
99 *
100 * @param referenceTaxonId referenceTaxonId of the species to check
101 * @return {@code true} if taxon is temporary
102 * @since 3.8
103 */
104 boolean isTemporarySpeciesUsed(Integer referenceTaxonId);
105
106 /**
107 * Add temporary species.
108 *
109 * @param species species to add
110 * @return added species
111 * @since 3.14
112 */
113 @Transactional(readOnly = false)
114 @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons", "referentSpeciesWithObsoletes"}, allEntries = true)
115 List<Species> addTemporarySpecies(List<Species> species);
116
117 /**
118 * Update temporary species.
119 *
120 * @param species species to update
121 * @return updated species
122 * @since 3.14
123 */
124 @Transactional(readOnly = false)
125 @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons", "referentSpeciesWithObsoletes"}, allEntries = true)
126 List<Species> updateTemporarySpecies(List<Species> species);
127
128 /**
129 * Link temporary species. (Means get existing references using species natural ids).
130 *
131 * @param species species to link
132 * @return linked species
133 * @since 3.14
134 */
135 List<Species> linkTemporarySpecies(List<Species> species);
136
137 /**
138 * Replace the {@code source} species by
139 * the {@code target} one in all data.
140 *
141 * @param source the source species to replace
142 * @param target the target species to use
143 * @param delete flag to delete the temporary vessel after replacement
144 * @since 3.6
145 */
146 @Transactional(readOnly = false)
147 @CacheEvict(value = {"fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache",
148 "species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons", "referentSpeciesWithObsoletes"},
149 allEntries = true)
150 void replaceSpecies(Species source, Species target, boolean delete);
151
152 /**
153 * Delete the temporary species with the given {@code referenceTaxonId}.
154 *
155 * @param referenceTaxonIds referenceTaxonId of the species to remove
156 * @since 3.8
157 */
158 @Transactional(readOnly = false)
159 @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons", "referentSpeciesWithObsoletes"}, allEntries = true)
160 void deleteTemporarySpecies(Collection<Integer> referenceTaxonIds);
161
162 /**
163 * Delete the temporary species with the given {@code referenceTaxonId}.
164 *
165 * @param referenceTaxonId reference taxonId of the species to remove
166 * @since 3.8
167 */
168 @Transactional(readOnly = false)
169 @CacheEvict(value = {"species", "referentSpecies", "referentSpeciesById", "referentSpeciesByIdVernacular", "obsoleteReferentTaxons", "referentSpeciesWithObsoletes"}, allEntries = true)
170 void deleteTemporarySpecies(Integer referenceTaxonId);
171
172 }