View Javadoc
1   /*
2    * #%L
3    * SUMARiS
4    * %%
5    * Copyright (C) 2019 SUMARiS Consortium
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as
9    * published by the Free Software Foundation, either version 3 of the
10   * License, or (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/gpl-3.0.html>.
20   * #L%
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   * @author Benoit Lavenier <benoit.lavenier@e-is.pro>
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          // Override some context properties
55          context.setFormatName(FREE_FORMAT);
56          context.setFormatVersion(version);
57  
58          return context;
59      }
60  
61      /* -- protected methods -- */
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          // Hide GearType (not in the FREE format)
78          xmlQuery.setGroup("gearType", false);
79  
80          // - Hide some columns (replaced by a new columns names)
81          xmlQuery.setGroup("date", false);
82          xmlQuery.setGroup("time", false);
83          xmlQuery.setGroup("fishingTime", false);
84  
85          xmlQuery.injectQuery(getXMLQueryURL(context, "injectionStationTable"));
86  
87          // Bind some PMFM ids
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          // TODO: add SIH Ifremer missing parameters (see FREE1 format specification) ?
92          //        TOTAL_LENGTH_HAULED Longueur levée,               = NET_LENGTH ?
93          //        TOTAL_NB_HOOKS Nombre total d'hameçons,           missing in SUMARIS
94          //        NB_FISH_POT Nombre de casiers nasses ou poches,   missing in SUMARIS
95          //        HEADLINE_LENGTH Longueur de la corde de dos (cumulée si jumeaux),   = HEADLINE_CUMULATIVE_LENGTH ?
96          //        WIDTH_GEAR Largeur cumulée (drague),              missing in SUMARIS
97          //        SEINE_LENGTH Longueur de la bolinche ou senne     missing in SUMARIS
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         // Special case for COST format:
116 
117         // - Hide sex columns, then replace by a new columns
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 }