View Javadoc
1   package net.sumaris.core.extraction.vo;
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 lombok.AccessLevel;
26  import lombok.Data;
27  import lombok.experimental.FieldDefaults;
28  import lombok.experimental.FieldNameConstants;
29  import org.apache.commons.collections4.CollectionUtils;
30  import org.apache.commons.collections4.MapUtils;
31  import org.apache.commons.collections4.SetUtils;
32  
33  import java.util.LinkedHashMap;
34  import java.util.List;
35  import java.util.Map;
36  import java.util.Set;
37  
38  /**
39   * @author Benoit Lavenier <benoit.lavenier@e-is.pro>*
40   */
41  @Data
42  @FieldDefaults(level = AccessLevel.PRIVATE)
43  public abstract class AggregationContextVO extends ExtractionContextVO {
44  
45      boolean enableAnalyze = true;
46  
47      @FieldNameConstants.Exclude
48      Map<String, Map<String, List<String>>> columnValues = new LinkedHashMap<>();
49  
50      @FieldNameConstants.Exclude
51      Map<String, Set<String>> spatialColumnNames = new LinkedHashMap<>();
52  
53      public void addTableName(String tableName, String sheetName,
54                               Set<String> hiddenColumnNames,
55                               Set<String> spatialColumnNames,
56                               Map<String,List<String>> availableValuesByColumn) {
57          super.addTableName(tableName, sheetName, hiddenColumnNames, false);
58  
59          if (CollectionUtils.isNotEmpty(spatialColumnNames)) {
60              this.spatialColumnNames.put(tableName, spatialColumnNames);
61          }
62          if (MapUtils.isNotEmpty(availableValuesByColumn)) {
63              columnValues.put(tableName, availableValuesByColumn);
64          }
65      }
66  
67  
68      /**
69       * Return the hidden columns of the given table
70       * @param tableName
71       */
72      public boolean hasSpatialColumn(String tableName) {
73          return CollectionUtils.isNotEmpty(spatialColumnNames.get(tableName));
74      }
75  
76      public boolean isSpatial() {
77          return SetUtils.emptyIfNull(getTableNames())
78                  .stream()
79                  .anyMatch(this::hasSpatialColumn);
80      }
81  
82      public Map<String, List<String>> getColumnValues(String tableName) {
83          return columnValues.get(tableName);
84      }
85  }