View Javadoc
1   package net.sumaris.core.extraction.dao.trip.cost;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core Extraction
6    * %%
7    * Copyright (C) 2018 - 2019 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
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.ExtractionTripFilterVO;
30  import net.sumaris.core.extraction.vo.trip.cost.ExtractionCostTripVersion;
31  import net.sumaris.core.extraction.vo.trip.rdb.ExtractionRdbTripContextVO;
32  import org.slf4j.Logger;
33  import org.slf4j.LoggerFactory;
34  import org.springframework.context.annotation.Lazy;
35  import org.springframework.stereotype.Repository;
36  
37  /**
38   * @author Benoit Lavenier <benoit.lavenier@e-is.pro>
39   */
40  @Repository("extractionCostTripDao")
41  @Lazy
42  public class ExtractionCostTripDaoImpl<C extends ExtractionRdbTripContextVO> extends ExtractionRdbTripDaoImpl<C> implements ExtractionCostTripDao {
43  
44      private static final Logger log = LoggerFactory.getLogger(ExtractionCostTripDaoImpl.class);
45  
46      private static final String XML_QUERY_COST_PATH = "cost/v%s/%s";
47      private String version = ExtractionCostTripVersion.VERSION_1_4.getLabel();
48  
49      @Override
50      public C execute(ExtractionFilterVO filter) {
51          C context = super.execute(filter);
52  
53          // Override some context properties
54          context.setFormatName(COST_FORMAT);
55          context.setFormatVersion(version);
56  
57          return context;
58      }
59  
60      /* -- protected methods -- */
61  
62      protected XMLQuery createStationQuery(C context) {
63  
64          XMLQuery xmlQuery = super.createStationQuery(context);
65  
66          // Special case for COST format:
67          // - Hide GearType (not in the COST format)
68          xmlQuery.setGroup("gearType", false);
69  
70          return xmlQuery;
71      }
72  
73      @Override
74      protected XMLQuery createSpeciesLengthQuery(C context) {
75          XMLQuery xmlQuery = super.createSpeciesLengthQuery(context);
76  
77          // Special case for COST format:
78  
79          // - Hide sex columns, then replace by a new columns
80          xmlQuery.setGroup("sex", false);
81          xmlQuery.setGroup("lengthClass", false);
82          xmlQuery.setGroup("numberAtLength", false);
83  
84          xmlQuery.injectQuery(getXMLQueryURL(context, "injectionSpeciesLengthTable"));
85  
86          return xmlQuery;
87      }
88  
89      protected String getQueryFullName(C context, String queryName) {
90          Preconditions.checkNotNull(context);
91          Preconditions.checkNotNull(context.getFormatVersion());
92  
93          String versionStr = version.replaceAll("[.]", "_");
94          switch (queryName) {
95              case "injectionSpeciesLengthTable":
96                  return String.format(XML_QUERY_COST_PATH, versionStr, queryName);
97              default:
98                  return super.getQueryFullName(context, queryName);
99          }
100     }
101 }