1
|
package eu.etaxonomy.cdm.io.berlinModel;
|
2
|
|
3
|
import java.sql.ResultSet;
|
4
|
import java.sql.ResultSetMetaData;
|
5
|
import java.sql.SQLException;
|
6
|
|
7
|
import org.apache.log4j.Logger;
|
8
|
|
9
|
import eu.etaxonomy.cdm.io.common.CdmIoBase;
|
10
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
11
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
12
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
13
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
14
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
15
|
import eu.etaxonomy.cdm.model.common.Language;
|
16
|
|
17
|
|
18
|
public abstract class BerlinModelIOBase extends CdmIoBase implements ICdmIO {
|
19
|
private static final Logger logger = Logger.getLogger(BerlinModelIOBase.class);
|
20
|
|
21
|
public BerlinModelIOBase() {
|
22
|
super();
|
23
|
}
|
24
|
|
25
|
|
26
|
protected boolean doIdCreatedUpdatedNotes(IImportConfigurator bmiConfig, IdentifiableEntity identifiableEntity, ResultSet rs, long id, String namespace)
|
27
|
throws SQLException{
|
28
|
|
29
|
Object createdWhen = rs.getObject("Created_When");
|
30
|
Object createdWho = rs.getObject("Created_Who");
|
31
|
Object updatedWhen = null;
|
32
|
Object updatedWho = null;
|
33
|
try {
|
34
|
updatedWhen = rs.getObject("Updated_When");
|
35
|
updatedWho = rs.getObject("Updated_who");
|
36
|
} catch (SQLException e) {
|
37
|
//Table "Name" has no updated when/who
|
38
|
}
|
39
|
Object notes = rs.getObject("notes");
|
40
|
|
41
|
boolean success = true;
|
42
|
|
43
|
//id
|
44
|
ImportHelper.setOriginalSource(identifiableEntity, bmiConfig.getSourceReference(), id, namespace);
|
45
|
|
46
|
|
47
|
//Created When, Who, Updated When Who
|
48
|
String createdAnnotationString = "Berlin Model record was created By: " + String.valueOf(createdWho) + " (" + String.valueOf(createdWhen) + ") ";
|
49
|
if (updatedWhen != null && updatedWho != null){
|
50
|
createdAnnotationString += " and updated By: " + String.valueOf(updatedWho) + " (" + String.valueOf(updatedWhen) + ")";
|
51
|
}
|
52
|
Annotation annotation = Annotation.NewInstance(createdAnnotationString, Language.ENGLISH());
|
53
|
annotation.setCommentator(bmiConfig.getCommentator());
|
54
|
identifiableEntity.addAnnotation(annotation);
|
55
|
|
56
|
//notes
|
57
|
if (notes != null){
|
58
|
String notesString = String.valueOf(notes);
|
59
|
if (notesString.length() > 254 ){
|
60
|
notesString = notesString.substring(0, 250) + "...";
|
61
|
}
|
62
|
Annotation notesAnnotation = Annotation.NewInstance(notesString, null);
|
63
|
//notes.setCommentator(bmiConfig.getCommentator());
|
64
|
identifiableEntity.addAnnotation(notesAnnotation);
|
65
|
}
|
66
|
return success;
|
67
|
}
|
68
|
|
69
|
|
70
|
protected boolean resultSetHasColumn(ResultSet rs, String columnName){
|
71
|
try {
|
72
|
ResultSetMetaData metaData = rs.getMetaData();
|
73
|
for (int i = 0; i < metaData.getColumnCount(); i++){
|
74
|
if (metaData.getColumnName(i).equalsIgnoreCase(columnName)){
|
75
|
return true;
|
76
|
}
|
77
|
}
|
78
|
return false;
|
79
|
} catch (SQLException e) {
|
80
|
return false;
|
81
|
}
|
82
|
}
|
83
|
|
84
|
}
|