View Javadoc
1   package fr.ifremer.tutti.persistence.service;
2   
3   /*
4    * #%L
5    * Tutti :: Persistence
6    * %%
7    * Copyright (C) 2012 - 2014 Ifremer
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the 
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public 
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.collect.Multimap;
26  import fr.ifremer.tutti.persistence.InvalidBatchModelException;
27  import fr.ifremer.tutti.persistence.TuttiPersistenceServiceImplementor;
28  import fr.ifremer.tutti.persistence.entities.data.BatchContainer;
29  import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
30  import fr.ifremer.tutti.persistence.entities.data.SpeciesBatchFrequency;
31  import fr.ifremer.tutti.persistence.entities.referential.Species;
32  import org.springframework.transaction.annotation.Transactional;
33  
34  import java.util.Collection;
35  import java.util.List;
36  import java.util.Set;
37  
38  /**
39   * Service to persist {@link SpeciesBatch}.
40   *
41   * @author Tony Chemit - chemit@codelutin.com
42   * @since 1.2
43   */
44  @Transactional(readOnly = true)
45  public interface SpeciesBatchPersistenceService extends TuttiPersistenceServiceImplementor {
46  
47      //------------------------------------------------------------------------//
48      //-- SpeciesBatch methods                                               --//
49      //------------------------------------------------------------------------//
50  
51      /**
52       * Get the batch parent of all root {@link SpeciesBatch} for the given
53       * fishing operation.
54       *
55       * <strong>Note:</strong> All childs of the batch should be loaded here.
56       *
57       * @param fishingOperationId if of the fishing operation to seek
58       * @param validateTree       flag to validate sample category model
59       * @return the list of root {@link SpeciesBatch}
60       * @throws InvalidBatchModelException if batch does not respect the sample category model
61       * @since 2.4
62       */
63      BatchContainer<SpeciesBatch> getRootSpeciesBatch(Integer fishingOperationId,
64                                                       boolean validateTree) throws InvalidBatchModelException;
65  
66      /**
67       * Récupérer les identifiants de tous les lots de la descendance du lot donné.
68       *
69       * @param id identifiant du lot parent
70       * @return l'ensemble des identifiants de toute la descendance d'un lot
71       */
72      Set<Integer> getBatchChildIds(Integer id);
73  
74      @Transactional(readOnly = false)
75      SpeciesBatch createSpeciesBatch(SpeciesBatch bean, Integer parentBatchId, boolean computeRankOrder);
76  
77      @Transactional(readOnly = false)
78      Collection<SpeciesBatch> createSpeciesBatches(Integer fishingOperationId, Collection<SpeciesBatch> beans);
79  
80      @Transactional(readOnly = false)
81      SpeciesBatch saveSpeciesBatch(SpeciesBatch bean);
82  
83      @Transactional(readOnly = false)
84      void deleteSpeciesBatch(Integer id);
85  
86      @Transactional(readOnly = false)
87      void deleteSpeciesSubBatch(Integer id);
88  
89      /**
90       * Change the species in the given {@code batchId} and in all his
91       * sub batches.
92       *  @param batchId id of the root species batch to treat
93       * @param species species to affect to all batches
94       */
95      @Transactional(readOnly = false)
96      void changeSpeciesBatchSpecies(Integer batchId, Species species);
97  
98      /**
99       * Get all the batches to confirm
100      *
101      * @param fishingOperationId if of the fishing operation to seek
102      * @return the list of {@link SpeciesBatch} to confirm
103      * @throws InvalidBatchModelException if batch does not respect the sample category model
104      * @since 3.13
105      */
106     List<SpeciesBatch> getAllSpeciesBatchToConfirm(Integer fishingOperationId) throws InvalidBatchModelException;
107 
108     //------------------------------------------------------------------------//
109     //-- SpeciesBatchFrequency methods                                      --//
110     //------------------------------------------------------------------------//
111 
112     /**
113      * Get all frequencies for the given species batch.
114      *
115      * @param speciesBatchId the id of the species batch to seek.
116      * @return the list of frequencies for the given specues batch id
117      * @since 1.0
118      */
119     List<SpeciesBatchFrequency> getAllSpeciesBatchFrequency(Integer speciesBatchId);
120 
121     /**
122      * Get all frequencies for the given root species batch container.
123      *
124      * @param batchContainer the root batch containter
125      * @return the list of species frequencies indexed by their species
126      * @since 3.3
127      */
128     Multimap<Species, SpeciesBatchFrequency> getAllSpeciesBatchFrequencyForBatch(BatchContainer<SpeciesBatch> batchContainer);
129 
130     /**
131      * Save all given {@link SpeciesBatchFrequency} into the given
132      * {@code speciesBatchId}. If some are not existing then creates them.
133      *
134      * <strong>Note:</strong> This will as a side effect remove all previous frequency for this species batch.
135      *
136      * @param speciesBatchId id of the {@link SpeciesBatch} to use
137      * @param frequencies    list of frequencies to create or update
138      * @return the persisted list of frequencies
139      * @since 1.0
140      */
141     @Transactional(readOnly = false)
142     List<SpeciesBatchFrequency> saveSpeciesBatchFrequency(Integer speciesBatchId,
143                                                           List<SpeciesBatchFrequency> frequencies);
144 
145 }