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
|
public class TeamDefaultCacheStrategy extends StrategyBase implements INomenclaturalAuthorCacheStrategy<Team> {
|
25
|
private static final long serialVersionUID = 8375295443642690479L;
|
26
|
@SuppressWarnings("unused")
|
27
|
private static final Logger logger = Logger.getLogger(TeamDefaultCacheStrategy.class);
|
28
|
|
29
|
|
30
|
public static final String FINAL_TEAM_CONCATINATION = " & ";
|
31
|
public static final String STD_TEAM_CONCATINATION = ", ";
|
32
|
public static final String ET_AL_TEAM_CONCATINATION_FULL = " & ";
|
33
|
public static final String ET_AL_TEAM_CONCATINATION_ABBREV = " & ";
|
34
|
|
35
|
public static final String EMPTY_TEAM = "-empty team-";
|
36
|
|
37
|
final static UUID uuid = UUID.fromString("1cbda0d1-d5cc-480f-bf38-40a510a3f223");
|
38
|
|
39
|
private int etAlPosition = 4;
|
40
|
|
41
|
// ************************* FACTORY ************************/
|
42
|
|
43
|
static public TeamDefaultCacheStrategy NewInstance(){
|
44
|
return new TeamDefaultCacheStrategy();
|
45
|
}
|
46
|
|
47
|
static public TeamDefaultCacheStrategy NewInstance(int etAlPosition){
|
48
|
TeamDefaultCacheStrategy result = new TeamDefaultCacheStrategy();
|
49
|
result.setEtAlPosition(etAlPosition);
|
50
|
return result;
|
51
|
}
|
52
|
|
53
|
// ********************* CONSTRUCTOR ***************************/
|
54
|
|
55
|
private TeamDefaultCacheStrategy() {
|
56
|
super();
|
57
|
}
|
58
|
|
59
|
@Override
|
60
|
protected UUID getUuid() {
|
61
|
return uuid;
|
62
|
}
|
63
|
|
64
|
// ************** GETTER / SETTER *******************/
|
65
|
|
66
|
public int getEtAlPosition() {
|
67
|
return etAlPosition;
|
68
|
}
|
69
|
|
70
|
public void setEtAlPosition(int etAlPosition) {
|
71
|
this.etAlPosition = etAlPosition;
|
72
|
}
|
73
|
|
74
|
// *********************** MTEHODS ****************/
|
75
|
|
76
|
@Override
|
77
|
public String getNomenclaturalTitle(Team team) {
|
78
|
String result = "";
|
79
|
|
80
|
List<Person> teamMembers = team.getTeamMembers();
|
81
|
int i = 0;
|
82
|
for (Person teamMember : teamMembers){
|
83
|
if(teamMember == null){
|
84
|
// this can happen in UIs in the process of adding new members
|
85
|
continue;
|
86
|
}
|
87
|
i++;
|
88
|
String concat = concatString(team, teamMembers, i);
|
89
|
result += concat + teamMember.getNomenclaturalTitle();
|
90
|
}
|
91
|
if (teamMembers.size() == 0){
|
92
|
result = team.getTitleCache();
|
93
|
}else if (team.isHasMoreMembers()){
|
94
|
result = addHasMoreMembers(result);
|
95
|
}
|
96
|
return result;
|
97
|
}
|
98
|
|
99
|
|
100
|
@Override
|
101
|
public String getTitleCache(Team team) {
|
102
|
String result = "";
|
103
|
List<Person> teamMembers = team.getTeamMembers();
|
104
|
|
105
|
for (int i = 1; i <= teamMembers.size() && i < etAlPosition; i++){
|
106
|
Person teamMember = teamMembers.get(i-1);
|
107
|
if(teamMember == null){
|
108
|
// this can happen in UIs in the process of adding new members
|
109
|
continue;
|
110
|
}
|
111
|
String concat = concatString(team, teamMembers, i);
|
112
|
result += concat + teamMember.getTitleCache();
|
113
|
}
|
114
|
if (teamMembers.size() == 0){
|
115
|
result = EMPTY_TEAM;
|
116
|
} else if (team.isHasMoreMembers() || teamMembers.size() >= etAlPosition){
|
117
|
result += ET_AL_TEAM_CONCATINATION_FULL + "al.";
|
118
|
}
|
119
|
return result;
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public String getFullTitle(Team team) {
|
124
|
String result = "";
|
125
|
List<Person> teamMembers = team.getTeamMembers();
|
126
|
|
127
|
int i = 0;
|
128
|
for (Person teamMember : teamMembers){
|
129
|
if(teamMember == null){
|
130
|
// this can happen in UIs in the process of adding new members
|
131
|
continue;
|
132
|
}
|
133
|
i++;
|
134
|
String concat = concatString(team, teamMembers, i);
|
135
|
result += concat + teamMember.getFullTitle();
|
136
|
}
|
137
|
if (teamMembers.size() == 0){
|
138
|
result = EMPTY_TEAM;
|
139
|
} else if (team.isHasMoreMembers()){
|
140
|
result += ET_AL_TEAM_CONCATINATION_FULL + "al.";
|
141
|
}
|
142
|
return result;
|
143
|
}
|
144
|
|
145
|
public static String concatString(Team team, List<Person> teamMembers, int i) {
|
146
|
String concat;
|
147
|
if (i <= 1){
|
148
|
concat = "";
|
149
|
}else if (i < teamMembers.size() || ( team.isHasMoreMembers() && i == teamMembers.size())){
|
150
|
concat = STD_TEAM_CONCATINATION;
|
151
|
}else{
|
152
|
concat = FINAL_TEAM_CONCATINATION;
|
153
|
}
|
154
|
return concat;
|
155
|
}
|
156
|
|
157
|
|
158
|
/**
|
159
|
* Add the et al. to the team string
|
160
|
* @param str team string without et al.
|
161
|
* @return
|
162
|
*/
|
163
|
public static String addHasMoreMembers(String str) {
|
164
|
return str + ET_AL_TEAM_CONCATINATION_ABBREV + "al.";
|
165
|
}
|
166
|
|
167
|
}
|