cleanup
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / csv / redlist / demo / CsvDemoRecord.java
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.csv.redlist.demo;
10
11 import java.io.PrintWriter;
12 import java.net.URISyntaxException;
13 import java.util.ArrayList;
14 import java.util.List;
15
16 import org.apache.log4j.Logger;
17
18 import com.fasterxml.jackson.annotation.JsonIgnore;
19
20 import eu.etaxonomy.cdm.io.stream.terms.TermUri;
21 import eu.etaxonomy.cdm.model.description.Feature;
22 import eu.etaxonomy.cdm.model.taxon.Classification;
23
24 /**
25 * @author a.oppermann
26 * @since 18.10.2012
27 *
28 */
29 public class CsvDemoRecord extends CsvDemoRecordBase{
30
31 @SuppressWarnings("unused")
32 private static final Logger logger = Logger.getLogger(CsvDemoRecord.class);
33
34 private String scientificNameId;
35 private String scientificName;
36 private String taxonomicStatus;
37 private final CsvDemoId datasetId;
38 private String taxonConceptID;
39 private String datasetName;
40 private ArrayList<String> synonyms;
41 private String threadStatus;
42 private ArrayList<String> countryCodes;
43 private ArrayList<String> headlines;
44 private Boolean isHeadLinePrinted;
45 private List<Feature> features;
46 private List<List<String>> featuresCells;
47 private final CsvDemoExportConfigurator config;
48 private String authorshipCache;
49 private String rank;
50 private String parentUuid;
51 private String lastUpdated;
52 private String externalID;
53
54 /**
55 *
56 * @param metaDataRecord
57 * @param config
58 */
59 public CsvDemoRecord(CsvDemoMetaDataRecord metaDataRecord, CsvDemoExportConfigurator config){
60 super(metaDataRecord, config);
61 this.config = config;
62 datasetId = new CsvDemoId(config);
63 }
64
65 @Override
66 protected void registerKnownFields(){
67 try {
68 addKnownField(TermUri.DWC_SCIENTIFIC_NAME);
69 addKnownField(TermUri.DWC_TAXONOMIC_STATUS);
70 addKnownField(TermUri.DWC_DATASET_NAME);
71 addKnownField("countryCode", "http://rs.tdwg.org/dwc/terms/countryCode");
72 } catch (URISyntaxException e) {
73 throw new RuntimeException(e);
74 }
75 }
76
77 @Override
78 public void write(PrintWriter writer) {
79 if(isHeadLinePrinted() != null && isHeadLinePrinted() == true){
80 printHeadline(writer, setHeadlines(), TermUri.DWC_DATASET_NAME);
81 isHeadLinePrinted=false;
82 }
83 if(config.isClassification()){
84 print(datasetName, writer, IS_FIRST, TermUri.DWC_DATASET_NAME);
85 }
86 if(config.isDoTaxonConceptExport()){
87 if(config.isTaxonName()){
88 print(scientificName, writer, IS_FIRST, TermUri.DWC_SCIENTIFIC_NAME);
89 }
90 }else{
91 if(config.isTaxonName()){
92 print(scientificName, writer, IS_NOT_FIRST, TermUri.DWC_SCIENTIFIC_NAME);
93 }
94 }
95 if(config.isTaxonNameID()){
96 print(scientificNameId, writer, IS_NOT_FIRST, TermUri.DWC_DATASET_ID);
97 }
98 if(config.isAuthor()){
99 print(authorshipCache, writer, IS_NOT_FIRST, TermUri.DC_CREATOR);
100 }
101 if(config.isRank()){
102 print(rank, writer, IS_NOT_FIRST, TermUri.DWC_TAXON_RANK);
103 }
104 if(config.isTaxonConceptID()){
105 print(taxonConceptID, writer, IS_NOT_FIRST, TermUri.DWC_TAXON_CONCEPT_ID);
106 }
107 if(config.isTaxonStatus()){
108 print(taxonomicStatus, writer, IS_NOT_FIRST, TermUri.DWC_TAXONOMIC_STATUS);
109 }
110 if(config.isAcceptedName()){
111 //TODO print accepted Name
112 }
113 if(config.isParentID()){
114 print(parentUuid, writer, IS_NOT_FIRST, TermUri.DWC_PARENT_NAME_USAGE_ID);
115 }
116 if(config.isSynonyms()){
117 print(synonyms, TermUri.DWC_SCIENTIFIC_NAME, writer);
118 }
119 if(config.isDistributions()){
120 print(countryCodes, TermUri.DWC_COUNTRY_CODE, writer);
121 }
122 if(config.isRedlistFeatures()){
123 if(features != null ||featuresCells != null || !featuresCells.isEmpty()){
124 for(List<String> featureList : featuresCells) {
125 print((ArrayList<String>)featureList, TermUri.DWC_LIFESTAGE, writer);
126 }
127 }
128 }
129 if(config.isExternalID()){
130 print(externalID, writer, IS_NOT_FIRST,TermUri.DWC_ORIGINAL_NAME_USAGE_ID);
131 }
132 if(config.isLastChange()){
133 print(lastUpdated, writer, IS_NOT_FIRST,TermUri.DC_MODIFIED);
134 }
135 writer.println();
136 }
137
138
139 //--------------Getter-Setter-Methods------------------//
140
141 /* public String getDatasetName() {
142 return datasetName;
143 }*/
144 public void setDatasetName(String datasetName) {
145 this.datasetName = datasetName;
146 }
147 public String getScientificName() {
148 return scientificName;
149 }
150 public void setScientificName(String scientificName) {
151 this.scientificName = scientificName;
152 }
153 /* public String getTaxonomicStatus() {
154 return taxonomicStatus;
155 }*/
156 public void setTaxonomicStatus(String taxonomicStatus) {
157 this.taxonomicStatus = taxonomicStatus;
158 }
159 /* public String getDatasetId() {
160 return datasetId.getId();
161 }*/
162 public void setDatasetId(Classification classification) {
163 this.datasetId.setId(classification);
164 }
165 public void setSynonyms(ArrayList<String> synonyms){
166 this.synonyms = synonyms;
167 }
168 /* public ArrayList<String> getSynonyms(){
169 return synonyms;
170 }*/
171 /* public String getThreadStatus() {
172 return threadStatus;
173 }*/
174 public void setThreadStatus(String threadStatus) {
175 this.threadStatus = threadStatus;
176 }
177
178 public void setCountryCode(ArrayList<String> countryCodes) {
179 this.countryCodes = countryCodes;
180 }
181
182 //FIXME: hard coded header lines
183 private ArrayList<String> setHeadlines(){
184 // if(config.isDoDemoExport()){
185 headlines = new ArrayList<>();
186
187 if(config.isClassification()){
188 headlines.add("Classification");
189 }
190 if(config.isTaxonName()){
191 headlines.add("Wissenschaftlicher Name");
192 }
193 if(config.isTaxonNameID()){
194 headlines.add("Taxon ID");
195 }
196 if(config.isAuthor()){
197 headlines.add("Autor");
198 }
199 if(config.isRank()){
200 headlines.add("Rang");
201 }
202 if(config.isTaxonStatus()){
203 headlines.add("Taxon Status");
204 }
205 if(config.isAcceptedName()){
206 headlines.add("Akzeptierter Name");
207 }
208 if(config.isTaxonConceptID()){
209 headlines.add("Taxon Konzept ID");
210 }
211 if(config.isParentID()){
212 headlines.add("Parent ID");
213 }
214 if(config.isSynonyms()){
215 headlines.add("Synonym");
216 }
217 if(config.isDistributions()){
218 headlines.add("Distribution");
219 }
220 if(features != null){
221 if(!features.isEmpty()){
222 for(Feature f : features) {
223 headlines.add(f.getLabel());
224 }
225 }
226 }
227 if(config.isExternalID()){
228 headlines.add("External ID");
229 }
230 if(config.isLastChange()){
231 headlines.add("Letztes Update");
232 }
233 // }else if(config.isDoTaxonConceptExport()){
234 // headlines = new ArrayList<String>();
235 // Collections.addAll(headlines, "Taxon Name UUID","Taxon Name","Author","Rank","Taxon Status","Accepted Name", "Taxon Concept ID", "Parent ID", "Last Change");
236 // }
237 return headlines;
238 }
239 @JsonIgnore
240 public Boolean isHeadLinePrinted() {
241 return isHeadLinePrinted;
242 }
243
244 public void setHeadLinePrinted(Boolean isHeadLinePrinted) {
245 this.isHeadLinePrinted = isHeadLinePrinted;
246 }
247
248 public void setScientificNameId(String scientificNameId) {
249 this.scientificNameId = scientificNameId;
250 }
251
252 public void setPrintFeatures(List<Feature> features) {
253 this.features = features;
254
255 }
256
257 public void setFeatures(List<List<String>> featureCells) {
258 this.featuresCells = featureCells;
259
260 }
261
262 public void setAuthorName(String authorshipCache) {
263 this.authorshipCache = authorshipCache;
264 }
265
266 public void setRank(String rank) {
267 this.rank = rank;
268 }
269
270 public void setParentUUID(String parentUuid) {
271 this.parentUuid = parentUuid;
272
273 }
274
275 public void setLastChange(String lastUpdated) {
276 this.lastUpdated = lastUpdated;
277 }
278
279 public void setTaxonConceptID(String taxonConceptID) {
280 this.taxonConceptID = taxonConceptID;
281 }
282
283 public void setExternalID(String externalID) {
284 this.externalID = externalID;
285 }
286 /**
287 * @return the scientificNameId
288 */
289 /* public String getScientificNameId() {
290 return scientificNameId;
291 }*/
292
293 /**
294 * @return the taxonConceptID
295 */
296 public String getTaxonConceptID() {
297 return taxonConceptID;
298 }
299 /*
300 public ArrayList<String> getCountryCodes() {
301 return countryCodes;
302 }
303 */
304 /**
305 * @return the authorshipCache
306 */
307 public String getAuthor() {
308 return authorshipCache;
309 }
310
311 /**
312 * @return the rank
313 */
314 public String getRank() {
315 return rank;
316 }
317
318 /**
319 * @return the parentUuid
320 */
321 public String getParentUuid() {
322 return parentUuid;
323 }
324
325 /**
326 * @return the lastUpdated
327 */
328 public String getLastUpdated() {
329 return lastUpdated;
330 }
331
332 /**
333 * @return the externalID
334 */
335 public String getExternalID() {
336 return externalID;
337 }
338
339 }