View Javadoc
1   package net.sumaris.importation.service.vo;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core Importation
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.collect.Lists;
26  
27  import java.util.List;
28  
29  public class DataLoadResult {
30  
31      public final static int MAX_ERRORS_COUNT = 1000;
32  
33      protected List<DataLoadError> errors = Lists.newArrayList();
34      protected List<String> errorsOnceList = Lists.newArrayList();
35  
36      public void addError(DataLoadError error) {
37          if (errors.size() < MAX_ERRORS_COUNT) {
38              errors.add(error);
39          }
40      }
41  
42      public void addErrorOnce(DataLoadError error) {
43          if (errorsOnceList.contains(error.getErrorCode())) {
44              return;
45          }
46  
47          errorsOnceList.add(error.getErrorCode());
48          addError(error);
49      }
50  
51      public DataLoadError[] getErrors(){
52          return this.errors.toArray(new DataLoadError[errors.size()]);
53      }
54  
55      public int errorCount() {
56          return errors.size();
57      }
58  
59      public boolean isSuccess(){
60          if (errors.size() > 0) {
61              for (DataLoadError error : errors) {
62                  if (error.getErrorType() == DataLoadError.ErrorType.ERROR
63                          || error.getErrorType() == DataLoadError.ErrorType.FATAL) {
64                      return false;
65                  }
66              }
67          }
68          return true;
69      }
70  
71  }