Project

General

Profile

Download (3.16 KB) Statistics
| Branch: | Tag: | Revision:
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.common;
11

    
12
import java.io.ByteArrayOutputStream;
13

    
14
import org.apache.log4j.Logger;
15
import org.springframework.beans.factory.annotation.Autowired;
16

    
17
import eu.etaxonomy.cdm.api.service.IClassificationService;
18
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
19
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.cdm.model.taxon.Synonym;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23

    
24
/**
25
 * @author a.mueller
26
 * @since 01.07.2008
27
 */
28
public abstract class CdmExportBase<CONFIG extends ExportConfiguratorBase<STATE, TRANSFORM, DEST>, STATE extends ExportStateBase, TRANSFORM extends IExportTransformer, DEST extends Object>
29
            extends CdmIoBase<STATE, ExportResult>
30
            implements ICdmExport<CONFIG, STATE>{
31

    
32
    private static final long serialVersionUID = 3685030095117254235L;
33

    
34
    private static Logger logger = Logger.getLogger(CdmExportBase.class);
35

    
36
    protected ByteArrayOutputStream exportStream;
37

    
38

    
39
    @Autowired
40
    protected IClassificationService classificationService;
41

    
42
    @Autowired
43
    protected ITaxonNodeService taxonNodeService;
44

    
45

    
46
	@Override
47
	public  ExportDataWrapper createExportData() {
48
	    if (exportStream != null){
49
	        ExportDataWrapper<byte[]> data = ExportDataWrapper.NewByteArrayInstance();
50
	        data.addExportData( exportStream.toByteArray());
51
	        return data;
52
	    }else{
53
	        return null;
54
	    }
55
	}
56

    
57
    @Override
58
    protected ExportResult getNoDataResult(STATE state) {
59
        return ExportResult.NewNoDataInstance(((IExportConfigurator)state.config).getResultType());
60
    }
61

    
62
    @Override
63
    protected ExportResult getDefaultResult(STATE state) {
64
        return ExportResult.NewInstance(((IExportConfigurator)state.config).getResultType());
65
    }
66

    
67
    @Override
68
    public byte[] getByteArray() {
69
        if (this.exportStream != null){
70
            return this.exportStream.toByteArray();
71
        }
72
        return null;
73
    }
74

    
75

    
76
    public Object getDbId(CdmBase cdmBase, STATE state){
77
        logger.warn("Not yet implemented for export base class");
78
        return null;
79
    }
80

    
81
    /**
82
     * <code>true</code> if neither synonym has state publish nor
83
     * taxon node filter includes unpublished taxa.
84
     */
85
    protected boolean isUnpublished(CONFIG config, Synonym synonym) {
86
        return ! (synonym.isPublish()
87
                || config.getTaxonNodeFilter().isIncludeUnpublished());
88
    }
89

    
90

    
91
    /**
92
     * <code>true</code> if neither pro parte synonym or misapplied name has state publish nor
93
     * taxon node filter includes unpublished taxa.
94
     */
95
    protected boolean isUnpublished(CONFIG config, Taxon relatedSynonymOrMisappliedName) {
96
        return ! (relatedSynonymOrMisappliedName.isPublish()
97
                || config.getTaxonNodeFilter().isIncludeUnpublished());
98
    }
99

    
100
}
(6-6/63)