Revision 892efc69
Added by Andreas Kohlbecker almost 14 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/pesi/out/PesiRelTaxonExport.java | ||
---|---|---|
20 | 20 |
import eu.etaxonomy.cdm.io.berlinModel.out.mapper.MethodMapper; |
21 | 21 |
import eu.etaxonomy.cdm.io.common.DbExportStateBase; |
22 | 22 |
import eu.etaxonomy.cdm.io.common.Source; |
23 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
24 | 23 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
25 | 24 |
import eu.etaxonomy.cdm.model.common.RelationshipBase; |
25 |
import eu.etaxonomy.cdm.model.name.NameRelationship; |
|
26 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
26 | 27 |
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship; |
27 | 28 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
28 | 29 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship; |
... | ... | |
129 | 130 |
|
130 | 131 |
logger.error("*** Finished Making " + pluralString + " ..." + getSuccessString(success)); |
131 | 132 |
|
133 |
|
|
134 |
count = 0; |
|
135 |
taxonCount = 0; |
|
136 |
pastCount = 0; |
|
137 |
// Start transaction |
|
138 |
List<TaxonBase> taxonBaseList = null; |
|
139 |
txStatus = startTransaction(true); |
|
140 |
String nameRelationString = "NameRelationships"; |
|
141 |
logger.error("Started new transaction. Fetching some " + nameRelationString + " (max: " + limit + ") ..."); |
|
142 |
while ((taxonBaseList = getTaxonService().list(null, limit, count, null, null)).size() > 0) { |
|
143 |
|
|
144 |
logger.error("Fetched " + taxonBaseList.size() + " " + nameRelationString + ". Exporting..."); |
|
145 |
for (TaxonBase taxonBase : taxonBaseList) { |
|
146 |
doCount(count++, modCount, nameRelationString); |
|
147 |
|
|
148 |
Set<NameRelationship> nameRelations = taxonBase.getName().getNameRelations(); |
|
149 |
for (NameRelationship nameRelationship : nameRelations) { |
|
150 |
success &= mapping.invoke(nameRelationship); |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
// Commit transaction |
|
155 |
commitTransaction(txStatus); |
|
156 |
logger.error("Committed transaction."); |
|
157 |
logger.error("Exported " + (count - pastCount) + " " + nameRelationString + ". Total: " + count); |
|
158 |
pastCount = count; |
|
159 |
|
|
160 |
// Start transaction |
|
161 |
txStatus = startTransaction(true); |
|
162 |
logger.error("Started new transaction. Fetching some " + nameRelationString + " (max: " + limit + ") ..."); |
|
163 |
} |
|
164 |
if (list.size() == 0) { |
|
165 |
logger.error("No " + nameRelationString + " left to fetch."); |
|
166 |
} |
|
167 |
// Commit transaction |
|
168 |
commitTransaction(txStatus); |
|
169 |
logger.error("Committed transaction."); |
|
170 |
|
|
171 |
|
|
132 | 172 |
return success; |
133 | 173 |
} catch (SQLException e) { |
134 | 174 |
e.printStackTrace(); |
... | ... | |
218 | 258 |
@SuppressWarnings("unused") |
219 | 259 |
private static String getNotes(RelationshipBase<?, ?, ?> relationship) { |
220 | 260 |
// TODO |
221 |
String result = null; |
|
222 |
if (relationship != null) { |
|
223 |
Set<Annotation> annotations = relationship.getAnnotations(); |
|
224 |
if (annotations.size() == 1) { |
|
225 |
result = annotations.iterator().next().getText(); |
|
226 |
} else { |
|
227 |
logger.warn("Relationship has more than one Annotation: " + relationship.getUuid()); |
|
228 |
} |
|
229 |
} |
|
230 |
return result; |
|
261 |
return null; |
|
231 | 262 |
} |
232 | 263 |
|
233 | 264 |
/** |
... | ... | |
245 | 276 |
} else if (relationship.isInstanceOf(SynonymRelationship.class)) { |
246 | 277 |
SynonymRelationship sr = (SynonymRelationship)relationship; |
247 | 278 |
taxon = (isFrom) ? sr.getSynonym() : sr.getAcceptedTaxon(); |
279 |
} else if (relationship.isInstanceOf(NameRelationship.class)) { |
|
280 |
NameRelationship nr = (NameRelationship)relationship; |
|
281 |
TaxonNameBase taxonName = (isFrom) ? nr.getFromName() : nr.getToName(); |
|
282 |
return state.getDbId(taxonName); |
|
283 |
|
|
284 |
// Set taxa = taxonName.getTaxa(); |
|
285 |
// if (taxa.size() == 0) { |
|
286 |
// logger.warn("This TaxonName has no Taxon: " + taxonName.getTitleCache()); |
|
287 |
// return state.getDbId(taxonName); |
|
288 |
// } else if (taxa.size() == 1) { |
|
289 |
// taxon = (TaxonBase<?>) taxa.iterator().next(); |
|
290 |
// } else if (taxa.size() > 1) { |
|
291 |
// logger.warn("This TaxonName has " + taxa.size() + " Taxa: " + taxonName.getTitleCache()); |
|
292 |
// } |
|
248 | 293 |
} |
249 | 294 |
if (taxon != null) { |
250 |
return state.getDbId(taxon); |
|
295 |
return state.getDbId(taxon.getName());
|
|
251 | 296 |
} |
252 |
logger.warn("No taxon found for relationship: " + relationship.getUuid());
|
|
297 |
logger.warn("No taxon found in state for relationship: " + relationship.toString());
|
|
253 | 298 |
return null; |
254 | 299 |
} |
255 | 300 |
|
Also available in: Unified diff
merging /branches/cdmlib/SPRINT-Chichorieae1/ to trunk