Revision 3ef2e1bd
Added by Andreas Müller over 7 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/wp6/palmae/PalmaePostImportUpdater.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
42 | 42 |
private static final Logger logger = Logger.getLogger(PalmaePostImportUpdater.class); |
43 | 43 |
|
44 | 44 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2Palmae(); |
45 |
|
|
46 |
|
|
45 |
|
|
46 |
|
|
47 | 47 |
private String relationships = "relationships"; |
48 | 48 |
private String taxonomicAccounts = "taxonomic accounts"; |
49 | 49 |
private String fossilRecord = "fossil record"; |
50 |
|
|
50 |
|
|
51 | 51 |
public boolean updateMissingFeatures(ICdmDataSource dataSource) { |
52 | 52 |
try{ |
53 | 53 |
int count = 0; |
54 | 54 |
UUID featureTreeUuid = PalmaeActivator.featureTreeUuid; |
55 | 55 |
CdmApplicationController cdmApp = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.VALIDATE); |
56 |
|
|
56 |
|
|
57 | 57 |
TransactionStatus tx = cdmApp.startTransaction(); |
58 |
|
|
58 |
|
|
59 | 59 |
FeatureTree tree = cdmApp.getFeatureTreeService().find(featureTreeUuid); |
60 | 60 |
FeatureNode root = tree.getRoot(); |
61 |
|
|
61 |
|
|
62 | 62 |
List<Feature> featureList = cdmApp.getTermService().list(Feature.class, null, null, null, null); |
63 | 63 |
for (Feature feature : featureList){ |
64 | 64 |
String label = feature.getLabel(); |
... | ... | |
88 | 88 |
logger.error("ERROR in feature tree update"); |
89 | 89 |
return false; |
90 | 90 |
} |
91 |
|
|
91 |
|
|
92 | 92 |
} |
93 |
|
|
93 |
|
|
94 | 94 |
public boolean updateNameUsage(ICdmDataSource dataSource) { |
95 | 95 |
try{ |
96 | 96 |
boolean result = true; |
... | ... | |
102 | 102 |
int count = cdmApp.getTaxonService().count(Taxon.class); |
103 | 103 |
List<TaxonBase> taxonList = cdmApp.getTaxonService().list(TaxonBase.class, 100000, page, null, null); |
104 | 104 |
int i = 0; |
105 |
|
|
105 |
|
|
106 | 106 |
IReference treatmentReference = (IReference) cdmApp.getCommonService().getSourcedObjectByIdInSource(Reference.class, "palm_pub_ed_999999", "PublicationCitation"); |
107 | 107 |
if (treatmentReference == null){ |
108 | 108 |
logger.error("Treatment reference could not be found"); |
... | ... | |
110 | 110 |
}else{ |
111 | 111 |
for (TaxonBase nameUsage : taxonList){ |
112 | 112 |
if ((i++ % 100) == 0){System.out.println(i);}; |
113 |
|
|
113 |
|
|
114 | 114 |
try { |
115 | 115 |
//if not in treatment |
116 | 116 |
if (! isInTreatment(nameUsage, treatmentReference, false)){ |
... | ... | |
156 | 156 |
logger.error("ERROR in name usage update"); |
157 | 157 |
return false; |
158 | 158 |
} |
159 |
|
|
159 |
|
|
160 | 160 |
} |
161 | 161 |
|
162 | 162 |
/** |
163 |
* @param nameUsage
|
|
163 |
* @param nameUsage |
|
164 | 164 |
* @return |
165 | 165 |
*/ |
166 | 166 |
private Taxon getAcceptedTreatmentTaxon(TaxonBase nameUsage, IReference treatmentReference) { |
... | ... | |
174 | 174 |
} |
175 | 175 |
}else if (candidate instanceof Synonym){ |
176 | 176 |
Synonym synonym = (Synonym)candidate; |
177 |
Set<Taxon> accTaxa = synonym.getAcceptedTaxa();
|
|
177 |
Taxon accTaxon = synonym.getAcceptedTaxon();
|
|
178 | 178 |
if (isInTreatment(synonym, treatmentReference, true)){ |
179 | 179 |
hasSynonymInTreatment = true; |
180 | 180 |
} |
181 |
for (Taxon accTaxon : accTaxa){
|
|
181 |
if (accTaxon != null){
|
|
182 | 182 |
if (isInTreatment(accTaxon, treatmentReference, false)){ |
183 | 183 |
return accTaxon; |
184 | 184 |
} |
... | ... | |
195 | 195 |
|
196 | 196 |
/** |
197 | 197 |
* @param taxonBase |
198 |
* @param treatmentReference
|
|
198 |
* @param treatmentReference |
|
199 | 199 |
* @return |
200 | 200 |
*/ |
201 | 201 |
private boolean isInTreatment(TaxonBase taxonBase, IReference treatmentReference, boolean silent) { |
... | ... | |
209 | 209 |
}else if (taxonBase instanceof Synonym){ |
210 | 210 |
Synonym synonym = (Synonym)taxonBase; |
211 | 211 |
boolean hasAccTaxonInTreatment = false; |
212 |
for (Taxon accTaxon : synonym.getAcceptedTaxa()){ |
|
212 |
Taxon accTaxon = synonym.getAcceptedTaxon(); |
|
213 |
if (accTaxon != null){ |
|
213 | 214 |
hasAccTaxonInTreatment |= isInTreatment(accTaxon, treatmentReference, false); |
214 | 215 |
} |
215 | 216 |
if (hasAccTaxonInTreatment == false){ |
... | ... | |
230 | 231 |
}else if (taxonBase instanceof Synonym){ |
231 | 232 |
Synonym synonym = (Synonym)taxonBase; |
232 | 233 |
boolean hasAccTaxonInTreatment = false; |
233 |
for (Taxon accTaxon : synonym.getAcceptedTaxa()){ |
|
234 |
Taxon accTaxon = synonym.getAcceptedTaxon(); |
|
235 |
if (accTaxon != null){ |
|
234 | 236 |
hasAccTaxonInTreatment |= isInTreatment(accTaxon, treatmentReference, false); |
235 | 237 |
} |
236 | 238 |
if (hasAccTaxonInTreatment == true){ |
... | ... | |
243 | 245 |
return false; |
244 | 246 |
} |
245 | 247 |
} |
246 |
|
|
248 |
|
|
247 | 249 |
/** |
248 | 250 |
* @param taxonCandidate |
249 | 251 |
* @param taxon |
... | ... | |
266 | 268 |
myDescription.addElement(textData); |
267 | 269 |
return true; |
268 | 270 |
} |
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
271 | 273 |
/** |
272 | 274 |
* @param args |
273 | 275 |
*/ |
Also available in: Unified diff
ref #5974 Remove synonym relationships (not finished yet)