1 package net.sumaris.importation.exception;
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 net.sumaris.importation.service.vo.DataLoadError;
26
27 public class FileValidationException extends Exception {
28
29 private static final long serialVersionUID = 4369710207426419207L;
30
31 protected final DataLoadError[] fileValidationDataLoadErrors;
32
33 protected final static int MAX_ERRORS_IN_DESCRIPTION = 100;
34
35 public FileValidationException(DataLoadError[] fileValidationDataLoadErrors) {
36 this.fileValidationDataLoadErrors = fileValidationDataLoadErrors;
37 }
38
39 public DataLoadError[] getFileValidationDataLoadErrors() {
40 return fileValidationDataLoadErrors;
41 }
42
43 @Override
44 public String getMessage() {
45 String baseMessage = "Error during file validation";
46 if (fileValidationDataLoadErrors == null) {
47 return baseMessage;
48 }
49
50 StringBuilder sb = new StringBuilder(baseMessage);
51 sb.append(":");
52 int errorCount = 0;
53 for (DataLoadError error : fileValidationDataLoadErrors) {
54 if (errorCount == MAX_ERRORS_IN_DESCRIPTION) {
55 sb.append("\n\t(...)");
56 break;
57 }
58 errorCount++;
59 sb.append("\n\t");
60 sb.append(error.getErrorType().name());
61 sb.append(" - ");
62 sb.append(error.getDescription());
63 }
64 return sb.toString();
65 }
66 }