Revision 50818ab7
Added by Katja Luther over 8 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/wp6/diptera/DipteraPostImportUpdater.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 |
*/ |
... | ... | |
25 | 25 |
import eu.etaxonomy.cdm.app.common.CdmDestinations; |
26 | 26 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
27 | 27 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
28 |
import eu.etaxonomy.cdm.model.common.CdmBase;
|
|
28 |
import eu.etaxonomy.cdm.io.common.ImportResult;
|
|
29 | 29 |
import eu.etaxonomy.cdm.model.common.Language; |
30 | 30 |
import eu.etaxonomy.cdm.model.common.OriginalSourceType; |
31 | 31 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
... | ... | |
37 | 37 |
import eu.etaxonomy.cdm.model.name.NonViralName; |
38 | 38 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
39 | 39 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
40 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
|
41 | 40 |
|
42 | 41 |
/** |
43 | 42 |
* @author a.mueller |
... | ... | |
48 | 47 |
private static final Logger logger = Logger.getLogger(DipteraPostImportUpdater.class); |
49 | 48 |
|
50 | 49 |
static final ICdmDataSource cdmDestination = CdmDestinations.localH2Palmae(); |
51 |
|
|
50 |
|
|
52 | 51 |
/** |
53 |
* This method updateds the citation text by deleting <code>OriginalName</code> tags and
|
|
52 |
* This method updateds the citation text by deleting <code>OriginalName</code> tags and |
|
54 | 53 |
* adding the original name to the source either as a link to an existing taxon name |
55 | 54 |
* or as a string. The later becomes true if there is not exactly one matching name |
56 | 55 |
* @param dataSource |
57 | 56 |
* @return |
58 | 57 |
*/ |
59 |
public boolean updateCitations(ICdmDataSource dataSource) {
|
|
60 |
try{ |
|
58 |
public ImportResult updateCitations(ICdmDataSource dataSource) {
|
|
59 |
|
|
61 | 60 |
logger.warn("start updating citations"); |
62 |
boolean result = true; |
|
61 |
ImportResult result = new ImportResult(); |
|
62 |
try{ |
|
63 | 63 |
CdmApplicationController cdmApp = CdmApplicationController.NewInstance(dataSource, DbSchemaValidation.VALIDATE); |
64 | 64 |
Set<DescriptionElementBase> citationsToSave = new HashSet<DescriptionElementBase>(); |
65 | 65 |
TransactionStatus tx = cdmApp.startTransaction(); |
... | ... | |
73 | 73 |
Map<String, TaxonNameBase> nameMap = new HashMap<String, TaxonNameBase>(); |
74 | 74 |
Map<String, TaxonNameBase> nameDuplicateMap = new HashMap<String, TaxonNameBase>(); |
75 | 75 |
fillNameMaps(nameList, nameMap, nameDuplicateMap); |
76 |
|
|
76 |
|
|
77 | 77 |
int i = 0; |
78 |
|
|
78 |
|
|
79 | 79 |
for (Taxon taxon : taxonList){ |
80 | 80 |
if ((i++ % modCount) == 0){ logger.warn("taxa handled: " + (i-1));} |
81 |
|
|
81 |
|
|
82 | 82 |
Set<TextData> citations = getCitations(taxon); |
83 | 83 |
for (TextData citation : citations){ |
84 | 84 |
Language language = Language.DEFAULT(); |
... | ... | |
88 | 88 |
citation.removeText(language); |
89 | 89 |
citation.putText(language, newText); |
90 | 90 |
TaxonNameBase<?,?> scientificName = getScientificName(originalNameString, nameMap, nameDuplicateMap); |
91 |
|
|
91 |
|
|
92 | 92 |
Set<DescriptionElementSource> sources = citation.getSources(); |
93 | 93 |
if (sources.size() > 1){ |
94 | 94 |
logger.warn("There are more then 1 sources for a description"); |
... | ... | |
104 | 104 |
source.setOriginalNameString(originalNameString); |
105 | 105 |
} |
106 | 106 |
} |
107 |
|
|
107 |
|
|
108 | 108 |
citationsToSave.add(citation); |
109 | 109 |
} |
110 | 110 |
} |
111 |
|
|
111 |
|
|
112 | 112 |
cdmApp.getDescriptionService().saveDescriptionElement(citationsToSave); |
113 | 113 |
//commit |
114 | 114 |
cdmApp.commitTransaction(tx); |
115 | 115 |
logger.warn("Citations updated!"); |
116 |
result.setSuccess(true); |
|
116 | 117 |
return result; |
117 | 118 |
} catch (Exception e) { |
118 | 119 |
e.printStackTrace(); |
119 | 120 |
logger.error("ERROR in citation update"); |
120 |
return false; |
|
121 |
result.setSuccess(false); |
|
122 |
result.addReport(e.getMessage().getBytes()); |
|
123 |
return result; |
|
121 | 124 |
} |
122 |
|
|
125 |
|
|
123 | 126 |
} |
124 |
|
|
125 |
public boolean updateCollections(ICdmDataSource dataSource){
|
|
127 |
|
|
128 |
public ImportResult updateCollections(ICdmDataSource dataSource){
|
|
126 | 129 |
DipteraCollectionImport collectionImport = new DipteraCollectionImport(); |
127 | 130 |
return collectionImport.invoke(dataSource); |
128 | 131 |
} |
... | ... | |
139 | 142 |
} |
140 | 143 |
} |
141 | 144 |
} |
142 |
|
|
143 |
|
|
145 |
|
|
146 |
|
|
144 | 147 |
private TaxonNameBase getScientificName(String originalNameString, Map<String, TaxonNameBase> nameMap, Map<String, TaxonNameBase> nameDuplicateMap) { |
145 | 148 |
originalNameString = originalNameString.trim(); |
146 | 149 |
TaxonNameBase result = nameMap.get(originalNameString); |
... | ... | |
203 | 206 |
|
204 | 207 |
|
205 | 208 |
|
206 |
|
|
209 |
|
|
207 | 210 |
/** |
208 | 211 |
* @param args |
209 | 212 |
*/ |
Also available in: Unified diff
adapt the import classes to the new return type ImportResult