Project

General

Profile

« Previous | Next » 

Revision 35d4750f

Added by Andreas Müller almost 13 years ago

started with DwcaReferenceExport

View differences:

.gitattributes
253 253
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaDistributionExport.java -text
254 254
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaDistributionRecord.java -text
255 255
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaExportBase.java -text
256
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImagesExport.java -text
257
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImagesRecord.java -text
256
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImageExport.java -text
257
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImageRecord.java -text
258 258
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaRecordBase.java -text
259
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaReferenceExport.java -text
260
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaReferenceRecord.java -text
259 261
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxExport.java -text
260 262
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxExportConfigurator.java -text
261 263
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxExportState.java -text
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImageExport.java
1
/**
2
* Copyright (C) 2007 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.io.dwca.out;
11

  
12
import java.io.File;
13
import java.io.FileNotFoundException;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16
import java.io.OutputStreamWriter;
17
import java.io.PrintWriter;
18
import java.io.UnsupportedEncodingException;
19
import java.util.List;
20
import java.util.Set;
21

  
22
import org.apache.log4j.Logger;
23
import org.springframework.stereotype.Component;
24
import org.springframework.transaction.TransactionStatus;
25

  
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.description.DescriptionBase;
29
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
30
import eu.etaxonomy.cdm.model.description.Distribution;
31
import eu.etaxonomy.cdm.model.description.Feature;
32
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
33
import eu.etaxonomy.cdm.model.media.Media;
34
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
35
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
36
import eu.etaxonomy.cdm.model.taxon.Taxon;
37
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
38

  
39
/**
40
 * @author a.mueller
41
 * @created 18.04.2011
42
 */
43
@Component
44
public class DwcaImageExport extends DwcaExportBase {
45
	private static final Logger logger = Logger.getLogger(DwcaImageExport.class);
46

  
47
	/**
48
	 * Constructor
49
	 */
50
	public DwcaImageExport() {
51
		super();
52
		this.ioName = this.getClass().getSimpleName();
53
	}
54

  
55
	/** Retrieves data from a CDM DB and serializes them CDM to XML.
56
	 * Starts with root taxa and traverses the classification to retrieve children taxa, synonyms and relationships.
57
	 * Taxa that are not part of the classification are not found.
58
	 * 
59
	 * @param exImpConfig
60
	 * @param dbname
61
	 * @param filename
62
	 */
63
	@Override
64
	protected boolean doInvoke(DwcaTaxExportState state){
65
		DwcaTaxExportConfigurator config = state.getConfig();
66
		String dbname = config.getSource() != null ? config.getSource().getName() : "unknown";
67
    	String fileName = config.getDestinationNameString();
68
		logger.info("Serializing DB " + dbname + " to file " + fileName);
69
		TransactionStatus txStatus = startTransaction(true);
70

  
71
		try {
72
			
73
			final String coreTaxFileName = "images.txt";
74
			fileName = fileName + File.separatorChar + coreTaxFileName;
75
			File f = new File(fileName);
76
			if (!f.exists()){
77
				f.createNewFile();
78
			}
79
			FileOutputStream fos = new FileOutputStream(f);
80
			PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, "UTF8"), true);
81

  
82
			
83
			
84
			List<TaxonNode> allNodes =  getClassificationService().getAllNodes();
85
			for (TaxonNode node : allNodes){
86
				DwcaImageRecord record = new DwcaImageRecord();
87
				Taxon taxon = CdmBase.deproxy(node.getTaxon(), Taxon.class);
88
				Set<? extends DescriptionBase> descriptions = taxon.getDescriptions();
89
				for (DescriptionBase description : descriptions){
90
					for (Object o : description.getElements()){
91
						DescriptionElementBase el = CdmBase.deproxy(o, DescriptionElementBase.class);
92
						if (el.getMedia().size() > 0){
93
							for (Media media: el.getMedia()){
94
								for (MediaRepresentation repr : media.getRepresentations()){
95
									for (MediaRepresentationPart part : repr.getParts()){
96
										handleMedia(record, media, repr, part, taxon);
97
									}
98
								}
99
							}
100
						}
101
					}
102
				}
103
				
104
				record.write(writer);
105
				writer.flush();
106
				
107
			}
108
		} catch (FileNotFoundException e) {
109
			e.printStackTrace();
110
		} catch (UnsupportedEncodingException e) {
111
			e.printStackTrace();
112
		} catch (ClassCastException e) {
113
			e.printStackTrace();
114
		} catch (IOException e) {
115
			e.printStackTrace();
116
		}
117
		commitTransaction(txStatus);
118
		return true;
119
	}
120
	
121

  
122

  
123

  
124
	private void handleMedia(DwcaImageRecord record, Media media, MediaRepresentation repr, MediaRepresentationPart part, Taxon taxon) {
125
		record.setCoreid(taxon.getId());
126
		record.setIdentifier(part.getUri());
127
		record.setTitle(media.getTitleCache());
128
		//TODO description if default language description is not available
129
		record.setDescription(media.getDescription(Language.DEFAULT()).getText());
130
		//TODO missing
131
		record.setSpatial(null);
132
		//TODO missing
133
		record.setCoordinates(null);
134
		record.setFormat(repr.getMimeType());
135
		//FIXME missing ??
136
		record.setLicense(media.getRights());
137
		record.setCreated(media.getMediaCreated());
138
		record.setCreator(media.getArtist());
139
		//TODO missing
140
		record.setContributor(null);
141
		//TODO missing
142
		record.setPublisher(null);
143
		//TODO missing
144
		record.setAudience(null);
145
	}
146
	
147
	@Override
148
	protected boolean doCheck(DwcaTaxExportState state) {
149
		boolean result = true;
150
		logger.warn("No check implemented for Jaxb export");
151
		return result;
152
	}
153

  
154

  
155
	@Override
156
	protected boolean isIgnore(DwcaTaxExportState state) {
157
		return false;
158
	}
159
	
160
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImageRecord.java
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.dwca.out;
11

  
12
import java.io.PrintWriter;
13
import java.net.URI;
14
import java.util.Set;
15

  
16
import org.apache.log4j.Logger;
17
import org.joda.time.DateTime;
18

  
19
import eu.etaxonomy.cdm.model.agent.AgentBase;
20
import eu.etaxonomy.cdm.model.location.Point;
21
import eu.etaxonomy.cdm.model.media.Rights;
22

  
23
/**
24
 * @author a.mueller
25
 * @date 20.04.2011
26
 *
27
 */
28
public class DwcaImageRecord extends DwcaRecordBase{
29
	@SuppressWarnings("unused")
30
	private static final Logger logger = Logger.getLogger(DwcaImageRecord.class);
31
	private Integer coreid;
32
	private URI identifier;
33
	private String title;
34
	private String description;
35
	
36
	//TODO ??
37
	private String spatial;
38
	private Point coordinates;
39
	private String format;
40
	private Set<Rights> license;
41
	private DateTime created;
42
	private AgentBase<?> creator;
43
	private AgentBase<?> contributor;
44
	private AgentBase<?> publisher;
45
	
46

  
47

  
48

  
49
	private String audience;
50
	
51
	public void write(PrintWriter writer) {
52
		print(coreid, writer, IS_FIRST);
53
		print(identifier, writer, IS_NOT_FIRST);
54
		print(title, writer, IS_NOT_FIRST);
55
		print(description, writer, IS_NOT_FIRST);
56
		print(spatial, writer, IS_NOT_FIRST);
57
		print(coordinates, writer, IS_NOT_FIRST);
58
		print(license, writer, IS_NOT_FIRST);
59
		print(getDate(created), writer, IS_NOT_FIRST);
60
		print(getAgent(creator), writer, IS_NOT_FIRST);
61
		print(getAgent(contributor), writer, IS_NOT_FIRST);
62
		print(getAgent(publisher), writer, IS_NOT_FIRST);
63
		print(audience, writer, IS_NOT_FIRST);
64

  
65
		writer.println();
66
	}
67

  
68

  
69
	public Integer getCoreid() {
70
		return coreid;
71
	}
72

  
73
	public void setCoreid(Integer coreid) {
74
		this.coreid = coreid;
75
	}
76
	
77
	public URI getIdentifier() {
78
		return identifier;
79
	}
80
	
81
	public void setIdentifier(URI identifier) {
82
		this.identifier = identifier;
83
	}
84

  
85
	public String getTitle() {
86
		return title;
87
	}
88

  
89
	public void setTitle(String title) {
90
		this.title = title;
91
	}
92

  
93
	public String getDescription() {
94
		return description;
95
	}
96

  
97
	public void setDescription(String description) {
98
		this.description = description;
99
	}
100

  
101
	public String getSpatial() {
102
		return spatial;
103
	}
104

  
105
	public void setSpatial(String spatial) {
106
		this.spatial = spatial;
107
	}
108

  
109
	public Point getCoordinates() {
110
		return coordinates;
111
	}
112

  
113
	public void setCoordinates(Point coordinates) {
114
		this.coordinates = coordinates;
115
	}
116

  
117
	public String getFormat() {
118
		return format;
119
	}
120

  
121
	public void setFormat(String format) {
122
		this.format = format;
123
	}
124

  
125
	public Set<Rights> getLicense() {
126
		return license;
127
	}
128

  
129
	public void setLicense(Set<Rights> set) {
130
		this.license = set;
131
	}
132

  
133
	public DateTime getCreated() {
134
		return created;
135
	}
136

  
137
	public void setCreated(DateTime created) {
138
		this.created = created;
139
	}
140

  
141
	public AgentBase<?> getCreator() {
142
		return creator;
143
	}
144

  
145
	public void setCreator(AgentBase<?> creator) {
146
		this.creator = creator;
147
	}
148

  
149
	public AgentBase<?> getContributor() {
150
		return contributor;
151
	}
152

  
153
	public void setContributor(AgentBase<?> contributor) {
154
		this.contributor = contributor;
155
	}
156

  
157
	public AgentBase<?> getPublisher() {
158
		return publisher;
159
	}
160

  
161
	public void setPublisher(AgentBase<?> publisher) {
162
		this.publisher = publisher;
163
	}
164

  
165
	public String getAudience() {
166
		return audience;
167
	}
168

  
169
	public void setAudience(String audience) {
170
		this.audience = audience;
171
	}
172

  
173

  
174
	
175
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImagesExport.java
1
/**
2
* Copyright (C) 2007 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.io.dwca.out;
11

  
12
import java.io.File;
13
import java.io.FileNotFoundException;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16
import java.io.OutputStreamWriter;
17
import java.io.PrintWriter;
18
import java.io.UnsupportedEncodingException;
19
import java.util.List;
20
import java.util.Set;
21

  
22
import org.apache.log4j.Logger;
23
import org.springframework.stereotype.Component;
24
import org.springframework.transaction.TransactionStatus;
25

  
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.description.DescriptionBase;
29
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
30
import eu.etaxonomy.cdm.model.description.Distribution;
31
import eu.etaxonomy.cdm.model.description.Feature;
32
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
33
import eu.etaxonomy.cdm.model.media.Media;
34
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
35
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
36
import eu.etaxonomy.cdm.model.taxon.Taxon;
37
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
38

  
39
/**
40
 * @author a.mueller
41
 * @created 18.04.2011
42
 */
43
@Component
44
public class DwcaImagesExport extends DwcaExportBase {
45
	private static final Logger logger = Logger.getLogger(DwcaImagesExport.class);
46

  
47
	/**
48
	 * Constructor
49
	 */
50
	public DwcaImagesExport() {
51
		super();
52
		this.ioName = this.getClass().getSimpleName();
53
	}
54

  
55
	/** Retrieves data from a CDM DB and serializes them CDM to XML.
56
	 * Starts with root taxa and traverses the classification to retrieve children taxa, synonyms and relationships.
57
	 * Taxa that are not part of the classification are not found.
58
	 * 
59
	 * @param exImpConfig
60
	 * @param dbname
61
	 * @param filename
62
	 */
63
	@Override
64
	protected boolean doInvoke(DwcaTaxExportState state){
65
		DwcaTaxExportConfigurator config = state.getConfig();
66
		String dbname = config.getSource() != null ? config.getSource().getName() : "unknown";
67
    	String fileName = config.getDestinationNameString();
68
		logger.info("Serializing DB " + dbname + " to file " + fileName);
69
		TransactionStatus txStatus = startTransaction(true);
70

  
71
		try {
72
			
73
			final String coreTaxFileName = "images.txt";
74
			fileName = fileName + File.separatorChar + coreTaxFileName;
75
			File f = new File(fileName);
76
			if (!f.exists()){
77
				f.createNewFile();
78
			}
79
			FileOutputStream fos = new FileOutputStream(f);
80
			PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, "UTF8"), true);
81

  
82
			
83
			
84
			List<TaxonNode> allNodes =  getClassificationService().getAllNodes();
85
			for (TaxonNode node : allNodes){
86
				DwcaImagesRecord record = new DwcaImagesRecord();
87
				Taxon taxon = CdmBase.deproxy(node.getTaxon(), Taxon.class);
88
				Set<? extends DescriptionBase> descriptions = taxon.getDescriptions();
89
				for (DescriptionBase description : descriptions){
90
					for (Object o : description.getElements()){
91
						DescriptionElementBase el = CdmBase.deproxy(o, DescriptionElementBase.class);
92
						if (el.getMedia().size() > 0){
93
							for (Media media: el.getMedia()){
94
								for (MediaRepresentation repr : media.getRepresentations()){
95
									for (MediaRepresentationPart part : repr.getParts()){
96
										handleMedia(record, media, repr, part, taxon);
97
									}
98
								}
99
							}
100
						}
101
					}
102
				}
103
				
104
				record.write(writer);
105
				writer.flush();
106
				
107
			}
108
		} catch (FileNotFoundException e) {
109
			e.printStackTrace();
110
		} catch (UnsupportedEncodingException e) {
111
			e.printStackTrace();
112
		} catch (ClassCastException e) {
113
			e.printStackTrace();
114
		} catch (IOException e) {
115
			e.printStackTrace();
116
		}
117
		commitTransaction(txStatus);
118
		return true;
119
	}
120
	
121

  
122

  
123

  
124
	private void handleMedia(DwcaImagesRecord record, Media media, MediaRepresentation repr, MediaRepresentationPart part, Taxon taxon) {
125
		record.setCoreid(taxon.getId());
126
		record.setIdentifier(part.getUri());
127
		record.setTitle(media.getTitleCache());
128
		//TODO description if default language description is not available
129
		record.setDescription(media.getDescription(Language.DEFAULT()).getText());
130
		//TODO missing
131
		record.setSpatial(null);
132
		//TODO missing
133
		record.setCoordinates(null);
134
		record.setFormat(repr.getMimeType());
135
		//FIXME missing ??
136
		record.setLicense(media.getRights());
137
		record.setCreated(media.getMediaCreated());
138
		record.setCreator(media.getArtist());
139
		//TODO missing
140
		record.setContributor(null);
141
		//TODO missing
142
		record.setPublisher(null);
143
		//TODO missing
144
		record.setAudience(null);
145
	}
146
	
147
	@Override
148
	protected boolean doCheck(DwcaTaxExportState state) {
149
		boolean result = true;
150
		logger.warn("No check implemented for Jaxb export");
151
		return result;
152
	}
153

  
154

  
155
	@Override
156
	protected boolean isIgnore(DwcaTaxExportState state) {
157
		return false;
158
	}
159
	
160
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaImagesRecord.java
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.dwca.out;
11

  
12
import java.io.PrintWriter;
13
import java.net.URI;
14
import java.util.Set;
15

  
16
import org.apache.log4j.Logger;
17
import org.joda.time.DateTime;
18

  
19
import eu.etaxonomy.cdm.model.agent.AgentBase;
20
import eu.etaxonomy.cdm.model.location.Point;
21
import eu.etaxonomy.cdm.model.media.Rights;
22

  
23
/**
24
 * @author a.mueller
25
 * @date 20.04.2011
26
 *
27
 */
28
public class DwcaImagesRecord extends DwcaRecordBase{
29
	@SuppressWarnings("unused")
30
	private static final Logger logger = Logger.getLogger(DwcaImagesRecord.class);
31
	private Integer coreid;
32
	private URI identifier;
33
	private String title;
34
	private String description;
35
	
36
	//TODO ??
37
	private String spatial;
38
	private Point coordinates;
39
	private String format;
40
	private Set<Rights> license;
41
	private DateTime created;
42
	private AgentBase<?> creator;
43
	private AgentBase<?> contributor;
44
	private AgentBase<?> publisher;
45
	
46

  
47

  
48

  
49
	private String audience;
50
	
51
	public void write(PrintWriter writer) {
52
		print(coreid, writer, IS_FIRST);
53
		print(identifier, writer, IS_NOT_FIRST);
54
		print(title, writer, IS_NOT_FIRST);
55
		print(description, writer, IS_NOT_FIRST);
56
		print(spatial, writer, IS_NOT_FIRST);
57
		print(coordinates, writer, IS_NOT_FIRST);
58
		print(license, writer, IS_NOT_FIRST);
59
		print(getDate(created), writer, IS_NOT_FIRST);
60
		print(getAgent(creator), writer, IS_NOT_FIRST);
61
		print(getAgent(contributor), writer, IS_NOT_FIRST);
62
		print(getAgent(publisher), writer, IS_NOT_FIRST);
63
		print(audience, writer, IS_NOT_FIRST);
64

  
65
		writer.println();
66
	}
67

  
68

  
69
	public Integer getCoreid() {
70
		return coreid;
71
	}
72

  
73
	public void setCoreid(Integer coreid) {
74
		this.coreid = coreid;
75
	}
76
	
77
	public URI getIdentifier() {
78
		return identifier;
79
	}
80
	
81
	public void setIdentifier(URI identifier) {
82
		this.identifier = identifier;
83
	}
84

  
85
	public String getTitle() {
86
		return title;
87
	}
88

  
89
	public void setTitle(String title) {
90
		this.title = title;
91
	}
92

  
93
	public String getDescription() {
94
		return description;
95
	}
96

  
97
	public void setDescription(String description) {
98
		this.description = description;
99
	}
100

  
101
	public String getSpatial() {
102
		return spatial;
103
	}
104

  
105
	public void setSpatial(String spatial) {
106
		this.spatial = spatial;
107
	}
108

  
109
	public Point getCoordinates() {
110
		return coordinates;
111
	}
112

  
113
	public void setCoordinates(Point coordinates) {
114
		this.coordinates = coordinates;
115
	}
116

  
117
	public String getFormat() {
118
		return format;
119
	}
120

  
121
	public void setFormat(String format) {
122
		this.format = format;
123
	}
124

  
125
	public Set<Rights> getLicense() {
126
		return license;
127
	}
128

  
129
	public void setLicense(Set<Rights> set) {
130
		this.license = set;
131
	}
132

  
133
	public DateTime getCreated() {
134
		return created;
135
	}
136

  
137
	public void setCreated(DateTime created) {
138
		this.created = created;
139
	}
140

  
141
	public AgentBase<?> getCreator() {
142
		return creator;
143
	}
144

  
145
	public void setCreator(AgentBase<?> creator) {
146
		this.creator = creator;
147
	}
148

  
149
	public AgentBase<?> getContributor() {
150
		return contributor;
151
	}
152

  
153
	public void setContributor(AgentBase<?> contributor) {
154
		this.contributor = contributor;
155
	}
156

  
157
	public AgentBase<?> getPublisher() {
158
		return publisher;
159
	}
160

  
161
	public void setPublisher(AgentBase<?> publisher) {
162
		this.publisher = publisher;
163
	}
164

  
165
	public String getAudience() {
166
		return audience;
167
	}
168

  
169
	public void setAudience(String audience) {
170
		this.audience = audience;
171
	}
172

  
173

  
174
	
175
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaReferenceExport.java
1
/**
2
* Copyright (C) 2007 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.io.dwca.out;
11

  
12
import java.io.File;
13
import java.io.FileNotFoundException;
14
import java.io.FileOutputStream;
15
import java.io.IOException;
16
import java.io.OutputStreamWriter;
17
import java.io.PrintWriter;
18
import java.io.UnsupportedEncodingException;
19
import java.util.List;
20
import java.util.Set;
21

  
22
import org.apache.log4j.Logger;
23
import org.springframework.stereotype.Component;
24
import org.springframework.transaction.TransactionStatus;
25

  
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.description.DescriptionBase;
28
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
29
import eu.etaxonomy.cdm.model.description.Distribution;
30
import eu.etaxonomy.cdm.model.description.Feature;
31
import eu.etaxonomy.cdm.model.taxon.Taxon;
32
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
33

  
34
/**
35
 * @author a.mueller
36
 * @created 18.04.2011
37
 */
38
@Component
39
public class DwcaReferenceExport extends DwcaExportBase {
40
	private static final Logger logger = Logger.getLogger(DwcaReferenceExport.class);
41

  
42
	/**
43
	 * Constructor
44
	 */
45
	public DwcaReferenceExport() {
46
		super();
47
		this.ioName = this.getClass().getSimpleName();
48
	}
49

  
50
	/** Retrieves data from a CDM DB and serializes them CDM to XML.
51
	 * Starts with root taxa and traverses the classification to retrieve children taxa, synonyms and relationships.
52
	 * Taxa that are not part of the classification are not found.
53
	 * 
54
	 * @param exImpConfig
55
	 * @param dbname
56
	 * @param filename
57
	 */
58
	@Override
59
	protected boolean doInvoke(DwcaTaxExportState state){
60
		DwcaTaxExportConfigurator config = state.getConfig();
61
		String dbname = config.getSource() != null ? config.getSource().getName() : "unknown";
62
    	String fileName = config.getDestinationNameString();
63
		logger.info("Serializing DB " + dbname + " to file " + fileName);
64
		TransactionStatus txStatus = startTransaction(true);
65

  
66
		try {
67
			
68
			final String coreTaxFileName = "distribution.txt";
69
			fileName = fileName + File.separatorChar + coreTaxFileName;
70
			File f = new File(fileName);
71
			if (!f.exists()){
72
				f.createNewFile();
73
			}
74
			FileOutputStream fos = new FileOutputStream(f);
75
			PrintWriter writer = new PrintWriter(new OutputStreamWriter(fos, "UTF8"), true);
76

  
77
			
78
			
79
			List<TaxonNode> allNodes =  getClassificationService().getAllNodes();
80
			for (TaxonNode node : allNodes){
81
				DwcaReferenceRecord record = new DwcaReferenceRecord();
82
				Taxon taxon = CdmBase.deproxy(node.getTaxon(), Taxon.class);
83
				Set<? extends DescriptionBase> descriptions = taxon.getDescriptions();
84
				for (DescriptionBase description : descriptions){
85
					for (Object o : description.getElements()){
86
						DescriptionElementBase el = CdmBase.deproxy(o, DescriptionElementBase.class);
87
						if (el.isInstanceOf(Distribution.class)){
88
							Distribution distribution = CdmBase.deproxy(el, Distribution.class);
89
							handleDistribution(record, distribution, taxon);
90
						}else if (el.getFeature().equals(Feature.COMMON_NAME())){
91
							//TODO
92
							String message = "Distribution export for TextData not yet implemented";
93
							logger.warn(message);
94
						}
95
					}
96
				}
97
				
98
				record.write(writer);
99
				writer.flush();
100
				
101
			}
102
		} catch (FileNotFoundException e) {
103
			e.printStackTrace();
104
		} catch (UnsupportedEncodingException e) {
105
			e.printStackTrace();
106
		} catch (ClassCastException e) {
107
			e.printStackTrace();
108
		} catch (IOException e) {
109
			e.printStackTrace();
110
		}
111
		commitTransaction(txStatus);
112
		return true;
113
	}
114
	
115

  
116

  
117

  
118
	private void handleDistribution(DwcaReferenceRecord record, Distribution distribution, Taxon taxon) {
119
//		record.setCoreid(taxon.getId());
120
//		handleArea(record, distribution.getArea());
121
//		//TODO missing
122
//		record.setLifeStage(null);
123
//		record.setOccurrenceStatus(distribution.getStatus());
124
//		//TODO missing
125
//		record.setThreadStatus(null);
126
//		//TODO missing
127
//		record.setEstablishmentMeans(null);
128
//		//TODO missing
129
//		record.setAppendixCITES(null);
130
//		//TODO missing
131
//		record.setEventDate(null);
132
//		//TODO missing
133
//		record.setSeasonalDate(null);
134
//		//FIXME
135
//		record.setSource(null);
136
//		//FIXME
137
//		record.setOccurrenceRemarks(null);
138
		
139
	}
140
	
141
	@Override
142
	protected boolean doCheck(DwcaTaxExportState state) {
143
		boolean result = true;
144
		logger.warn("No check implemented for Jaxb export");
145
		return result;
146
	}
147

  
148

  
149
	@Override
150
	protected boolean isIgnore(DwcaTaxExportState state) {
151
		return false;
152
	}
153
	
154
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaReferenceRecord.java
1
// $Id$
2
/**
3
* Copyright (C) 2009 EDIT
4
* European Distributed Institute of Taxonomy 
5
* http://www.e-taxonomy.eu
6
* 
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.cdm.io.dwca.out;
11

  
12
import java.io.PrintWriter;
13
import java.util.Set;
14

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.model.common.Language;
18
import eu.etaxonomy.cdm.model.common.TimePeriod;
19
import eu.etaxonomy.cdm.model.media.Rights;
20

  
21
/**
22
 * @author a.mueller
23
 * @date 18.04.2011
24
 *
25
 */
26
public class DwcaReferenceRecord extends DwcaRecordBase{
27
	@SuppressWarnings("unused")
28
	private static final Logger logger = Logger.getLogger(DwcaReferenceRecord.class);
29
	private Integer coreid;
30
	
31
	private String identifier;
32
	private String bibliographicCitation;
33
	private String title;
34
	private String creator;
35
	private TimePeriod date;
36
	private String source;
37
	private String description;
38
	private String subject;
39
	private Language language;
40
	private Set<Rights> rights;
41
	private String taxonRemarks;
42
	private String type;
43
	
44
	
45
	public void write(PrintWriter writer) {
46
		print(coreid, writer, IS_FIRST);
47
		print(identifier, writer, IS_NOT_FIRST);
48
		print(bibliographicCitation, writer, IS_NOT_FIRST);
49
		print(title, writer, IS_NOT_FIRST);
50
		print(creator, writer, IS_NOT_FIRST);
51
		//TODO
52
		print(getTimePeriod(date), writer, IS_NOT_FIRST);
53
		print(source, writer, IS_NOT_FIRST);
54
		print(description, writer, IS_NOT_FIRST);
55
		print(subject, writer, IS_NOT_FIRST);
56
		print(getLanguage(language), writer, IS_NOT_FIRST);
57
		print(rights, writer, IS_NOT_FIRST);
58
		print(taxonRemarks, writer, IS_NOT_FIRST);
59
		print(type, writer, IS_NOT_FIRST);
60
		writer.println();
61
	}
62

  
63

  
64
	public String getSource() {
65
		return source;
66
	}
67
	public void setSource(String source) {
68
		this.source = source;
69
	}
70

  
71
	public Integer getCoreid() {
72
		return coreid;
73
	}
74

  
75
	public void setCoreid(Integer coreid) {
76
		this.coreid = coreid;
77
	}
78

  
79

  
80
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/dwca/out/DwcaTaxExportConfigurator.java
56 56
				DwcaTaxExport.class,
57 57
				DwcaVernacularExport.class,
58 58
				DwcaDistributionExport.class,
59
				DwcaImagesExport.class
59
				DwcaImageExport.class
60 60
		};
61 61
	};
62 62

  

Also available in: Unified diff