Project

General

Profile

« Previous | Next » 

Revision f1a25720

Added by Katja Luther over 6 years ago

  • ID f1a25720755daa96e8838a617a660dfced7b9f31
  • Parent 23e50194

first implementation for change from joda time to java8 time

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/csv/redlist/out/CsvRecordBaseRedlist.java
1 1
/**
2 2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
11 11
import java.io.PrintWriter;
12 12
import java.net.URI;
13 13
import java.net.URISyntaxException;
14
import java.time.ZonedDateTime;
15
import java.time.temporal.Temporal;
14 16
import java.util.ArrayList;
15 17
import java.util.HashMap;
16 18
import java.util.HashSet;
......
20 22

  
21 23
import org.apache.commons.lang.StringUtils;
22 24
import org.apache.log4j.Logger;
23
import org.joda.time.DateTime;
24
import org.joda.time.Partial;
25 25

  
26 26
import eu.etaxonomy.cdm.common.CdmUtils;
27 27
import eu.etaxonomy.cdm.io.dwca.TermUri;
......
61 61
	protected static final boolean IS_FIRST = false;
62 62
	protected static final boolean IS_NOT_FIRST = true;
63 63
//	protected static final String SEP = ",";
64
	
64

  
65 65
	protected Map<String, URI> knownFields = new HashMap<String, URI>();
66 66
	protected Set<TermUri> knownTermFields = new HashSet<TermUri>();
67
	
67

  
68 68
	public abstract void write(PrintWriter writer);
69 69
	protected abstract void registerKnownFields();
70
	
70

  
71 71
	protected int count;
72 72
	private CsvMetaDataRecordRedlist metaDataRecord;
73 73
	protected CsvTaxExportConfiguratorRedlist config;
......
75 75
	private Integer id;
76 76
	private UUID uuid;
77 77

  
78
	
78

  
79 79
	protected CsvRecordBaseRedlist(CsvMetaDataRecordRedlist metaDataRecord, CsvTaxExportConfiguratorRedlist config){
80 80
		this.metaDataRecord = metaDataRecord;
81 81
		this.count = metaDataRecord.inc();
82 82
		this.config = config;
83 83
	}
84
	
85
	
84

  
85

  
86 86
	public void setId(Integer id) {
87 87
		this.id = id;
88 88
	}
......
107 107
		String value = null;
108 108
		print(value, writer, addSeparator, fieldKey);
109 109
	}
110
	
110

  
111 111
//	protected void print(Object object, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
112 112
//		print(object == null ? null : object.toString(), writer, addSeparator, fieldKey);
113 113
//	}
......
124 124
		print(agent == null ? null : getAgent(agent), writer, addSeparator, fieldKey);
125 125
	}
126 126

  
127
	
127

  
128 128
	protected void print(Language language, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
129 129
		print(language, writer, addSeparator, fieldKey.getUriString());
130 130
	}
......
137 137
	protected void print(LSID lsid, PrintWriter writer, boolean addSeparator, String fieldKey) {
138 138
		print(lsid == null ? null : String.valueOf(lsid.toString()), writer, addSeparator, fieldKey);
139 139
	}
140
	
140

  
141 141
	protected void print(Set<Rights> rights, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
142 142
		print(rights, writer, addSeparator, fieldKey.getUriString());
143 143
	}
......
151 151
	protected void print(URI uri, PrintWriter writer, boolean addSeparator, String fieldKey) {
152 152
		print(uri == null ? null : String.valueOf(uri), writer, addSeparator, fieldKey);
153 153
	}
154
	
154

  
155 155
	protected void print(Point point, PrintWriter writer, boolean addSeparator, TermUri latitudeKey, TermUri longitudeKey) {
156 156
		print(point, writer, addSeparator, latitudeKey.getUriString(), longitudeKey.getUriString());
157 157
	}
158
	
158

  
159 159
	protected void print(Point point, PrintWriter writer, boolean addSeparator, String latitudeKey, String longitudeKey) {
160 160
		if (point == null){
161 161
			String toPrint = null;
......
170 170
	}
171 171
	protected void print(Boolean boolValue, PrintWriter writer, boolean addSeparator, TermUri fieldKey) {
172 172
		print(boolValue, writer, addSeparator, fieldKey.getUriString());
173
	}	
173
	}
174 174
	protected void print(Boolean boolValue, PrintWriter writer, boolean addSeparator, String fieldKey) {
175 175
		print(boolValue == null ? null : String.valueOf(boolValue), writer, addSeparator, fieldKey);
176 176
	}
......
181 181
	protected void print(Integer intValue, PrintWriter writer, boolean addSeparator, String fieldKey) {
182 182
		print(intValue == null ? null : String.valueOf(intValue), writer, addSeparator, fieldKey);
183 183
	}
184
	
184

  
185 185
	protected void printId(Integer intValue, PrintWriter writer, boolean addSeparator, String fieldKey) {
186 186
		print(intValue == null ? null : String.valueOf(intValue), writer, addSeparator, fieldKey);
187 187
	}
......
196 196
	protected void print(String value, PrintWriter writer, boolean addSeparator, TermUri fieldKey, String defaultValue) {
197 197
		print(value, writer, addSeparator, fieldKey.getUriString(), defaultValue);
198 198
	}
199
	
199

  
200 200
	protected void print(String value, PrintWriter writer, boolean addSeparator, String fieldKey) {
201 201
		print(value, writer, addSeparator, fieldKey, null);
202 202
	}
203
	
203

  
204 204
	protected void print(String value, PrintWriter writer, boolean addSeparator, String fieldKey, String defaultValue) {
205 205
		if (count == 1 && addSeparator == IS_NOT_FIRST){
206 206
			registerFieldKey(URI.create(fieldKey), defaultValue);
......
210 210
			if (StringUtils.isNotBlank(value)){
211 211
				//Replace quotes by double quotes
212 212
				value = value.replace("\"", "\"\"");
213
				
213

  
214 214
				value = value.replace(config.getLinesTerminatedBy(), "\\r");
215
				
215

  
216 216
				//replace all line brakes according to best practices: http://code.google.com/p/gbif-ecat/wiki/BestPractices
217 217
				value = value.replace("\r\n", "\\r");
218 218
				value = value.replace("\r", "\\r");
219 219
				value = value.replace("\n", "\\r");
220
				
220

  
221 221
				strToPrint += config.getFieldsEnclosedBy() + value + config.getFieldsEnclosedBy();
222 222
			}
223 223
			writer.print(strToPrint);
224 224
		}
225 225
	}
226
	
226

  
227 227
	/**
228 228
	 * @param writer
229 229
	 * @param list
......
245 245
	 * @param list
246 246
	 * @param termUri
247 247
	 * @param writer
248
	 * 
248
	 *
249 249
	 * Method for concatenating strings, especially for the red list use case
250 250
	 */
251 251
	protected void print(ArrayList<String> list, TermUri termUri, PrintWriter writer){
......
266 266
					print(element, writer, IS_FIRST, termUri);
267 267
					writer.write(",");
268 268
					logger.info(element);
269
					
269

  
270 270
				}
271 271
			}
272 272
		}
273 273
	}
274
	
275
	
274

  
275

  
276 276
	private void registerFieldKey(URI key, String defaultValue) {
277 277
		this.metaDataRecord.addFieldEntry(key, defaultValue);
278 278
	}
279 279

  
280
	
280

  
281 281
	protected String getRights(Rights rights) {
282 282
		if (rights == null){
283 283
			return "";
......
296 296
		}
297 297
	}
298 298

  
299
	protected String getDate(DateTime date) {
299
	protected String getDate(ZonedDateTime date) {
300 300
		if (date == null){
301 301
			return "";
302 302
		}else{
......
339 339
			return result;
340 340
		}
341 341
	}
342
	
342

  
343 343
	protected String getSex(DefinedTerm sex) {
344 344
		String result = CsvTaxExportTransformerRedlist.transformToGbifSex(sex);
345 345
		if (result == null){
......
352 352
			return result;
353 353
		}
354 354
	}
355
	
355

  
356 356
	protected String getLifeStage(DefinedTerm stage) {
357 357
		String result = CsvTaxExportTransformerRedlist.transformToGbifLifeStage(stage);
358 358
		if (result == null){
......
378 378
			return result;
379 379
		}
380 380
	}
381
	
381

  
382 382
	protected String getEstablishmentMeans(PresenceAbsenceTerm status) {
383 383
		String result = CsvTaxExportTransformerRedlist.transformToGbifEstablishmentMeans(status);
384 384
		if (result == null){
......
392 392
		}
393 393
	}
394 394

  
395
	
396
	
395

  
396

  
397 397
	protected String getAgent(AgentBase<?> agent) {
398 398
		if (agent == null){
399 399
			return "";
......
402 402
			return agent.getTitleCache();
403 403
		}
404 404
	}
405
	
405

  
406 406

  
407 407
	protected String getFeature(Feature feature) {
408 408
		if (feature == null){
......
413 413
		}
414 414
	}
415 415

  
416
	
416

  
417 417
	protected String getTimePeriod(TimePeriod period) {
418 418
		if (period == null){
419 419
			return "";
......
422 422
			return period.toString();
423 423
		}
424 424
	}
425
	
425

  
426 426
	protected String getTimePeriodPart(TimePeriod period, boolean useEnd) {
427 427
		if (period == null){
428 428
			return "";
429 429
		}else{
430
			Partial date = useEnd? period.getEnd(): period.getStart();
430
			Temporal date = useEnd? period.getEnd(): period.getStart();
431 431
			if (date == null){
432 432
				return "";
433 433
			}else{
......
451 451
			return result;
452 452
		}
453 453
	}
454
	
454

  
455 455

  
456 456
	protected String getDesignationType(TypeDesignationStatusBase<?> status) {
457 457
		if (status == null){
......
471 471
			return result;
472 472
		}
473 473
	}
474
	
475
	
474

  
475

  
476 476
	protected void addKnownField(String string, String uri) throws URISyntaxException {
477 477
		this.knownFields.put(string, new URI(uri));
478 478
	}
479
	
479

  
480 480
	protected void addKnownField(TermUri term) throws URISyntaxException {
481 481
		this.knownTermFields.add(term);
482 482
	}

Also available in: Unified diff