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
|
package eu.etaxonomy.cdm.io.dwca.out;
|
10
|
|
11
|
import java.io.PrintWriter;
|
12
|
import java.net.URISyntaxException;
|
13
|
|
14
|
import org.apache.commons.lang.StringUtils;
|
15
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.io.stream.terms.TermUri;
|
18
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
19
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
20
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
21
|
import eu.etaxonomy.cdm.model.location.Country;
|
22
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
23
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
24
|
|
25
|
/**
|
26
|
* @author a.mueller
|
27
|
* @since 20.04.2011
|
28
|
*
|
29
|
*/
|
30
|
public class DwcaDistributionRecord extends DwcaRecordBase implements IDwcaAreaRecord{
|
31
|
@SuppressWarnings("unused")
|
32
|
private static final Logger logger = LogManager.getLogger(DwcaDistributionRecord.class);
|
33
|
|
34
|
private DwcaId locationId;
|
35
|
private String locationIdString;
|
36
|
private String locality;
|
37
|
private String countryCode;
|
38
|
private DefinedTerm lifeStage;
|
39
|
private PresenceAbsenceTerm occurrenceStatus;
|
40
|
private String threadStatus;
|
41
|
|
42
|
private PresenceAbsenceTerm establishmentMeans;
|
43
|
private String appendixCITES;
|
44
|
private TimePeriod eventDate;
|
45
|
|
46
|
private TimePeriod seasonalDate; //startDayOfYear and endDayOfYear
|
47
|
private String source;
|
48
|
private String occurrenceRemarks;
|
49
|
|
50
|
|
51
|
public DwcaDistributionRecord(DwcaMetaDataRecord metaDataRecord, DwcaTaxExportConfigurator config){
|
52
|
super(metaDataRecord, config);
|
53
|
locationId = new DwcaId(config);
|
54
|
}
|
55
|
|
56
|
|
57
|
@Override
|
58
|
protected void registerKnownFields(){
|
59
|
try {
|
60
|
addKnownField(TermUri.DWC_LOCATION_ID);
|
61
|
addKnownField(TermUri.DWC_LOCALITY);
|
62
|
addKnownField(TermUri.DWC_COUNTRY_CODE);
|
63
|
addKnownField(TermUri.DWC_LIFESTAGE);
|
64
|
addKnownField(TermUri.IUCN_THREAD_STATUS);
|
65
|
|
66
|
addKnownField(TermUri.DWC_OCCURRENCE_STATUS);
|
67
|
addKnownField(TermUri.DWC_ESTABLISHMENT_MEANS);
|
68
|
addKnownField(TermUri.GBIF_APPENDIX_CITES);
|
69
|
addKnownField(TermUri.DWC_EVENT_DATE);
|
70
|
addKnownField(TermUri.DWC_START_DAY_OF_YEAR);
|
71
|
addKnownField(TermUri.DC_SOURCE);
|
72
|
addKnownField(TermUri.DWC_OCCURRENCE_REMARKS);
|
73
|
} catch (URISyntaxException e) {
|
74
|
throw new RuntimeException(e);
|
75
|
}
|
76
|
}
|
77
|
|
78
|
// @Override
|
79
|
// public List<String> getHeaderList() {
|
80
|
// String[] result = new String[]{"coreid",
|
81
|
// "locationId",
|
82
|
// "locality",
|
83
|
// "countryCode",
|
84
|
// "lifeStage",
|
85
|
// "occurrenceStatus",
|
86
|
// "threadStatus",
|
87
|
// "establishmentMeans",
|
88
|
// "appendixCITES",
|
89
|
// "eventDate",
|
90
|
// "startDayOfYear",
|
91
|
// "endDayOfYear",
|
92
|
// "source",
|
93
|
// "occurrenceRemarks"};
|
94
|
// return Arrays.asList(result);
|
95
|
// }
|
96
|
|
97
|
@Override
|
98
|
public void writeCsv(DwcaTaxExportState state) {
|
99
|
try {
|
100
|
DwcaTaxExportFile table = DwcaTaxExportFile.DISTRIBUTION;
|
101
|
String[] csvLine = new String[table.getSize()];
|
102
|
|
103
|
//
|
104
|
line(state, csvLine, table, TermUri.DC_IDENTIFIER, getUuid());
|
105
|
if (StringUtils.isNotBlank(locationIdString)){
|
106
|
line(state, csvLine, table, TermUri.DWC_LOCATION_ID, locationIdString);
|
107
|
}else{
|
108
|
line(state, csvLine, table, TermUri.DWC_LOCATION_ID, locationId);
|
109
|
}
|
110
|
line(state, csvLine, table, TermUri.DWC_LOCALITY, locality);
|
111
|
line(state, csvLine, table, TermUri.DWC_COUNTRY_CODE, countryCode);
|
112
|
line(state, csvLine, table, TermUri.DWC_LIFESTAGE, getLifeStage(lifeStage));
|
113
|
line(state, csvLine, table, TermUri.IUCN_THREAD_STATUS, getOccurrenceStatus(occurrenceStatus));
|
114
|
line(state, csvLine, table, TermUri.DWC_OCCURRENCE_STATUS, threadStatus);
|
115
|
line(state, csvLine, table, TermUri.DWC_ESTABLISHMENT_MEANS, getEstablishmentMeans(establishmentMeans));
|
116
|
line(state, csvLine, table, TermUri.GBIF_APPENDIX_CITES, appendixCITES);
|
117
|
line(state, csvLine, table, TermUri.DWC_EVENT_DATE, getTimePeriod(eventDate));
|
118
|
line(state, csvLine, table, TermUri.DWC_START_DAY_OF_YEAR, getTimePeriodPart(seasonalDate, false));
|
119
|
line(state, csvLine, table, TermUri.DWC_END_DAY_OF_YEAR, getTimePeriodPart(seasonalDate, true));
|
120
|
line(state, csvLine, table, TermUri.DC_SOURCE, source);
|
121
|
line(state, csvLine, table, TermUri.DWC_OCCURRENCE_REMARKS, occurrenceRemarks);
|
122
|
|
123
|
state.getProcessor().put(table, getId().toString(), csvLine);
|
124
|
} catch (Exception e) {
|
125
|
String message = "Unhandled exception when writing distribution record: " + e.getMessage();
|
126
|
state.getResult().addException(e, message);
|
127
|
}
|
128
|
|
129
|
}
|
130
|
|
131
|
@Override
|
132
|
protected void doWrite(DwcaTaxExportState state, PrintWriter writer) {
|
133
|
|
134
|
printId(getUuid(), writer, IS_FIRST, "coreid");
|
135
|
if (StringUtils.isNotBlank(locationIdString)){
|
136
|
print(locationIdString, writer, IS_NOT_FIRST, TermUri.DWC_LOCATION_ID);
|
137
|
}else{
|
138
|
print(locationId, writer, IS_NOT_FIRST, TermUri.DWC_LOCATION_ID);
|
139
|
}
|
140
|
print(locality, writer, IS_NOT_FIRST, TermUri.DWC_LOCALITY);
|
141
|
print(countryCode, writer, IS_NOT_FIRST, TermUri.DWC_COUNTRY_CODE);
|
142
|
print(getLifeStage(lifeStage), writer, IS_NOT_FIRST, TermUri.DWC_LIFESTAGE);
|
143
|
print(getOccurrenceStatus(occurrenceStatus), writer, IS_NOT_FIRST, TermUri.DWC_OCCURRENCE_STATUS);
|
144
|
print(threadStatus, writer, IS_NOT_FIRST, TermUri.IUCN_THREAD_STATUS);
|
145
|
print(getEstablishmentMeans(establishmentMeans), writer, IS_NOT_FIRST, TermUri.DWC_ESTABLISHMENT_MEANS);
|
146
|
print(appendixCITES, writer, IS_NOT_FIRST, TermUri.GBIF_APPENDIX_CITES);
|
147
|
print(getTimePeriod(eventDate),writer, IS_NOT_FIRST, TermUri.DWC_EVENT_DATE);
|
148
|
print(getTimePeriodPart(seasonalDate, false),writer, IS_NOT_FIRST, TermUri.DWC_START_DAY_OF_YEAR);
|
149
|
//TODO
|
150
|
print(getTimePeriodPart(seasonalDate, true),writer, IS_NOT_FIRST, TermUri.DWC_END_DAY_OF_YEAR);
|
151
|
print(source, writer, IS_NOT_FIRST, TermUri.DC_SOURCE);
|
152
|
print(occurrenceRemarks, writer, IS_NOT_FIRST, TermUri.DWC_OCCURRENCE_REMARKS);
|
153
|
writer.println();
|
154
|
}
|
155
|
|
156
|
|
157
|
public String getSource() {
|
158
|
return source;
|
159
|
}
|
160
|
public void setSource(String source) {
|
161
|
this.source = source;
|
162
|
}
|
163
|
|
164
|
public String getLocality() {
|
165
|
return locality;
|
166
|
}
|
167
|
|
168
|
|
169
|
@Override
|
170
|
public void setLocality(String locality) {
|
171
|
this.locality = locality;
|
172
|
}
|
173
|
|
174
|
|
175
|
public String getCountryCode() {
|
176
|
return countryCode;
|
177
|
}
|
178
|
|
179
|
|
180
|
@Override
|
181
|
public void setCountryCode(String countryCode) {
|
182
|
this.countryCode = countryCode;
|
183
|
}
|
184
|
|
185
|
|
186
|
public DefinedTerm getLifeStage() {
|
187
|
return lifeStage;
|
188
|
}
|
189
|
|
190
|
|
191
|
public void setLifeStage(DefinedTerm lifeStage) {
|
192
|
this.lifeStage = lifeStage;
|
193
|
}
|
194
|
|
195
|
|
196
|
public String getLocationId() {
|
197
|
return locationId.getId();
|
198
|
}
|
199
|
|
200
|
@Override
|
201
|
public void setLocationId(NamedArea area) {
|
202
|
if (area.getVocabulary().getUuid().equals(NamedArea.uuidTdwgAreaVocabulary)){
|
203
|
String locationId = "TDWG:" + area.getIdInVocabulary();
|
204
|
this.locationIdString = locationId;
|
205
|
}else if (area.isInstanceOf(Country.class)){
|
206
|
Country country = CdmBase.deproxy(area, Country.class);
|
207
|
String locationId = "ISO3166:" + country.getIso3166_A2();
|
208
|
this.locationIdString = locationId;
|
209
|
}else{
|
210
|
this.locationId.setId(area);
|
211
|
}
|
212
|
}
|
213
|
|
214
|
public PresenceAbsenceTerm getOccurrenceStatus() {
|
215
|
return occurrenceStatus;
|
216
|
}
|
217
|
|
218
|
|
219
|
public void setOccurrenceStatus(PresenceAbsenceTerm occurrenceStatus) {
|
220
|
this.occurrenceStatus = occurrenceStatus;
|
221
|
}
|
222
|
|
223
|
|
224
|
public String getThreadStatus() {
|
225
|
return threadStatus;
|
226
|
}
|
227
|
|
228
|
|
229
|
public void setThreadStatus(String threadStatus) {
|
230
|
this.threadStatus = threadStatus;
|
231
|
}
|
232
|
|
233
|
|
234
|
public PresenceAbsenceTerm getEstablishmentMeans() {
|
235
|
return establishmentMeans;
|
236
|
}
|
237
|
|
238
|
|
239
|
public void setEstablishmentMeans(PresenceAbsenceTerm establishmentMeans) {
|
240
|
this.establishmentMeans = establishmentMeans;
|
241
|
}
|
242
|
|
243
|
|
244
|
public String getAppendixCITES() {
|
245
|
return appendixCITES;
|
246
|
}
|
247
|
|
248
|
|
249
|
public void setAppendixCITES(String appendixCITES) {
|
250
|
this.appendixCITES = appendixCITES;
|
251
|
}
|
252
|
|
253
|
|
254
|
public TimePeriod getEventDate() {
|
255
|
return eventDate;
|
256
|
}
|
257
|
|
258
|
|
259
|
public void setEventDate(TimePeriod eventDate) {
|
260
|
this.eventDate = eventDate;
|
261
|
}
|
262
|
|
263
|
|
264
|
public TimePeriod getSeasonalDate() {
|
265
|
return seasonalDate;
|
266
|
}
|
267
|
|
268
|
|
269
|
public void setSeasonalDate(TimePeriod seasonalDate) {
|
270
|
this.seasonalDate = seasonalDate;
|
271
|
}
|
272
|
|
273
|
|
274
|
public String getOccurrenceRemarks() {
|
275
|
return occurrenceRemarks;
|
276
|
}
|
277
|
|
278
|
|
279
|
public void setOccurrenceRemarks(String occurrenceRemarks) {
|
280
|
this.occurrenceRemarks = occurrenceRemarks;
|
281
|
}
|
282
|
|
283
|
|
284
|
}
|