Project

General

Profile

Download (7.25 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.cdm.remote.dto.namecatalogue;
2

    
3
import java.util.ArrayList;
4
import java.util.HashSet;
5
import java.util.Iterator;
6
import java.util.List;
7
import java.util.Set;
8

    
9
import eu.etaxonomy.cdm.model.common.Language;
10
import eu.etaxonomy.cdm.model.name.NameRelationship;
11
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
12
import eu.etaxonomy.cdm.model.name.TaxonName;
13
import eu.etaxonomy.cdm.model.reference.Reference;
14
import eu.etaxonomy.cdm.model.taxon.Taxon;
15
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
16
import eu.etaxonomy.cdm.remote.dto.common.RemoteResponse;
17

    
18
public class NameInformation implements RemoteResponse {
19

    
20
	private NameInformation.NameInformationRequest request;
21
	private NameInformation.NameInformationResponse response;
22

    
23
	public NameInformation() {
24

    
25
	}
26

    
27
	public void setRequest(String nameUuid) {
28
		request = new NameInformation.NameInformationRequest();
29
		request.setNameUuid(nameUuid);
30
	}
31

    
32
	public void setResponse(String title,
33
			String name,
34
			String rank,
35
			Set<NomenclaturalStatus> nomenclatureStatus,
36
			String citation,
37
			Set<NameRelationship> relationsFromThisName,
38
			Set<NameRelationship> relationsToThisName,
39
			Set<TaxonBase> taxonBases) {
40
		response = new NameInformation.NameInformationResponse();
41
		response.setTitle(title);
42
		response.setName(name);
43
		response.setRank(rank);
44

    
45
		// set status list
46
		Iterator it = nomenclatureStatus.iterator();
47
		System.out.println("NStatus Size : " + nomenclatureStatus.size());
48
		while(it.hasNext()) {
49
			NomenclaturalStatus ns = (NomenclaturalStatus)it.next();
50
			response.addToNomenclatureStaus(ns.toString());
51
		}
52
		// set citation
53
		response.setCitation(citation);
54

    
55
		addToResponseNameRelationships(relationsFromThisName, relationsToThisName);
56
		addToResponseTaxonInfo(taxonBases);
57

    
58
	}
59

    
60

    
61
	private void addToResponseNameRelationships(Set<NameRelationship> relationsFromThisName,
62
				Set<NameRelationship> relationsToThisName) {
63
		// set name from relationship
64
		String typeString = "";
65
		String relatednameCache = "";
66
		String relatedCitation = "";
67

    
68
		Iterator it = relationsFromThisName.iterator();
69

    
70
		while(it.hasNext()) {
71
			typeString = "";
72
			relatednameCache = "";
73
			relatedCitation = "";
74

    
75
			NameRelationship nr = (NameRelationship)it.next();
76
			if(nr.getType() != null) {
77
				typeString = nr.getType()
78
				        .getRepresentation(Language.DEFAULT())
79
                        .getLabel();
80
			}
81
			TaxonName tnbRelatedTo = nr.getToName();
82
			if(tnbRelatedTo != null) {
83
			    System.out.println("tnbRelatedTo not null");
84
				relatednameCache = tnbRelatedTo.getTitleCache();
85
				Reference ref = (Reference) tnbRelatedTo.getNomenclaturalReference();
86
				if(ref !=null) {
87
				    relatedCitation = ref.getTitleCache();
88
				}
89
			}
90
			response.addNameRelationships(typeString,
91
					relatednameCache,
92
					relatedCitation);
93
		}
94
		// set name to relationship
95
		it = relationsToThisName.iterator();
96

    
97
		while(it.hasNext()) {
98
			typeString = "";
99
			relatednameCache = "";
100
			relatedCitation = "";
101

    
102
			NameRelationship nr = (NameRelationship)it.next();
103
			if(nr.getType() != null) {
104
				typeString = nr.getType()
105
				        .getInverseRepresentation(Language.DEFAULT())
106
                        .getLabel();
107
			}
108

    
109
			TaxonName tnbRelatedFrom = nr.getFromName();
110
			if(tnbRelatedFrom != null) {
111
			    System.out.println("tnbRelatedTo not null");
112
				relatednameCache = tnbRelatedFrom.getTitleCache();
113
				Reference ref = (Reference) tnbRelatedFrom.getNomenclaturalReference();
114
				if(ref !=null) {
115
				    relatedCitation = ref.getTitleCache();
116
				}
117
			}
118
			response.addNameRelationships(typeString,
119
					relatednameCache,
120
					relatedCitation);
121
		}
122

    
123
	}
124

    
125
	public void addToResponseTaxonInfo(Set<TaxonBase> taxonBases) {
126
		Iterator it = taxonBases.iterator();
127
		while(it.hasNext()) {
128
			TaxonBase tb = (TaxonBase)it.next();
129
			response.addToTaxonUuids(tb.getUuid().toString());
130
			if(tb.isInstanceOf(Taxon.class) && tb.getLsid() != null) {
131
				response.addToTaxonLsids(tb.getLsid().toString());
132
			}
133

    
134
		}
135
	}
136

    
137

    
138
	public NameInformation.NameInformationResponse getResponse() {
139
		return response;
140
	}
141

    
142
	public NameInformation.NameInformationRequest getRequest() {
143
		return this.request;
144
	}
145

    
146
	public class NameInformationRequest {
147
		private String nameUuid;
148

    
149
		public NameInformationRequest() {
150
			this.nameUuid = "";
151
		}
152

    
153
		public void setNameUuid(String nameUuid) {
154
			this.nameUuid = nameUuid;
155
		}
156

    
157
		public String getNameUuid() {
158
			return this.nameUuid;
159
		}
160

    
161

    
162
	}
163

    
164
	public class NameInformationResponse {
165
		private String title;
166
		private String name;
167
		private String rank;
168
		private List<String> nomenclatureStatus;
169
		private String citation;
170
		private List<NameInformation.NameInformationResponse.NameRelationshipInfo> nameRelationships;
171
		private Set<String> taxonUuids;
172
		private Set<String> taxonLsids;
173

    
174

    
175
		public NameInformationResponse() {
176
			title = "";
177
			name = "";
178
			rank = "";
179
			nomenclatureStatus = new ArrayList<String>();
180
			citation = "";
181
			nameRelationships = new ArrayList<NameInformation.NameInformationResponse.NameRelationshipInfo>();
182
			taxonUuids = new HashSet<String>();
183
			taxonLsids = new HashSet<String>();
184

    
185
		}
186

    
187
		public void setTitle(String title) {
188
			this.title = title;
189
		}
190

    
191
		public String getTitle() {
192
			return this.title;
193
		}
194

    
195
		public void setName(String name) {
196
			this.name = name;
197
		}
198

    
199
		public String getName() {
200
			return this.name;
201
		}
202

    
203
		public void setRank(String rank) {
204
			this.rank = rank;
205
		}
206

    
207
		public String getRank() {
208
			return this.rank;
209
		}
210

    
211
		public void addToNomenclatureStaus(String nomenclatureStatus) {
212
			this.nomenclatureStatus.add(nomenclatureStatus);
213
		}
214

    
215
		public List<String> getNomenclatureStatus() {
216
			return this.nomenclatureStatus;
217
		}
218

    
219
		public void setCitation(String citation) {
220
			this.citation = citation;
221
		}
222

    
223
		public String getCitation() {
224
			return this.citation;
225
		}
226

    
227
		public void addNameRelationships(String type, String relatedName, String citation) {
228
			NameInformation.NameInformationResponse.NameRelationshipInfo nr =
229
					new NameInformation.NameInformationResponse.NameRelationshipInfo();
230
			nr.setRelationInfo(type, relatedName, citation);
231
			nameRelationships.add(nr);
232
		}
233

    
234
		public List<NameInformation.NameInformationResponse.NameRelationshipInfo> getNameRelationships() {
235
			return nameRelationships;
236
		}
237

    
238
		public void addToTaxonUuids(String taxonUuid) {
239
			taxonUuids.add(taxonUuid);
240
		}
241

    
242
		public Set<String> getTaxonUuids() {
243
			return this.taxonUuids;
244
		}
245

    
246
		public void addToTaxonLsids(String lsid) {
247
			taxonLsids.add(lsid);
248
		}
249

    
250
		public Set<String> getTaxonLsids() {
251
			return this.taxonLsids;
252
		}
253

    
254
		public class NameRelationshipInfo {
255
			private String type;
256
			private String relatedName;
257
			private String citation;
258

    
259

    
260

    
261
			public NameRelationshipInfo() {
262

    
263
			}
264

    
265
			public void setRelationInfo(String type, String relatedName, String citation) {
266
				this.type = type;
267
				this.relatedName = relatedName;
268
				this.citation = citation;
269
			}
270

    
271
			public String getType() {
272
				return this.type;
273
			}
274

    
275
			public String getRelatedName() {
276
				return this.relatedName;
277
			}
278

    
279
			public String getCitation() {
280
				return this.citation;
281
			}
282

    
283

    
284
		}
285
	}
286
}
(2-2/4)