1
|
/**
|
2
|
* Copyright (C) 2009 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.cdm.strategy.cache.agent;
|
11
|
|
12
|
import java.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.agent.Person;
|
18
|
import eu.etaxonomy.cdm.model.agent.Team;
|
19
|
import eu.etaxonomy.cdm.strategy.StrategyBase;
|
20
|
|
21
|
/**
|
22
|
* @author AM
|
23
|
*
|
24
|
*/
|
25
|
public class TeamDefaultCacheStrategy extends StrategyBase implements INomenclaturalAuthorCacheStrategy<Team> {
|
26
|
private static final long serialVersionUID = 8375295443642690479L;
|
27
|
@SuppressWarnings("unused")
|
28
|
private static final Logger logger = Logger.getLogger(TeamDefaultCacheStrategy.class);
|
29
|
|
30
|
|
31
|
private static final String FINAL_TEAM_CONCATINATION = " & ";
|
32
|
private static final String STD_TEAM_CONCATINATION = ", ";
|
33
|
private static final String ET_AL_TEAM_CONCATINATION_FULL = " & ";
|
34
|
private static final String ET_AL_TEAM_CONCATINATION_ABBREV = " & ";
|
35
|
|
36
|
|
37
|
final static UUID uuid = UUID.fromString("1cbda0d1-d5cc-480f-bf38-40a510a3f223");
|
38
|
|
39
|
public static final String EMPTY_TEAM = "-empty team-";
|
40
|
|
41
|
static public TeamDefaultCacheStrategy NewInstance(){
|
42
|
return new TeamDefaultCacheStrategy();
|
43
|
}
|
44
|
|
45
|
private TeamDefaultCacheStrategy() {
|
46
|
super();
|
47
|
}
|
48
|
|
49
|
@Override
|
50
|
protected UUID getUuid() {
|
51
|
return uuid;
|
52
|
}
|
53
|
|
54
|
@Override
|
55
|
public String getNomenclaturalTitle(Team team) {
|
56
|
String result = "";
|
57
|
|
58
|
List<Person> teamMembers = team.getTeamMembers();
|
59
|
int i = 0;
|
60
|
for (Person teamMember : teamMembers){
|
61
|
i++;
|
62
|
String concat = concatString(team, teamMembers, i);
|
63
|
result += concat + teamMember.getNomenclaturalTitle();
|
64
|
}
|
65
|
if (teamMembers.size() == 0){
|
66
|
result = team.getTitleCache();
|
67
|
}else if (team.isHasMoreMembers()){
|
68
|
result = addHasMoreMembers(result);
|
69
|
}
|
70
|
return result;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* Add the et al. to the team string
|
75
|
* @param str team string without et al.
|
76
|
* @return
|
77
|
*/
|
78
|
public static String addHasMoreMembers(String str) {
|
79
|
return str + ET_AL_TEAM_CONCATINATION_ABBREV + "al.";
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
public String getTitleCache(Team team) {
|
84
|
// TODO is still dummy
|
85
|
String result = "";
|
86
|
List<Person> teamMembers = team.getTeamMembers();//Hibernate.initialize(teamMembers);
|
87
|
|
88
|
int i = 0;
|
89
|
for (Person teamMember : teamMembers){
|
90
|
i++;
|
91
|
String concat = concatString(team, teamMembers, i);
|
92
|
result += concat + teamMember.getTitleCache();
|
93
|
}
|
94
|
if (teamMembers.size() == 0){
|
95
|
result = EMPTY_TEAM;
|
96
|
} else if (team.isHasMoreMembers()){
|
97
|
result += ET_AL_TEAM_CONCATINATION_FULL + "al.";
|
98
|
}
|
99
|
return result;
|
100
|
}
|
101
|
|
102
|
public static String concatString(Team team, List<Person> teamMembers, int i) {
|
103
|
String concat;
|
104
|
if (i <= 1){
|
105
|
concat = "";
|
106
|
}else if (i < teamMembers.size() || ( team.isHasMoreMembers() && i == teamMembers.size())){
|
107
|
concat = STD_TEAM_CONCATINATION;
|
108
|
}else{
|
109
|
concat = FINAL_TEAM_CONCATINATION;
|
110
|
}
|
111
|
return concat;
|
112
|
}
|
113
|
|
114
|
}
|