Revision 31938ede
Added by Andreas Müller over 5 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelOccurrenceSourceImport.java | ||
---|---|---|
53 | 53 |
|
54 | 54 |
|
55 | 55 |
private Map<String, Integer> sourceNumberRefIdMap; |
56 |
private Set<String> unfoundReferences = new HashSet<String>();
|
|
56 |
private Set<String> unfoundReferences = new HashSet<>(); |
|
57 | 57 |
|
58 | 58 |
|
59 | 59 |
public BerlinModelOccurrenceSourceImport(){ |
... | ... | |
83 | 83 |
|
84 | 84 |
@Override |
85 | 85 |
protected void doInvoke(BerlinModelImportState state) { |
86 |
unfoundReferences = new HashSet<String>();
|
|
86 |
unfoundReferences = new HashSet<>(); |
|
87 | 87 |
|
88 | 88 |
try { |
89 | 89 |
sourceNumberRefIdMap = makeSourceNumberReferenceIdMap(state); |
... | ... | |
101 | 101 |
} |
102 | 102 |
|
103 | 103 |
@Override |
104 |
public boolean doPartition(ResultSetPartitioner partitioner, BerlinModelImportState state) { |
|
104 |
public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, BerlinModelImportState state) {
|
|
105 | 105 |
boolean success = true; |
106 | 106 |
ResultSet rs = partitioner.getResultSet(); |
107 |
Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE); |
|
107 |
@SuppressWarnings("unchecked") |
|
108 |
Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE); |
|
108 | 109 |
|
109 | 110 |
Set<DescriptionElementBase> objectsToSave = new HashSet<DescriptionElementBase>(); |
110 | 111 |
try { |
... | ... | |
165 | 166 |
String nameSpace; |
166 | 167 |
Class<?> cdmClass; |
167 | 168 |
Set<String> idSet; |
168 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
|
169 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>(); |
|
169 | 170 |
|
170 | 171 |
try{ |
171 |
Set<String> occurrenceIdSet = new HashSet<String>();
|
|
172 |
Set<String> referenceIdSet = new HashSet<String>();
|
|
173 |
Set<String> nameIdSet = new HashSet<String>();
|
|
174 |
Set<String> sourceNumberSet = new HashSet<String>();
|
|
172 |
Set<String> occurrenceIdSet = new HashSet<>(); |
|
173 |
Set<String> referenceIdSet = new HashSet<>(); |
|
174 |
Set<String> nameIdSet = new HashSet<>(); |
|
175 |
Set<String> sourceNumberSet = new HashSet<>(); |
|
175 | 176 |
while (rs.next()){ |
176 | 177 |
handleForeignKey(rs, occurrenceIdSet, "occurrenceFk"); |
177 | 178 |
handleForeignKey(rs, nameIdSet, "oldNameFk"); |
... | ... | |
179 | 180 |
} |
180 | 181 |
|
181 | 182 |
sourceNumberSet.remove(""); |
182 |
referenceIdSet = handleSourceNumber(rs, sourceNumberSet, result);
|
|
183 |
referenceIdSet = handleSourceNumber(sourceNumberSet);
|
|
183 | 184 |
|
184 | 185 |
|
185 | 186 |
//occurrence map |
186 | 187 |
nameSpace = BerlinModelOccurrenceImport.NAMESPACE; |
187 | 188 |
cdmClass = Distribution.class; |
188 | 189 |
idSet = occurrenceIdSet; |
189 |
Map<String, Distribution> occurrenceMap = (Map<String, Distribution>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
190 |
@SuppressWarnings("unchecked") |
|
191 |
Map<String, Distribution> occurrenceMap = (Map<String, Distribution>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
190 | 192 |
result.put(nameSpace, occurrenceMap); |
191 | 193 |
|
192 | 194 |
//name map |
193 | 195 |
nameSpace = BerlinModelTaxonNameImport.NAMESPACE; |
194 | 196 |
cdmClass = TaxonName.class; |
195 | 197 |
idSet =nameIdSet; |
196 |
Map<String, TaxonName> nameMap = (Map<String, TaxonName>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
198 |
@SuppressWarnings("unchecked") |
|
199 |
Map<String, TaxonName> nameMap = (Map<String, TaxonName>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
197 | 200 |
result.put(nameSpace, nameMap); |
198 | 201 |
|
199 | 202 |
//reference map |
200 | 203 |
nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE; |
201 | 204 |
cdmClass = Reference.class; |
202 | 205 |
idSet = referenceIdSet; |
203 |
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
206 |
@SuppressWarnings("unchecked") |
|
207 |
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
|
204 | 208 |
result.put(nameSpace, referenceMap); |
205 | 209 |
|
206 | 210 |
} catch (SQLException e) { |
... | ... | |
209 | 213 |
return result; |
210 | 214 |
} |
211 | 215 |
|
212 |
private Set<String> handleSourceNumber(ResultSet rs, Set<String> sourceNumberSet, Map<Object, Map<String, ? extends CdmBase>> result) {
|
|
216 |
private Set<String> handleSourceNumber(Set<String> sourceNumberSet) {
|
|
213 | 217 |
Map<String, Integer> sourceNumberReferenceIdMap = this.sourceNumberRefIdMap; |
214 |
Set<String> referenceIdSet = new HashSet<String>();
|
|
218 |
Set<String> referenceIdSet = new HashSet<>(); |
|
215 | 219 |
|
216 | 220 |
for(String sourceNumber : sourceNumberSet){ |
217 | 221 |
Integer refId = sourceNumberReferenceIdMap.get(sourceNumber); |
... | ... | |
258 | 262 |
* @throws SQLException |
259 | 263 |
*/ |
260 | 264 |
private Map<String, Integer> makeSourceNumberReferenceIdMap(BerlinModelImportState state) throws SQLException { |
261 |
Map<String, Integer> result = new HashMap<String, Integer>();
|
|
265 |
Map<String, Integer> result = new HashMap<>(); |
|
262 | 266 |
|
263 | 267 |
Source source = state.getConfig().getSource(); |
264 | 268 |
String strQuery = " SELECT RefId, IdInSource " + |
265 | 269 |
" FROM Reference " + |
266 |
" WHERE (IdInSource IS NOT NULL) AND (IdInSource NOT LIKE '') ";
|
|
270 |
" WHERE (IdInSource IS NOT NULL) AND (IdInSource NOT LIKE '') "; |
|
267 | 271 |
|
268 | 272 |
ResultSet rs = source.getResultSet(strQuery) ; |
269 | 273 |
while (rs.next()){ |
Also available in: Unified diff
cleanup