1 package net.sumaris.importation.service.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.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 }