Revision d6d15f6c
Added by Andreas Müller almost 4 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/parser/ParseHandler.java | ||
---|---|---|
22 | 22 |
* <p>ParseHandler class.</p> |
23 | 23 |
* |
24 | 24 |
* @author n.hoffmann |
25 |
* @author a.mueller |
|
25 | 26 |
*/ |
26 | 27 |
public class ParseHandler{ |
27 | 28 |
|
28 |
// private class MatchMatrix { |
|
29 |
// |
|
30 |
// List<TaxonName> duplicateNames = new ArrayList<>(); |
|
31 |
// List<INomenclaturalReference> duplicateReferences = new ArrayList<>(); |
|
32 |
// List<INomenclaturalReference> duplicateInReferences = new ArrayList<>(); |
|
33 |
// |
|
34 |
// List<TeamOrPersonBase<?>> duplicateCombinationAuthorships = new ArrayList<>(); |
|
35 |
// List<TeamOrPersonBase<?>> duplicateExCombinationAuthorships = new ArrayList<>(); |
|
36 |
// List<TeamOrPersonBase<?>> duplicateBasionymAuthorships = new ArrayList<>(); |
|
37 |
// List<TeamOrPersonBase<?>> duplicateExBasionymAuthorships = new ArrayList<>(); |
|
38 |
// } |
|
39 |
|
|
40 | 29 |
private static NonViralNameParserImpl nonViralNameParser = NonViralNameParserImpl.NewInstance(); |
41 | 30 |
|
42 | 31 |
/** |
... | ... | |
44 | 33 |
*/ |
45 | 34 |
private TaxonName name; |
46 | 35 |
|
47 |
// private boolean doResolveInReferences; |
|
48 |
|
|
49 | 36 |
/** |
50 | 37 |
* Creates a new instance |
51 | 38 |
*/ |
... | ... | |
135 | 122 |
*/ |
136 | 123 |
public INonViralName parseAndResolveDuplicates(String unparsedNameString){ |
137 | 124 |
|
138 |
// INonViralName parsedName = parse(unparsedNameString); |
|
139 |
|
|
140 |
TaxonName parsedName2 = (TaxonName)CdmStore.getService(INameService.class).parseName(name, unparsedNameString, null, true, true).getCdmEntity(); |
|
141 |
|
|
142 |
// MatchMatrix matchMatrix = findMatches(parsedName); |
|
143 |
// |
|
144 |
// resolveDuplicates(parsedName, matchMatrix); |
|
145 |
|
|
146 |
return parsedName2; |
|
125 |
TaxonName parsedName = (TaxonName)CdmStore.getService(INameService.class).parseName(name, unparsedNameString, null, true, true).getCdmEntity(); |
|
126 |
return parsedName; |
|
147 | 127 |
} |
148 | 128 |
|
149 |
// /** |
|
150 |
// * @param name The name to resolve duplicates for. |
|
151 |
// */ |
|
152 |
// private void resolveDuplicates(INonViralName name, MatchMatrix matchMatrix) { |
|
153 |
// resolveDuplicateNames(name, matchMatrix); |
|
154 |
// |
|
155 |
// resolveAllDuplicateAuthors(name, matchMatrix); |
|
156 |
// |
|
157 |
// resolveDuplicateReferences(name, matchMatrix); |
|
158 |
// |
|
159 |
//// if(matchMatrix.duplicateInReferences != null) { |
|
160 |
//// resolveDuplicateInReferences(name, matchMatrix); |
|
161 |
//// } |
|
162 |
// } |
|
163 |
// |
|
164 |
// |
|
165 |
// /** |
|
166 |
// * @param name The name to resolve duplicates for. |
|
167 |
// */ |
|
168 |
// private void resolveDuplicateNames(INonViralName name, MatchMatrix matchMatrix) { |
|
169 |
// //FIXME this has no effect yet as the new name is not used |
|
170 |
// if (matchMatrix.duplicateNames.size() == 1){ |
|
171 |
// name = matchMatrix.duplicateNames.iterator().next(); |
|
172 |
// }else if(matchMatrix.duplicateNames.size() > 1){ |
|
173 |
// // FIXME TODO resolve multiple duplications. Use first match for a start |
|
174 |
// name = matchMatrix.duplicateNames.iterator().next(); |
|
175 |
// } |
|
176 |
// } |
|
177 |
// |
|
178 |
// /** |
|
179 |
// * @param name The name to resolve duplicates for. |
|
180 |
// */ |
|
181 |
// private void resolveDuplicateReferences(INonViralName name, MatchMatrix matchMatrix) { |
|
182 |
// if(matchMatrix.duplicateReferences.size() == 1){ |
|
183 |
// // exactly one match. We assume that the user wants this reference |
|
184 |
// INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next(); |
|
185 |
// name.setNomenclaturalReference(duplicate); |
|
186 |
// }else if(matchMatrix.duplicateReferences.size() > 1){ |
|
187 |
// // FIXME TODO resolve multiple duplications. Use first match for a start |
|
188 |
// INomenclaturalReference duplicate = matchMatrix.duplicateReferences.iterator().next(); |
|
189 |
// name.setNomenclaturalReference(duplicate); |
|
190 |
// } |
|
191 |
// //if reference is new but the in reference is already in db |
|
192 |
// if (matchMatrix.duplicateReferences.size() == 0 && (name.getNomenclaturalReference() != null && name.getNomenclaturalReference().getInReference() != null) && matchMatrix.duplicateInReferences.size() > 0){ |
|
193 |
// resolveDuplicateInReferences(name, matchMatrix); |
|
194 |
// } |
|
195 |
// } |
|
196 |
// |
|
197 |
// /** |
|
198 |
// * @param name The name to resolve duplicates for. |
|
199 |
// */ |
|
200 |
// private void resolveDuplicateInReferences(INonViralName name, MatchMatrix matchMatrix) { |
|
201 |
// Reference reference = HibernateProxyHelper.deproxy(name.getNomenclaturalReference()); |
|
202 |
// |
|
203 |
// if(matchMatrix.duplicateInReferences.size() > 0){ |
|
204 |
// Reference inReference = (Reference) matchMatrix.duplicateInReferences.iterator().next(); |
|
205 |
// reference.setInReference(inReference); |
|
206 |
// MessagingUtils.warn(this.getClass(), reference.generateTitle()); |
|
207 |
// // FIXME TODO resolve multiple duplications. We use first match for a start |
|
208 |
// MessagingUtils.warn(this.getClass(), reference.getTitleCache()); |
|
209 |
// } |
|
210 |
// } |
|
211 |
// |
|
212 |
// |
|
213 |
// /** |
|
214 |
// * @param name The name to resolve duplicates for. |
|
215 |
// */ |
|
216 |
// private void resolveAllDuplicateAuthors(INonViralName name, MatchMatrix matchMatrix) { |
|
217 |
// |
|
218 |
// if(matchMatrix.duplicateCombinationAuthorships.size() > 0){ |
|
219 |
// name.setCombinationAuthorship(matchMatrix.duplicateCombinationAuthorships.iterator().next()); |
|
220 |
// Reference reference = name.getNomenclaturalReference(); |
|
221 |
// if(reference != null){ |
|
222 |
// reference.setAuthorship(matchMatrix.duplicateCombinationAuthorships.iterator().next()); |
|
223 |
// } |
|
224 |
// // FIXME TODO resolve multiple duplications. We use first match for a start. |
|
225 |
// } |
|
226 |
// |
|
227 |
// if(matchMatrix.duplicateExCombinationAuthorships.size() > 0){ |
|
228 |
// name.setExCombinationAuthorship(matchMatrix.duplicateExCombinationAuthorships.iterator().next()); |
|
229 |
// // FIXME TODO resolve multiple duplications. We use first match for a start. |
|
230 |
// } |
|
231 |
// |
|
232 |
// if(matchMatrix.duplicateBasionymAuthorships.size() > 0){ |
|
233 |
// name.setBasionymAuthorship(matchMatrix.duplicateBasionymAuthorships.iterator().next()); |
|
234 |
// // FIXME TODO resolve multiple duplications. We use first match for a start. |
|
235 |
// } |
|
236 |
// |
|
237 |
// if(matchMatrix.duplicateExBasionymAuthorships.size() > 0){ |
|
238 |
// name.setExBasionymAuthorship(matchMatrix.duplicateExBasionymAuthorships.iterator().next()); |
|
239 |
// // FIXME TODO resolve multiple duplications. We use first match for a start. |
|
240 |
// } |
|
241 |
// } |
|
242 |
// |
|
243 |
// /** |
|
244 |
// * Splits a NonViralName into its parts and calls methods to find matches for these |
|
245 |
// * parts in the database. |
|
246 |
// * |
|
247 |
// * @param name The NonViralName to find matches for. |
|
248 |
// */ |
|
249 |
// private MatchMatrix findMatches(INonViralName name){ |
|
250 |
// |
|
251 |
// MatchMatrix matchMatrix = new MatchMatrix(); |
|
252 |
// |
|
253 |
// matchMatrix.duplicateNames = findMatchingLatinNames(name); |
|
254 |
// |
|
255 |
// matchMatrix.duplicateCombinationAuthorships = findMatchingAuthors(name.getCombinationAuthorship()); |
|
256 |
// matchMatrix.duplicateExCombinationAuthorships = findMatchingAuthors(name.getExCombinationAuthorship()); |
|
257 |
// matchMatrix.duplicateBasionymAuthorships = findMatchingAuthors(name.getBasionymAuthorship()); |
|
258 |
// matchMatrix.duplicateExBasionymAuthorships = findMatchingAuthors(name.getExBasionymAuthorship()); |
|
259 |
// |
|
260 |
// INomenclaturalReference nomenclaturalReference = name.getNomenclaturalReference(); |
|
261 |
// |
|
262 |
// // check if the reference has an inreference and also check if the inReference already exists |
|
263 |
// if(nomenclaturalReference != null){ |
|
264 |
// Reference inReference = ((Reference)nomenclaturalReference).getInReference(); |
|
265 |
// if(inReference != null){ |
|
266 |
// doResolveInReferences = true; |
|
267 |
// matchMatrix.duplicateInReferences = findMatchingNomenclaturalReference(inReference); |
|
268 |
// } |
|
269 |
// } |
|
270 |
// |
|
271 |
// matchMatrix.duplicateReferences = findMatchingNomenclaturalReference(nomenclaturalReference); |
|
272 |
// |
|
273 |
// return matchMatrix; |
|
274 |
// } |
|
275 |
// |
|
276 |
// /** |
|
277 |
// * @param nomenclaturalReference The NomenclaturalReference to find matches for. |
|
278 |
// * @return A <code>List</code> of possibly matching NomenclaturalReference's. |
|
279 |
// */ |
|
280 |
// private List<INomenclaturalReference> findMatchingNomenclaturalReference(INomenclaturalReference nomenclaturalReference) { |
|
281 |
// if(nomenclaturalReference == null) { |
|
282 |
// return new ArrayList<INomenclaturalReference>(); |
|
283 |
// } |
|
284 |
// try{ |
|
285 |
// return CdmStore.getCommonService().findMatching(nomenclaturalReference, MatchStrategy.Reference); |
|
286 |
// }catch (MatchException e) { |
|
287 |
// MessagingUtils.error(this.getClass(), "Error finding matching references", e); |
|
288 |
// } |
|
289 |
// return null; |
|
290 |
// } |
|
291 |
// |
|
292 |
// /** |
|
293 |
// * @param authorTeam The TeamOrPersonBase to find matches for. |
|
294 |
// * @return A <code>List</code> of possibly matching TeamOrPersonBase's. |
|
295 |
// */ |
|
296 |
// private List<TeamOrPersonBase<?>> findMatchingAuthors(TeamOrPersonBase<?> authorTeam) { |
|
297 |
// |
|
298 |
// if(authorTeam == null){ |
|
299 |
// return new ArrayList<>(); |
|
300 |
// } |
|
301 |
// try{ |
|
302 |
// return CdmStore.getCommonService().findMatching(authorTeam, MatchStrategy.TeamOrPerson); |
|
303 |
// |
|
304 |
// }catch (MatchException e) { |
|
305 |
// MessagingUtils.error(this.getClass(), "Error finding matching authors", e); |
|
306 |
// } |
|
307 |
// return null; |
|
308 |
// } |
|
309 |
// |
|
310 |
// /** |
|
311 |
// * @param taxonName The TaxonNameBase to find matches for. |
|
312 |
// * @return A <code>List</code> of possibly matching TaxonNameBase's. |
|
313 |
// */ |
|
314 |
// private List<TaxonName> findMatchingLatinNames(ITaxonNameBase taxonName) { |
|
315 |
// try { |
|
316 |
// return CdmStore.getCommonService().findMatching(TaxonName.castAndDeproxy(taxonName), MatchStrategy.NonViralName); |
|
317 |
// } catch (MatchException e) { |
|
318 |
// MessagingUtils.error(this.getClass(), "Error finding matching names", e); |
|
319 |
// } |
|
320 |
// return null; |
|
321 |
// } |
|
322 | 129 |
} |
Also available in: Unified diff
ref #9078 remove commented code in ParseHandler