Revision 2108
Added by Duane Costa about 20 years ago
HarvestLog.java | ||
---|---|---|
32 | 32 |
import java.sql.Statement; |
33 | 33 |
import java.text.SimpleDateFormat; |
34 | 34 |
import java.util.Date; |
35 |
import java.util.Properties; |
|
36 |
import java.util.StringTokenizer; |
|
35 | 37 |
|
36 | 38 |
|
37 | 39 |
/** |
... | ... | |
89 | 91 |
this.siteScheduleID = siteScheduleID; |
90 | 92 |
|
91 | 93 |
harvestOperationCodeLevel = |
92 |
dbGetHarvestOperationCodeLevel(harvestOperationCode);
|
|
93 |
explanation = dbGetExplanation(harvestOperationCode);
|
|
94 |
getHarvestOperationCodeLevel(harvestOperationCode);
|
|
95 |
explanation = getExplanation(harvestOperationCode);
|
|
94 | 96 |
dbInsertHarvestLogEntry(); // Insert this entry to the HARVEST_LOG table |
95 | 97 |
} |
96 | 98 |
|
... | ... | |
133 | 135 |
this.harvestDetailLog = new HarvestDetailLog(harvester, harvestLogID, |
134 | 136 |
harvestDocument, errorMessage); |
135 | 137 |
harvestOperationCodeLevel = |
136 |
dbGetHarvestOperationCodeLevel(harvestOperationCode);
|
|
137 |
explanation = dbGetExplanation(harvestOperationCode);
|
|
138 |
getHarvestOperationCodeLevel(harvestOperationCode);
|
|
139 |
explanation = getExplanation(harvestOperationCode);
|
|
138 | 140 |
dbInsertHarvestLogEntry(); // Insert to the HARVEST_LOG table |
139 | 141 |
harvestDetailLog.dbInsertHarvestDetailLogEntry(); // and HARVEST_DETAIL_LOG |
140 | 142 |
} |
141 | 143 |
|
142 | 144 |
|
143 | 145 |
/** |
144 |
* Retrieves the value of the EXPLANATION field of the HARVEST_OPERATION |
|
145 |
* table based on the value of the HARVEST_OPERATION_CODE field. |
|
146 |
* |
|
147 |
* @param harvestOperationCode string value of the harvest operation code |
|
148 |
* @return the explanation for this harvest operation, a String |
|
149 |
*/ |
|
150 |
String dbGetExplanation(String harvestOperationCode) { |
|
151 |
String explanation; |
|
152 |
String fieldName = "EXPLANATION"; |
|
153 |
|
|
154 |
explanation = dbQueryHarvestOperation(fieldName, harvestOperationCode); |
|
155 |
|
|
156 |
return explanation; |
|
157 |
} |
|
158 |
|
|
159 |
|
|
160 |
/** |
|
161 |
* Retrieves the value of the HARVEST_OPERATION_CODE_LEVEL field of the |
|
162 |
* HARVEST_OPERATION table based on the value of the HARVEST_OPERATION_CODE |
|
163 |
* field. |
|
164 |
* |
|
165 |
* @param harvestOperationCode string value of the harvest operation code |
|
166 |
* @return the code level value, a String, one of the following: |
|
167 |
* "error", "warning", "notice", "info", or "debug" |
|
168 |
*/ |
|
169 |
String dbGetHarvestOperationCodeLevel(String harvestOperationCode) { |
|
170 |
String harvestOperationCodeLevel; |
|
171 |
String fieldName = "HARVEST_OPERATION_CODE_LEVEL"; |
|
172 |
|
|
173 |
harvestOperationCodeLevel = |
|
174 |
dbQueryHarvestOperation(fieldName, harvestOperationCode); |
|
175 |
|
|
176 |
return harvestOperationCodeLevel; |
|
177 |
} |
|
178 |
|
|
179 |
|
|
180 |
/** |
|
181 | 146 |
* Inserts a new entry into the HARVEST_LOG table, based on the contents of |
182 | 147 |
* this HarvestLog object. Not yet implemented. |
183 | 148 |
*/ |
... | ... | |
211 | 176 |
|
212 | 177 |
|
213 | 178 |
/** |
179 |
* Maps each code level to an integer value. |
|
180 |
* |
|
181 |
* @param codeLevel the code level: "error", "warning", "notice", |
|
182 |
* "info", or "debug" |
|
183 |
* @return codeLevelValue the corresponding code level value |
|
184 |
*/ |
|
185 |
int getCodeLevelValue(String codeLevel) { |
|
186 |
int codeLevelValue = 0; |
|
187 |
|
|
188 |
if (codeLevel.equalsIgnoreCase("error")) { |
|
189 |
codeLevelValue = 1; |
|
190 |
} |
|
191 |
else if (codeLevel.equalsIgnoreCase("warning")) { |
|
192 |
codeLevelValue = 2; |
|
193 |
} |
|
194 |
else if (codeLevel.equalsIgnoreCase("notice")) { |
|
195 |
codeLevelValue = 3; |
|
196 |
} |
|
197 |
else if (codeLevel.equalsIgnoreCase("info")) { |
|
198 |
codeLevelValue = 4; |
|
199 |
} |
|
200 |
else if (codeLevel.equalsIgnoreCase("debug")) { |
|
201 |
codeLevelValue = 5; |
|
202 |
} |
|
203 |
|
|
204 |
return codeLevelValue; |
|
205 |
} |
|
206 |
|
|
207 |
|
|
208 |
/** |
|
209 |
* Retrieves the value of the EXPLANATION field of the HARVEST_OPERATION |
|
210 |
* table based on the value of the HARVEST_OPERATION_CODE field. |
|
211 |
* |
|
212 |
* @param harvestOperationCode string value of the harvest operation code |
|
213 |
* @return the explanation for this harvest operation, a String |
|
214 |
*/ |
|
215 |
String getExplanation(String harvestOperationCode) { |
|
216 |
String explanation; |
|
217 |
String fieldName = "EXPLANATION"; |
|
218 |
|
|
219 |
explanation = getHarvestOperation(fieldName, harvestOperationCode); |
|
220 |
|
|
221 |
return explanation; |
|
222 |
} |
|
223 |
|
|
224 |
|
|
225 |
/** |
|
214 | 226 |
* Retrieves the value of the either the EXPLANATION field or the |
215 | 227 |
* HARVEST_OPERATION_CODE_LEVEL field of the HARVEST_OPERATION table based on |
216 | 228 |
* the value of the HARVEST_OPERATION_CODE field. |
... | ... | |
219 | 231 |
* @param harvestOperationCode string value of the harvest operation code |
220 | 232 |
* @return the explanation string or the harvestOperationCodeLevel string |
221 | 233 |
*/ |
222 |
String dbQueryHarvestOperation(String fieldName, |
|
223 |
String harvestOperationCode |
|
224 |
) { |
|
234 |
String getHarvestOperation(String fieldName, String harvestOperationCode) { |
|
225 | 235 |
String explanation = "No explanation available"; |
226 | 236 |
String harvestOperationCodeLevel = "debug"; |
227 |
String queryString; |
|
237 |
Properties properties = Harvester.properties; |
|
238 |
String propertyValue; |
|
228 | 239 |
String returnString = ""; |
229 |
ResultSet rs; |
|
230 |
Statement stmt; |
|
231 |
SQLWarning warn; |
|
240 |
StringTokenizer stringTokenizer; |
|
232 | 241 |
|
233 |
queryString = "SELECT EXPLANATION, HARVEST_OPERATION_CODE_LEVEL " + |
|
234 |
"FROM HARVEST_OPERATION " + |
|
235 |
"WHERE HARVEST_OPERATION_CODE=" + |
|
236 |
"'" + harvestOperationCode + "'"; |
|
237 |
|
|
238 |
try { // Query the HARVEST_OPERATION table |
|
239 |
stmt = harvester.conn.createStatement(); |
|
240 |
rs = stmt.executeQuery(queryString); |
|
241 |
warn = rs.getWarnings(); |
|
242 |
|
|
243 |
if (warn != null) { |
|
244 |
System.out.println("\n---Warning---\n"); |
|
245 |
|
|
246 |
while (warn != null) { |
|
247 |
System.out.println("Message: " + warn.getMessage()); |
|
248 |
System.out.println("SQLState: " + warn.getSQLState()); |
|
249 |
System.out.print("Vendor error code: "); |
|
250 |
System.out.println(warn.getErrorCode()); |
|
251 |
System.out.println(""); |
|
252 |
warn = warn.getNextWarning(); |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
256 |
while (rs.next()) { |
|
257 |
explanation = rs.getString("EXPLANATION"); |
|
258 |
harvestOperationCodeLevel = rs.getString("HARVEST_OPERATION_CODE_LEVEL"); |
|
259 |
warn = rs.getWarnings(); |
|
260 |
|
|
261 |
if (warn != null) { |
|
262 |
System.out.println("\n---Warning---\n"); |
|
263 |
|
|
264 |
while (warn != null) { |
|
265 |
System.out.println("Message: " + warn.getMessage()); |
|
266 |
System.out.println("SQLState: " + warn.getSQLState()); |
|
267 |
System.out.print("Vendor error code: "); |
|
268 |
System.out.println(warn.getErrorCode()); |
|
269 |
System.out.println(""); |
|
270 |
warn = warn.getNextWarning(); |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
rs.close(); |
|
276 |
stmt.close(); |
|
277 |
} |
|
278 |
catch (SQLException e) { |
|
279 |
System.out.println("SQLException: Database access failed: " + e); |
|
280 |
} |
|
281 |
|
|
242 |
propertyValue = properties.getProperty(harvestOperationCode); |
|
243 |
stringTokenizer = new StringTokenizer(propertyValue, ","); |
|
244 |
|
|
245 |
explanation = (String) stringTokenizer.nextElement(); |
|
246 |
harvestOperationCodeLevel = (String) stringTokenizer.nextElement(); |
|
247 |
|
|
282 | 248 |
if (fieldName.equals("EXPLANATION")) { |
283 | 249 |
returnString = explanation; |
284 | 250 |
} |
... | ... | |
291 | 257 |
|
292 | 258 |
|
293 | 259 |
/** |
294 |
* Maps each code level to an integer value. |
|
260 |
* Retrieves the value of the HARVEST_OPERATION_CODE_LEVEL field of the |
|
261 |
* HARVEST_OPERATION table based on the value of the HARVEST_OPERATION_CODE |
|
262 |
* field. |
|
295 | 263 |
* |
296 |
* @param codeLevel the code level: "error", "warning", "notice",
|
|
297 |
* "info", or "debug"
|
|
298 |
* @return codeLevelValue the corresponding code level value
|
|
264 |
* @param harvestOperationCode string value of the harvest operation code
|
|
265 |
* @return the code level value, a String, one of the following:
|
|
266 |
* "error", "warning", "notice", "info", or "debug"
|
|
299 | 267 |
*/ |
300 |
int getCodeLevelValue(String codeLevel) { |
|
301 |
int codeLevelValue = 0; |
|
268 |
String getHarvestOperationCodeLevel(String harvestOperationCode) { |
|
269 |
String harvestOperationCodeLevel; |
|
270 |
String fieldName = "HARVEST_OPERATION_CODE_LEVEL"; |
|
302 | 271 |
|
303 |
if (codeLevel.equalsIgnoreCase("error")) { |
|
304 |
codeLevelValue = 1; |
|
305 |
} |
|
306 |
else if (codeLevel.equalsIgnoreCase("warning")) { |
|
307 |
codeLevelValue = 2; |
|
308 |
} |
|
309 |
else if (codeLevel.equalsIgnoreCase("notice")) { |
|
310 |
codeLevelValue = 3; |
|
311 |
} |
|
312 |
else if (codeLevel.equalsIgnoreCase("info")) { |
|
313 |
codeLevelValue = 4; |
|
314 |
} |
|
315 |
else if (codeLevel.equalsIgnoreCase("debug")) { |
|
316 |
codeLevelValue = 5; |
|
317 |
} |
|
318 |
|
|
319 |
return codeLevelValue; |
|
272 |
harvestOperationCodeLevel = |
|
273 |
getHarvestOperation(fieldName, harvestOperationCode); |
|
274 |
|
|
275 |
return harvestOperationCodeLevel; |
|
320 | 276 |
} |
321 | 277 |
|
322 | 278 |
|
Also available in: Unified diff
Omit HARVEST_OPERATION_TABLE and store harvest operations in properties file instead