View Javadoc
1   package fr.ifremer.tutti.service.export.toconfirmreport;
2   
3   /*
4    * #%L
5    * Tutti :: Service
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2012 - 2015 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.entities.data.CatchBatch;
28  import fr.ifremer.tutti.persistence.entities.data.FishingOperation;
29  import fr.ifremer.tutti.persistence.entities.data.SpeciesBatch;
30  import fr.ifremer.tutti.service.PersistenceService;
31  import org.apache.commons.collections4.CollectionUtils;
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  import java.util.List;
36  
37  /**
38   * Contains a fishing operation data need to get species or benthos batch to report.
39   *
40   * Created on 2/9/15.
41   *
42   * @author Tony Chemit - chemit@codelutin.com
43   * @since 3.13
44   */
45  public class ToConfirmReportFishingOperationData {
46  
47      /** Logger. */
48      private static final Log log = LogFactory.getLog(ToConfirmReportFishingOperationData.class);
49  
50      public static ToConfirmReportFishingOperationData create(PersistenceService persistenceService,
51                                                               Integer fishingOperationId) {
52  
53          boolean withCatchBatch = persistenceService.isFishingOperationWithCatchBatch(fishingOperationId);
54  
55          ToConfirmReportFishingOperationData result;
56  
57          if (!withCatchBatch) {
58  
59              if (log.isWarnEnabled()) {
60                  log.warn("Skip fishing operation " + fishingOperationId + " since no catchBatch associated.");
61              }
62              result = null;
63  
64          } else {
65  
66              FishingOperation fishingOperation = persistenceService.getFishingOperation(fishingOperationId);
67  
68              CatchBatch catchBatch = persistenceService.getCatchBatchFromFishingOperation(fishingOperationId);
69  
70              List<SpeciesBatch> speciesBatchToConfirm = persistenceService.getAllSpeciesBatchToConfirm(fishingOperationId);
71  
72              List<SpeciesBatch> benthosBatchToConfirm = persistenceService.getAllBenthosBatchToConfirm(fishingOperationId);
73  
74              if (CollectionUtils.isEmpty(speciesBatchToConfirm) && CollectionUtils.isEmpty(benthosBatchToConfirm)) {
75  
76                  if (log.isInfoEnabled()) {
77                      log.info("No species nor benthos to confirm for fishing operation: " + fishingOperationId);
78                  }
79                  result = null;
80  
81              } else {
82  
83                  if (log.isInfoEnabled()) {
84                      log.info("Found some species or benthos to confirm for fishing operation: " + fishingOperationId);
85                  }
86                  result = new ToConfirmReportFishingOperationData(fishingOperation,
87                                                                   catchBatch,
88                                                                   speciesBatchToConfirm,
89                                                                   benthosBatchToConfirm);
90              }
91  
92          }
93  
94          return result;
95  
96      }
97  
98      final FishingOperation fishingOperation;
99  
100     final CatchBatch catchBatch;
101 
102     final List<SpeciesBatch> speciesBatchToConfirm;
103 
104     final List<SpeciesBatch> benthosBatchToConfirm;
105 
106     public FishingOperation getFishingOperation() {
107         return fishingOperation;
108     }
109 
110     public CatchBatch getCatchBatch() {
111         return catchBatch;
112     }
113 
114     public List<SpeciesBatch> getSpeciesBatchToConfirm() {
115         return speciesBatchToConfirm;
116     }
117 
118     public boolean isWithSpeciesBatchToConfirm() {
119         return CollectionUtils.isNotEmpty(speciesBatchToConfirm);
120     }
121 
122     public List<SpeciesBatch> getBenthosBatchToConfirm() {
123         return benthosBatchToConfirm;
124     }
125 
126     public boolean isWithBenthosBatchToConfirm() {
127         return CollectionUtils.isNotEmpty(benthosBatchToConfirm);
128     }
129 
130     private ToConfirmReportFishingOperationData(FishingOperation fishingOperation,
131                                                 CatchBatch catchBatch,
132                                                 List<SpeciesBatch> speciesBatchToConfirm,
133                                                 List<SpeciesBatch> benthosBatchToConfirm) {
134         this.fishingOperation = fishingOperation;
135         this.catchBatch = catchBatch;
136         this.speciesBatchToConfirm = speciesBatchToConfirm;
137         this.benthosBatchToConfirm = benthosBatchToConfirm;
138     }
139 
140 }