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 net.sumaris.core.dao.technical.schema.SumarisColumnMetadata;
26  import net.sumaris.core.dao.technical.schema.SumarisTableMetadata;
27  import net.sumaris.importation.util.csv.FileMessageFormatter;
28  import net.sumaris.importation.util.csv.FileReader;
29  
30  public class DataLoadError {
31  
32  	public enum ErrorType {
33  
34  		WARNING,
35  		ERROR,
36  		FATAL
37  	}
38  
39  
40  	public static final class Builder {
41  
42  		public static Builder create() {
43  			return new Builder();
44  		}
45  
46  		public static Builder create(SumarisTableMetadata table, SumarisColumnMetadata column, int lineNumber, String description) {
47  			Builder error = new Builder();
48  			error.setLineNumber(lineNumber);
49  			error.setColumnName(column != null ? column.getName() : null);
50  			error.setDescription(FileMessageFormatter.format(table, column, lineNumber, description));
51  			return error;
52  		}
53  
54  		public static Builder create(FileReader reader, SumarisTableMetadata table, SumarisColumnMetadata column, String description) {
55  			Builder error = new Builder();
56  			error.setLineNumber(reader.getCurrentLine());
57  			error.setColumnName(column != null ? column.getName() : null);
58  			error.setDescription(FileMessageFormatter.format(table, column, reader.getCurrentLine(), description));
59  			return error;
60  		}
61  
62  		protected ErrorType errorType;
63  
64  		protected String errorCode;
65  
66  		protected String description;
67  
68  		protected int lineNumber;
69  
70  		protected Integer columnNumber;
71  
72  		protected String columnName;
73  
74  		public Builder() {
75  
76  		}
77  
78  		public Builder setColumnName(String columnName) {
79  			this.columnName = columnName;
80  			return this;
81  		}
82  
83  		public Builder setColumnNumber(Integer columnNumber) {
84  			this.columnNumber = columnNumber;
85  			return this;
86  		}
87  
88  		public Builder setLineNumber(int lineNumber) {
89  			this.lineNumber = lineNumber;
90  			return this;
91  		}
92  
93  		public Builder setErrorCode(String errorCode) {
94  			this.errorCode = errorCode;
95  			return this;
96  		}
97  
98  		public Builder setErrorType(ErrorType errorType) {
99  			this.errorType = errorType;
100 			return this;
101 		}
102 
103 		public Builder setDescription(String description) {
104 			this.description = description;
105 			return this;
106 		}
107 
108 		public Builder setReader(FileReader reader) {
109 			this.lineNumber = reader.getCurrentLine();
110 			return this;
111 		}
112 
113 		public DataLoadError build() {
114 			DataLoadError result = new DataLoadError();
115 			result.setErrorCode(errorCode);
116 			result.setErrorType(errorType);
117 			result.setColumnName(columnName);
118 			result.setColumnNumber(columnNumber);
119 			result.setDescription(description);
120 			result.setLineNumber(lineNumber);
121 			return result;
122 		}
123 
124 	}
125 
126 	protected String errorCode;
127 
128 	protected String description;
129 
130 	protected int lineNumber;
131 
132 	protected Integer columnNumber;
133 
134 	protected String columnName;
135 
136 	public Integer getColumnNumber() {
137 		return columnNumber;
138 	}
139 
140 	public void setColumnNumber(Integer columnNumber) {
141 		this.columnNumber = columnNumber;
142 	}
143 
144 	public String getColumnName() {
145 		return columnName;
146 	}
147 
148 	public void setColumnName(String columnName) {
149 		this.columnName = columnName;
150 	}
151 
152 	protected ErrorType errorType;
153 
154 	public String getErrorCode() {
155 		return errorCode;
156 	}
157 
158 	public void setErrorCode(String errorCode) {
159 		this.errorCode = errorCode;
160 	}
161 
162 	public String getDescription() {
163 		return description;
164 	}
165 
166 	public void setDescription(String description) {
167 		this.description = description;
168 	}
169 
170 	public int getLineNumber() {
171 		return lineNumber;
172 	}
173 
174 	public void setLineNumber(int lineNumber) {
175 		this.lineNumber = lineNumber;
176 	}
177 
178 	public ErrorType getErrorType() {
179 		return errorType;
180 	}
181 
182 	public void setErrorType(ErrorType errorType) {
183 		this.errorType = errorType;
184 	}
185 
186 }