1 package fr.ifremer.tutti.service.export.toconfirmreport;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
39
40
41
42
43
44
45 public class ToConfirmReportFishingOperationData {
46
47
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 }