implemented user management, fixes #803. Minor refactorings.
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / model / TaxonHelper.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.model;
11
12 import java.util.HashSet;
13 import java.util.Set;
14
15 import org.apache.log4j.Logger;
16
17 import eu.etaxonomy.cdm.model.taxon.Taxon;
18 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
19
20 /**
21 * @author n.hoffmann
22 * @created 25.03.2009
23 * @version 1.0
24 */
25 public class TaxonHelper {
26 private static final Logger logger = Logger
27 .getLogger(TaxonHelper.class);
28
29
30 /**
31 * TODO this method should be in cdm library
32 *
33 * Example:
34 * TaxonA(fromTaxon) isOverlapping TaxonB(toTaxon)
35 *
36 * @param fromTaxon
37 * @param toTaxon
38 * @return
39 * @deprecated TODO this method should be in the library
40 */
41 public static TaxonRelationship getRelationshipBetweenTwoTaxa(Taxon fromTaxon, Taxon toTaxon){
42 Set<TaxonRelationship> relations = new HashSet<TaxonRelationship>();
43
44 for(TaxonRelationship relation : fromTaxon.getRelationsFromThisTaxon()){
45 if(relation.getToTaxon().equals(toTaxon)){
46 relations.add(relation);
47 }
48 }
49
50 if(relations.size() > 1){
51 logger.warn("Found multiple relations between two taxa. Does this make sense?");
52 }
53
54 if(relations.size() == 0){
55 logger.warn("No relations between the two given taxa");
56 new Throwable("No relations between the two given taxa");
57 }
58
59 return relations.toArray(new TaxonRelationship[0])[0];
60 }
61 }