1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sumaris.core.extraction.dao.trip.free;
24
25 import com.google.common.base.Preconditions;
26 import net.sumaris.core.extraction.dao.technical.XMLQuery;
27 import net.sumaris.core.extraction.dao.trip.rdb.ExtractionRdbTripDaoImpl;
28 import net.sumaris.core.extraction.vo.ExtractionFilterVO;
29 import net.sumaris.core.extraction.vo.trip.cost.ExtractionCostTripVersion;
30 import net.sumaris.core.extraction.vo.trip.free.ExtractionFreeTripVersion;
31 import net.sumaris.core.extraction.vo.trip.rdb.ExtractionRdbTripContextVO;
32 import net.sumaris.core.model.referential.pmfm.PmfmEnum;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.context.annotation.Lazy;
36 import org.springframework.stereotype.Repository;
37
38
39
40
41 @Repository("extractionFreeTripDao")
42 @Lazy
43 public class ExtractionFreeTripDaoImpl<C extends ExtractionRdbTripContextVO> extends ExtractionRdbTripDaoImpl<C> implements ExtractionFreeTripDao {
44
45 private static final Logger log = LoggerFactory.getLogger(ExtractionFreeTripDaoImpl.class);
46
47 private static final String XML_QUERY_FREE_PATH = "free/v%s/%s";
48 private String version = ExtractionFreeTripVersion.VERSION_1.getLabel();
49
50 @Override
51 public C execute(ExtractionFilterVO filter) {
52 C context = super.execute(filter);
53
54
55 context.setFormatName(FREE_FORMAT);
56 context.setFormatVersion(version);
57
58 return context;
59 }
60
61
62
63 @Override
64 protected XMLQuery createTripQuery(C context) {
65 XMLQuery xmlQuery = super.createTripQuery(context);
66
67 xmlQuery.injectQuery(getXMLQueryURL(context, "injectionTripTable"));
68
69 return xmlQuery;
70 }
71
72 @Override
73 protected XMLQuery createStationQuery(C context) {
74
75 XMLQuery xmlQuery = super.createStationQuery(context);
76
77
78 xmlQuery.setGroup("gearType", false);
79
80
81 xmlQuery.setGroup("date", false);
82 xmlQuery.setGroup("time", false);
83 xmlQuery.setGroup("fishingTime", false);
84
85 xmlQuery.injectQuery(getXMLQueryURL(context, "injectionStationTable"));
86
87
88 xmlQuery.bind("headlineCumulativeLengthPmfmId", String.valueOf(PmfmEnum.HEADLINE_CUMULATIVE_LENGTH.getId()));
89 xmlQuery.bind("beamCumulativeLengthPmfmId", String.valueOf(PmfmEnum.BEAM_CUMULATIVE_LENGTH.getId()));
90 xmlQuery.bind("netLengthPmfmId", String.valueOf(PmfmEnum.NET_LENGTH.getId()));
91
92
93
94
95
96
97
98
99 return xmlQuery;
100 }
101
102 @Override
103 protected XMLQuery createSpeciesListQuery(C context) {
104 XMLQuery xmlQuery = super.createSpeciesListQuery(context);
105
106 xmlQuery.injectQuery(getXMLQueryURL(context, "injectionSpeciesListTable"));
107
108 return xmlQuery;
109 }
110
111 @Override
112 protected XMLQuery createSpeciesLengthQuery(C context) {
113 XMLQuery xmlQuery = super.createSpeciesLengthQuery(context);
114
115
116
117
118 xmlQuery.setGroup("sex", false);
119 xmlQuery.setGroup("lengthClass", false);
120 xmlQuery.setGroup("numberAtLength", false);
121
122 xmlQuery.injectQuery(getXMLQueryURL(context, "injectionSpeciesLengthTable"));
123
124 return xmlQuery;
125 }
126
127 protected String getQueryFullName(C context, String queryName) {
128 Preconditions.checkNotNull(context);
129 Preconditions.checkNotNull(context.getFormatVersion());
130
131 String versionStr = version.replaceAll("[.]", "_");
132 switch (queryName) {
133 case "injectionTripTable":
134 case "injectionStationTable":
135 case "injectionSpeciesListTable":
136 case "injectionSpeciesLengthTable":
137 return String.format(XML_QUERY_FREE_PATH, versionStr, queryName);
138 default:
139 return super.getQueryFullName(context, queryName);
140 }
141 }
142 }