001package fr.ifremer.adagio.core.dao.data.batch; 002 003/* 004 * #%L 005 * SIH-Adagio Core for Allegro 006 * $Id: CatchBatchExtendDao.java 12089 2014-05-20 19:37:05Z bl05b3e $ 007 * $HeadURL: https://forge.ifremer.fr/svn/sih-adagio/tags/adagio-3.5.6/core/src/main/java/fr/ifremer/adagio/core/dao/data/batch/CatchBatchExtendDao.java $ 008 * %% 009 * Copyright (C) 2012 - 2013 Ifremer 010 * %% 011 * This program is free software: you can redistribute it and/or modify 012 * it under the terms of the GNU Affero General Public License as published by 013 * the Free Software Foundation, either version 3 of the License, or 014 * (at your option) any later version. 015 * 016 * This program is distributed in the hope that it will be useful, 017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 019 * GNU General Public License for more details. 020 * 021 * You should have received a copy of the GNU Affero General Public License 022 * along with this program. If not, see <http://www.gnu.org/licenses/>. 023 * #L% 024 */ 025 026import java.util.Collection; 027import java.util.List; 028 029import org.springframework.cache.annotation.CacheEvict; 030import org.springframework.cache.annotation.Cacheable; 031 032import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationError; 033import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidationException; 034import fr.ifremer.adagio.core.dao.data.batch.validator.CatchBatchValidator; 035import fr.ifremer.adagio.core.dao.data.measure.QuantificationMeasurement; 036import fr.ifremer.adagio.core.dao.data.measure.SortingMeasurement; 037import org.springframework.dao.DataRetrievalFailureException; 038 039public interface CatchBatchExtendDao extends CatchBatchDao { 040 041 /** 042 * Property name used to walk in a sorting batch identified by a pmfm. 043 * 044 * @see #getSortingBatch(Collection, Object...) 045 * @since 3.3.6 046 */ 047 String PMFM_ID = "pmfmId"; 048 049 /** 050 * Property name used to walk in a sorting batch identified by a reference 051 * taxon. 052 * 053 * @see #getSortingBatch(Collection, Object...) 054 * @since 3.3.6 055 */ 056 String REFERENCE_TAXON_ID = "referenceTaxonId"; 057 058 void registerCatchBatchValidator(CatchBatchValidator validator); 059 060 void unregisterCatchBatchValidator(CatchBatchValidator validator); 061 062 /** 063 * Load a catch batch and all its childrens. (No validation) 064 * 065 * @param catchBatchId 066 * id of the catch batch to load 067 * @return the catch batch with all children, or null if not found 068 */ 069 CatchBatch loadFullTree(Integer catchBatchId); 070 071 /** 072 * Load a catch batch and all its childrens. 073 * 074 * @param catchBatchId 075 * id of the catch batch to load 076 * @param validate 077 * if true, method validate() is typically called 078 * @param quickFix 079 * if true, will try to quick fix validation error 080 * @return the catch batch with all children 081 * @throws CatchBatchValidationException 082 * only if valaidate = true, and error found (with gravity ERROR or FATAL) 083 */ 084 CatchBatch loadFullTree(Integer catchBatchId, boolean validate, boolean quickFix) throws CatchBatchValidationException; 085 086 /** 087 * Method typically using by other loadFullTree() methods. 088 * Please do not call directly, but throw other methods. 089 * 090 * @param catchBatchId 091 * id of the catch batch to load 092 * @param useCache 093 * must the be enable ? 094 * @param forceReload 095 * is cache is enable, force a eviction to refresh the cache 096 * @return A full batch tree 097 */ 098 @Cacheable(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", key = "#catchBatchId", condition = "#useCache == true") 099 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", beforeInvocation = true, key = "#catchBatchId", condition = "#useCache==true and #forceReload==true") 100 CatchBatch loadFullTreeWithCache(Integer catchBatchId, boolean useCache, boolean forceReload); 101 102 /** 103 * Validate a catch batch, using all registered validators that are enable for this catchBatch 104 * 105 * @param catchBatch 106 * batch to validate 107 * @return null if validation has no errors, or a list of errors found. 108 */ 109 List<CatchBatchValidationError> validate(CatchBatch catchBatch); 110 111 /** 112 * retrieve a sorting batch, from path give in params. i.e:<br/> 113 * getSortingBatch(sortingBatchCollection,<br/> 114 * PMFM_ID, PmfmId.SEX, QualitativeValueId.FEMALE) 115 * 116 * @param batchs 117 * incoming batchs to filter 118 * @param params 119 * @return 120 */ 121 SortingBatch getSortingBatch(Collection<Batch> batchs, Object... params); 122 123 /** 124 * Retrieve a child (in all tree depth) of the given catch batch, using an sorting batch id. 125 * 126 * @param catchBatch 127 * @param sortingBatchId 128 * id of the sorting batch to retrieve 129 * @return the sorting batch found 130 * @throws DataRetrievalFailureException 131 * if the sorting batch could not be found 132 */ 133 SortingBatch getSortingBatchById(CatchBatch catchBatch, Integer sortingBatchId); 134 135 /** 136 * @param fishingOperationId 137 * id of the fishing operation 138 * @return {@code true} if there is a catchBatch for the given fishing 139 * operation, {@code false} otherwise. 140 * @since 3.3.6 141 */ 142 boolean isCatchBatchExistsForFishingOperation(Integer fishingOperationId); 143 144 /** 145 * Retrieve a catch batch Id, from a fishing operation id 146 * 147 * @param fishingOperationId 148 * id of the fishing operation 149 * @return the fid of the catch batch associated with the fishing operation 150 * @throws DataRetrievalFailureException 151 * if catch batch id not found 152 */ 153 Integer getIdByFishingOperationId(Integer fishingOperationId) throws DataRetrievalFailureException; 154 155 /** 156 * Retrieve a catch batch Id, from a sorting batch id 157 * 158 * @param sortingBatchId 159 * @return 160 * @throws DataRetrievalFailureException 161 * if catch batch id not found 162 */ 163 Integer getIdBySortingBatchId(Integer sortingBatchId) throws DataRetrievalFailureException; 164 165 /** 166 * Remove a batch, with all children (could be CatchBatch or a SortingBatch) 167 * -> Method optimize for cache using in loadFullTree() 168 * 169 * @param batchId 170 * id of the batch to remove 171 */ 172 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", key = "#parentCatchBatch.id") 173 void removeWithChildren(Integer batchId, CatchBatch parentCatchBatch); 174 175 /** 176 * Remove a batch, with all children (could be CatchBatch or a SortingBatch) 177 * -> Method NOT optimize for cache using in loadFullTree : will evict all the cache 178 * 179 * @param batchId 180 * id of the batch to remove 181 */ 182 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", allEntries = true) 183 void removeWithChildren(Integer batchId); 184 185 /** 186 * Remove a batch and evict all the cache 187 * 188 * @param catchBatchId 189 * id of the catch batch to remove 190 */ 191 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", allEntries = true) 192 void remove(Integer catchBatchId); 193 194 /** 195 * Walk throw the batch given by the id and grab ids of all his shell. 196 * 197 * <strong>Note:</strong> Will use a postorder traversal (child before 198 * parent) to keep ids. 199 * 200 * @param batchId 201 * id of the batch to scan 202 * @return list of all children ids in postorder traversal order 203 * @since 3.3.6 204 */ 205 List<Integer> getAllChildrenIds(Integer batchId); 206 207 SortingMeasurement getSortingMeasurement(SortingBatch sortingBatch, Integer pmfmId, Integer recorderDepartmentId, boolean createIfNotExists); 208 209 QuantificationMeasurement getQuantificationMeasurement(Batch batch, Integer pmfmId, Integer recorderDepartmentId, boolean createIfNotExists); 210 211 QuantificationMeasurement setQuantificationMeasurement(Batch batch, Integer pmfmId, Integer recorderDepartmentId, Float weightValue, 212 boolean isReferenceQuantitification); 213 214 SortingMeasurement getInheritedSortingMeasurement(SortingBatch sortingBatch, Integer pmfmId); 215 216 /** 217 * Change the species of a batch. 218 * -> Method NOT optimize for cache using in loadFullTree : will evict all the cache 219 * 220 * @param batchId 221 * @param referenceTaxonId 222 */ 223 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", allEntries = true) 224 void setSortingBatchReferenceTaxon(String batchId, Integer referenceTaxonId); 225 226 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", key = "#catchBatch.id") 227 void update(CatchBatch catchBatch); 228 229 /** 230 * Create a new batch 231 * 232 * @param sortingBatch 233 * @param parentCatchBatch 234 */ 235 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", key = "#parentCatchBatch.id") 236 SortingBatch createSortingBatch(SortingBatch sortingBatch, CatchBatch parentCatchBatch); 237 238 /** 239 * Load a batch. 240 * If the given catchBatch has been load using loadFullTree, this 241 * method will use cache stored inside the catchBatch 242 * 243 * @param sortingBatchId 244 * @param parentCatchBatch 245 * @return 246 */ 247 SortingBatch loadSortingBatch(Integer sortingBatchId, CatchBatch parentCatchBatch); 248 249 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", key = "#parentCatchBatch.id") 250 void updateSortingBatch(SortingBatch sortingBatch, CatchBatch parentCatchBatch); 251 252 @CacheEvict(value = "fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", key = "#parentCatchBatch.id") 253 void updateSortingBatch(List<SortingBatch> sortingBatchs, CatchBatch parentCatchBatch); 254 255}