View Javadoc
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.data.Cruise;
29  import fr.ifremer.tutti.persistence.entities.referential.Vessel;
30  import org.springframework.cache.annotation.CacheEvict;
31  import org.springframework.cache.annotation.Cacheable;
32  import org.springframework.transaction.annotation.Transactional;
33  
34  import java.util.Collection;
35  import java.util.List;
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 VesselPersistenceService extends TuttiPersistenceServiceImplementor {
45  
46      /**
47       * @return all scientific vessels (used by a {@link Cruise}).
48       * @see Cruise#getVessel()
49       * @see Cruise#setVessel(Vessel)
50       * @since 0.3
51       */
52      List<Vessel> getAllScientificVessel();
53  
54      /**
55       * @return all commercial vessels (used by a {@link Cruise}).
56       * @see Cruise#getVessel()
57       * @see Cruise#setVessel(Vessel)
58       * @since 0.3
59       */
60      @Cacheable(value = "fishingVessels")
61      List<Vessel> getAllFishingVessel();
62  
63      @Cacheable(value = "vesselsWithObsoletes")
64      List<Vessel> getAllVesselWithObsoletes();
65  
66      /**
67       * @param vesselCode code of the vessel to find
68       * @return the vessel
69       * @since 0.3
70       */
71      @Cacheable(value = "vesselByCode", key = "#vesselCode")
72      Vessel getVessel(String vesselCode);
73  
74      /**
75       * Check if the temporary vessel with the given {@code id} is used.
76       *
77       * @param code code of the vessel to remove
78       * @return {@code true} if vessel is temporary
79       * @since 3.8
80       */
81      boolean isTemporaryVesselUsed(String code);
82  
83      /**
84       * Add temporary vessels.
85       *
86       * @param vessels vessels to add
87       * @return added vessels
88       * @since 3.14
89       */
90      @Transactional(readOnly = false)
91      @CacheEvict(value = {"fishingVessels", "vesselByCode", "vesselsWithObsoletes"}, allEntries = true)
92      List<Vessel> addTemporaryVessels(List<Vessel> vessels);
93  
94      /**
95       * Update temporary vessels.
96       *
97       * @param vessels vessels to update
98       * @return updated vessels
99       * @since 3.14
100      */
101     @Transactional(readOnly = false)
102     @CacheEvict(value = {"fishingVessels", "vesselByCode", "vesselsWithObsoletes"}, allEntries = true)
103     List<Vessel> updateTemporaryVessels(List<Vessel> vessels);
104 
105     /**
106      * Link temporary vessels. (Means get existing references using vessels natural ids).
107      *
108      * @param vessels vessels to link
109      * @return linked vessels
110      * @since 3.14
111      */
112     List<Vessel> linkTemporaryVessels(List<Vessel> vessels);
113 
114     /**
115      * Replace the {@code source} vessel by
116      * the {@code target} one in all data.
117      *
118      * @param source the source vessel to replace
119      * @param target the target vessel to use
120      * @param delete flag to delete the temporary vessel after replacement
121      * @since 3.6
122      */
123     @Transactional(readOnly = false)
124     @CacheEvict(value = {"fr.ifremer.adagio.core.dao.data.batch.CatchBatchCache", "fishingVessels", "vesselByCode", "vesselsWithObsoletes"},
125             allEntries = true)
126     void replaceVessel(Vessel source, Vessel target, boolean delete);
127 
128     /**
129      * Delete the temporary vessels with the given {@code codes}.
130      *
131      * @param codes code of the vessels to remove
132      * @since 3.8
133      */
134     @Transactional(readOnly = false)
135     @CacheEvict(value = {"fishingVessels", "vesselByCode", "vesselsWithObsoletes"}, allEntries = true)
136     void deleteTemporaryVessels(Collection<String> codes);
137 
138     /**
139      * Delete the temporary vessel with the given {@code code}.
140      *
141      * @param code code of the vessel to remove
142      * @since 3.8
143      */
144     @Transactional(readOnly = false)
145     @CacheEvict(value = {"fishingVessels", "vesselByCode", "vesselsWithObsoletes"}, allEntries = true)
146     void deleteTemporaryVessel(String code);
147 
148 }