1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.io.berlinModel.in;
|
11
|
|
12
|
import java.sql.ResultSet;
|
13
|
import java.sql.SQLException;
|
14
|
import java.util.Collection;
|
15
|
import java.util.HashMap;
|
16
|
import java.util.Map;
|
17
|
|
18
|
import org.apache.commons.lang.StringUtils;
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelRefDetailImportValidator;
|
23
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
24
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
25
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
26
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
27
|
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
|
28
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
29
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
30
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
31
|
|
32
|
/**
|
33
|
* This class imports all preliminary refdetails as generic references. Non preliminary
|
34
|
* refdetails are imported as microcitation together with the record using the refdetail
|
35
|
* and therefore left out here.
|
36
|
*
|
37
|
* @author a.mueller
|
38
|
* @created 20.03.2008
|
39
|
*/
|
40
|
@Component
|
41
|
public class BerlinModelRefDetailImport extends BerlinModelImportBase {
|
42
|
private static final Logger logger = Logger.getLogger(BerlinModelRefDetailImport.class);
|
43
|
|
44
|
// public static final String NOM_REFDETAIL_NAMESPACE = "NomRefDetail";
|
45
|
// public static final String BIBLIO_REFDETAIL_NAMESPACE = "BiblioRefDetail";
|
46
|
public static final String REFDETAIL_NAMESPACE = "RefDetail";
|
47
|
|
48
|
private int modCount = 1000;
|
49
|
private static final String pluralString = "ref-details";
|
50
|
private static final String dbTableName = "RefDetail";
|
51
|
|
52
|
|
53
|
public BerlinModelRefDetailImport(){
|
54
|
super(dbTableName, pluralString);
|
55
|
}
|
56
|
|
57
|
@Override
|
58
|
protected String getIdQuery(BerlinModelImportState state) {
|
59
|
String strQuery = " SELECT RefDetail.RefDetailId " +
|
60
|
" FROM RefDetail " +
|
61
|
" WHERE (RefDetail.PreliminaryFlag = 1)";
|
62
|
if (StringUtils.isNotBlank(state.getConfig().getRefDetailFilter())){
|
63
|
strQuery += " AND " + state.getConfig().getRefDetailFilter();
|
64
|
}
|
65
|
|
66
|
return strQuery;
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
protected String getRecordQuery(BerlinModelImportConfigurator config) {
|
71
|
String strQuery =
|
72
|
" SELECT RefDetail.*, Reference.RefYear " +
|
73
|
" FROM RefDetail " +
|
74
|
" INNER JOIN Reference ON Reference.RefId = RefDetail.RefFk " +
|
75
|
" WHERE (RefDetail.refDetailId IN (" + ID_LIST_TOKEN + ")) AND " +
|
76
|
" (RefDetail.PreliminaryFlag = 1)";
|
77
|
return strQuery;
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
82
|
boolean success = true;
|
83
|
logger.info("start make " + getPluralString() + " ...");
|
84
|
|
85
|
BerlinModelImportConfigurator config = state.getConfig();
|
86
|
Map<Integer, Reference> refDetailsToSave = new HashMap<Integer, Reference>();
|
87
|
|
88
|
ResultSet rs = partitioner.getResultSet();
|
89
|
int refCount = 0;
|
90
|
|
91
|
try {
|
92
|
int i = 0;
|
93
|
while (rs.next()){
|
94
|
|
95
|
if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("RefDetails handled: " + (i-1) );}
|
96
|
int refDetailId = rs.getInt("refDetailId");
|
97
|
String refYear = rs.getString("RefYear");
|
98
|
|
99
|
//nomRef
|
100
|
String fullNomRefCache = rs.getString("fullNomRefCache");
|
101
|
String fullRefCache = rs.getString("fullRefCache");
|
102
|
|
103
|
if ( StringUtils.isNotBlank(fullNomRefCache) || StringUtils.isNotBlank(fullRefCache) ){
|
104
|
Reference<?> genericReference = ReferenceFactory.newGeneric();
|
105
|
|
106
|
if (StringUtils.isNotBlank(fullNomRefCache)){
|
107
|
genericReference.setAbbrevTitleCache(fullNomRefCache, true);
|
108
|
}
|
109
|
if ( StringUtils.isNotBlank(fullRefCache) ){
|
110
|
genericReference.setTitleCache(fullRefCache, true);
|
111
|
}
|
112
|
|
113
|
refDetailsToSave.put(refDetailId, genericReference);
|
114
|
//year
|
115
|
genericReference.setDatePublished(ImportHelper.getDatePublished(refYear));
|
116
|
//refId, created, notes
|
117
|
doIdCreatedUpdatedNotes(state, genericReference, rs, refDetailId, REFDETAIL_NAMESPACE );
|
118
|
refCount++;
|
119
|
}
|
120
|
// xx;
|
121
|
// //biblioRef
|
122
|
// String fullRefCache = rs.getString("fullRefCache");
|
123
|
// if ( StringUtils.isNotBlank(fullRefCache) && ! fullRefCache.equals(fullNomRefCache)){
|
124
|
// Reference<?> genericReference = ReferenceFactory.newGeneric();
|
125
|
// genericReference.setTitleCache(fullRefCache, true);
|
126
|
// biblioRefDetailsToSave.put(refDetailId, genericReference);
|
127
|
// //year
|
128
|
// genericReference.setDatePublished(ImportHelper.getDatePublished(refYear));
|
129
|
// //refId, created, notes
|
130
|
// doIdCreatedUpdatedNotes(state, genericReference, rs, refDetailId, BIBLIO_REFDETAIL_NAMESPACE );
|
131
|
// refCounter.biblioRefCount++;
|
132
|
// }
|
133
|
}
|
134
|
//save and store in map
|
135
|
logger.info("Save preliminary (RefDetail) references (" + refCount + ")");
|
136
|
partitioner.startDoSave();
|
137
|
Collection<Reference> col = refDetailsToSave.values();
|
138
|
getReferenceService().save(col);
|
139
|
|
140
|
//TODO
|
141
|
//SecondarySources
|
142
|
//IdInSource
|
143
|
|
144
|
} catch (SQLException e) {
|
145
|
logger.error("SQLException:" + e);
|
146
|
return false;
|
147
|
}
|
148
|
return success;
|
149
|
}
|
150
|
|
151
|
@Override
|
152
|
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
|
153
|
|
154
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
155
|
|
156
|
//no related objects needed
|
157
|
|
158
|
return result;
|
159
|
}
|
160
|
|
161
|
@Override
|
162
|
protected boolean doCheck(BerlinModelImportState state){
|
163
|
IOValidator<BerlinModelImportState> validator = new BerlinModelRefDetailImportValidator();
|
164
|
return validator.validate(state);
|
165
|
}
|
166
|
|
167
|
@Override
|
168
|
protected boolean isIgnore(BerlinModelImportState state){
|
169
|
DO_REFERENCES doReference = state.getConfig().getDoReferences();
|
170
|
return (doReference == IImportConfigurator.DO_REFERENCES.NONE || doReference == IImportConfigurator.DO_REFERENCES.CONCEPT_REFERENCES);
|
171
|
}
|
172
|
|
173
|
}
|