View Javadoc
1   package net.sumaris.core.vo.technical.extraction;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core
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 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   * @author Benoit Lavenier <benoit.lavenier@e-is.pro>*
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 }