1 package net.sumaris.core.extraction.vo;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import com.google.common.base.Preconditions;
26 import com.google.common.collect.Maps;
27 import lombok.AccessLevel;
28 import lombok.Data;
29 import lombok.experimental.FieldDefaults;
30 import lombok.experimental.FieldNameConstants;
31 import org.apache.commons.collections4.CollectionUtils;
32
33 import java.util.*;
34
35
36
37
38
39 @Data
40 @FieldDefaults(level = AccessLevel.PRIVATE)
41 public class ExtractionContextVO {
42
43 long id;
44
45 String label;
46 String formatName;
47 String formatVersion;
48 ExtractionFilterVO filter;
49
50 @FieldNameConstants.Exclude
51 Map<String, String> tableNames = new LinkedHashMap<>();
52
53 @FieldNameConstants.Exclude
54 Map<String, Set<String>> hiddenColumnNames = new LinkedHashMap<>();
55
56
57 @FieldNameConstants.Exclude
58 Set<String> tableNameWithDistinct = new HashSet<>();
59
60 public ExtractionContextVO() {
61
62 }
63
64 protected ExtractionContextVO../../../../net/sumaris/core/extraction/vo/ExtractionContextVO.html#ExtractionContextVO">ExtractionContextVO(ExtractionContextVO source) {
65
66 this.id = source.id;
67 this.label = source.label;
68 this.formatName = source.formatName;
69 this.formatVersion = source.formatVersion;
70 this.tableNames.putAll(source.tableNames);
71 this.hiddenColumnNames.putAll(source.hiddenColumnNames);
72 this.tableNameWithDistinct.addAll(source.tableNameWithDistinct);
73 }
74
75
76 public String getLabel() {
77 return label != null ? label : (this.formatName != null ? this.formatName.toLowerCase() : null);
78 }
79
80
81
82
83
84
85 public void addTableName(String tableName, String sheetName) {
86 addTableName(tableName, sheetName, null, false);
87 }
88
89
90
91
92
93
94
95 public void addTableName(String tableName, String sheetName,
96 Set<String> hiddenColumnNames,
97 boolean enableDistinct) {
98 tableNames.put(tableName, sheetName);
99 if (CollectionUtils.isNotEmpty(hiddenColumnNames)) {
100 this.hiddenColumnNames.put(tableName, hiddenColumnNames);
101 }
102 if (enableDistinct) {
103 this.tableNameWithDistinct.add(tableName);
104 }
105 }
106
107 public String getSheetName(String tableName) {
108 String otherName = tableNames.get(tableName);
109 return (otherName!=null) ? otherName : tableName;
110 }
111
112 public Set<String> getTableNames() {
113 return tableNames.keySet();
114 }
115
116 public String getTableNameBySheetName(String sheetName) {
117 Preconditions.checkNotNull(sheetName);
118 return tableNames.entrySet().stream()
119 .filter(e -> sheetName.equalsIgnoreCase(e.getValue()))
120 .map(e -> e.getKey())
121 .findFirst()
122 .orElse(null);
123 }
124
125 public boolean hasSheet(String sheetName) {
126 Preconditions.checkNotNull(sheetName);
127 return tableNames.containsValue(sheetName);
128 }
129
130
131
132
133
134 public Set<String> getHiddenColumns(String tableName) {
135 return hiddenColumnNames.get(tableName);
136 }
137
138
139
140
141
142
143 public boolean isDistinctEnable(String tableName) {
144 return tableNameWithDistinct.contains(tableName);
145 }
146 }