1 package net.sumaris.core.vo.technical.extraction;
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 lombok.Data;
27 import lombok.experimental.FieldNameConstants;
28 import net.sumaris.core.model.data.IWithRecorderDepartmentEntity;
29 import net.sumaris.core.model.data.IWithRecorderPersonEntity;
30 import net.sumaris.core.vo.administration.user.DepartmentVO;
31 import net.sumaris.core.vo.administration.user.PersonVO;
32 import net.sumaris.core.vo.referential.IReferentialVO;
33 import org.apache.commons.collections4.ListUtils;
34
35 import java.util.Date;
36 import java.util.List;
37 import java.util.Map;
38 import java.util.Optional;
39 import java.util.stream.Collectors;
40
41
42
43
44 @Data
45 @FieldNameConstants
46 public class ExtractionProductVO implements IReferentialVO,
47 IWithRecorderDepartmentEntity<Integer, DepartmentVO>,
48 IWithRecorderPersonEntity<Integer, PersonVO> {
49
50 private Integer id;
51 private String label;
52 private String name;
53 private String description;
54 private String comments;
55 private Date updateDate;
56 private Date creationDate;
57 private Boolean isSpatial;
58
59 private DepartmentVO recorderDepartment;
60 private PersonVO recorderPerson;
61
62 private Integer statusId;
63 private Integer parentId;
64
65 private List<ExtractionProductTableVO> tables;
66 private List<ExtractionProductStrataVO> stratum;
67
68 public List<String> getTableNames() {
69 if (tables == null) return null;
70 return tables.stream().map(t -> t.getTableName()).collect(Collectors.toList());
71 }
72
73 public List<String> getSheetNames() {
74 if (tables == null) return null;
75 return tables.stream().map(t -> t.getLabel()).collect(Collectors.toList());
76 }
77
78 public Map<String, String> getItems() {
79 if (tables == null) return null;
80 return tables.stream().collect(Collectors.toMap(t -> t.getLabel(), t -> t.getTableName()));
81 }
82
83 public Optional<String> getTableNameBySheetName(String sheetName) {
84 Preconditions.checkNotNull(sheetName);
85 return ListUtils.emptyIfNull(tables).stream()
86 .filter(t -> sheetName.equalsIgnoreCase(t.getLabel()))
87 .map(t -> t.getTableName())
88 .findFirst();
89 }
90
91 public Optional<String> getSheetNameByTableName(String tableName) {
92 Preconditions.checkNotNull(tableName);
93 return ListUtils.emptyIfNull(tables).stream()
94 .filter(t -> tableName.equalsIgnoreCase(t.getTableName()))
95 .map(t -> t.getLabel())
96 .findFirst();
97 }
98
99 public boolean hasSpatialSheet() {
100 return ListUtils.emptyIfNull(tables).stream()
101 .anyMatch(t -> t.getIsSpatial() != null && t.getIsSpatial().booleanValue());
102
103 }
104
105 }