Project

General

Profile

Download (1.51 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

    
11
package eu.etaxonomy.taxeditor.model;
12

    
13
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
14
import eu.etaxonomy.cdm.model.agent.Person;
15
import eu.etaxonomy.cdm.model.agent.Team;
16
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
17

    
18
/**
19
 * Utility class for handling of authorship related elements.
20
 *
21
 * @author n.hoffmann
22
 * @created Sep 8, 2010
23
 * @version 1.0
24
 */
25
public class AuthorHelper {
26

    
27
    /**
28
     * If the given {@link TeamOrPersonBase} is a {@link Person} this methods
29
     * creates a new {@link Team} with this person. If it already a team the
30
     * team is returned.
31
     * 
32
     * @param teamOrPerson
33
     *            a team or a person
34
     * @return the given team or a newly created team with the given person
35
     */
36
	public static Team getAuthor(TeamOrPersonBase<?> teamOrPerson){
37
		if(teamOrPerson == null){
38
			return null;
39
		}
40
		Object deproxiedObject = HibernateProxyHelper.deproxy(teamOrPerson);
41
		if(deproxiedObject instanceof Person){
42
			Person person = (Person) deproxiedObject;
43
			Team team = Team.NewInstance();
44
			team.addTeamMember(person);
45
			return team;
46
		}
47
		else if(deproxiedObject instanceof Team){
48
			return (Team) deproxiedObject;
49
		}else{
50
			throw new IllegalArgumentException("Given object os of the wrong type");
51
		}
52
	}
53
}
(3-3/37)