Project

General

Profile

Download (5.36 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2008 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*/
6

    
7
package eu.etaxonomy.cdm.io.common;
8

    
9
import org.apache.log4j.Logger;
10

    
11
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
12
import eu.etaxonomy.cdm.api.application.ICdmRepository;
13
import eu.etaxonomy.cdm.database.ICdmDataSource;
14
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
15
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
16
import eu.etaxonomy.cdm.model.reference.IDatabase;
17
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
18

    
19
/**
20
 * @author a.babadshanjan
21
 * @since 16.11.2008
22
 */
23
public abstract class ExportConfiguratorBase<STATE extends ExportStateBase, TRANSFORM extends IExportTransformer, DEST extends Object>
24
            extends IoConfiguratorBase
25
            implements IExportConfigurator<STATE, TRANSFORM>{
26

    
27
    private static final long serialVersionUID = -6361253919270760156L;
28

    
29
    private static final Logger logger = Logger.getLogger(ExportConfiguratorBase.class);
30

    
31
	private CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
32

    
33
	private TARGET target = TARGET.FILE;
34

    
35
	private ICdmDataSource source;
36
	private DEST destination;
37
	protected IDatabase sourceReference;
38

    
39
    protected Class<ICdmIO>[] ioClassList;
40

    
41
	 private TaxonNodeFilter taxonNodeFilter = new TaxonNodeFilter();
42

    
43
	protected ExportResultType resultType;
44
	/**
45
     * @param resultType the resultType to set
46
     */
47
    public void setResultType(ExportResultType resultType) {
48
        this.resultType = resultType;
49
    }
50

    
51
    /**
52
	 * The transformer class to be used for Input
53
	 */
54
	private TRANSFORM transformer;
55

    
56
	public ExportConfiguratorBase(TRANSFORM transformer){
57
		super();
58
		//setDbSchemaValidation(DbSchemaValidation.UPDATE);
59
		makeIoClassList();
60
		this.setTransformer(transformer);
61
	}
62

    
63
	abstract protected void makeIoClassList();
64

    
65

    
66
	@Override
67
    public TRANSFORM getTransformer() {
68
		return transformer;
69
	}
70

    
71
	@Override
72
    public void setTransformer(TRANSFORM transformer) {
73
		this.transformer = transformer;
74
	}
75

    
76

    
77
	@Override
78
    public ICdmDataSource getSource() {
79
		return source;
80
	}
81

    
82
	@Override
83
    public void setSource(ICdmDataSource source) {
84
		this.source = source;
85
	}
86

    
87
	/**
88
	 * @param source the source to get
89
	 */
90
	public DEST getDestination() {
91
		return destination;
92
	}
93

    
94
	/**
95
	 * @param source the source to set
96
	 */
97
	public void setDestination(DEST destination) {
98
		this.destination = destination;
99
	}
100

    
101

    
102

    
103
	/* (non-Javadoc)
104
	 * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
105
	 */
106
//	@Override
107
	public IDatabase getSourceReference() {
108
		//TODO //needed
109
		if (this.sourceReference == null){
110
			sourceReference = ReferenceFactory.newDatabase();
111
			if (getSource() != null){
112
				sourceReference.setTitleCache(getSource().getDatabase(), true);
113
			}
114
		}
115
		return sourceReference;
116
	}
117

    
118
	@Override
119
    public Class<ICdmIO>[] getIoClassList(){
120
		return ioClassList;
121
	}
122

    
123
	@Override
124
    public CHECK getCheck() {
125
		return this.check;
126
	}
127

    
128
	public void setCheck(CHECK check) {
129
		this.check = check;
130
	}
131

    
132
	@Override
133
	public TARGET getTarget() {
134
	    return this.target;
135
	}
136

    
137
	@Override
138
	public void setTarget(TARGET target) {
139
	    this.target = target;
140
	}
141

    
142

    
143
	/**
144
	 * Returns a new instance of <code>CdmApplicationController</code> created by the values of this configuration.
145
	 * @return
146
	 */
147
	public ICdmRepository getNewCdmAppController(){
148
		return getCdmAppController(true, false);
149
	}
150

    
151
	/**
152
	 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
153
	 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
154
	 * been created before a new controller is returned.
155
	 * @return
156
	 */
157
	public ICdmRepository getCdmAppController(boolean createNew){
158
		return getCdmAppController(createNew, false);
159
	}
160

    
161

    
162
	/**
163
	 * Returns a <code>CdmApplicationController</code> created by the values of this configuration.
164
	 * If create new is true always a new controller is returned, else the last created controller is returned. If no controller has
165
	 * been created before a new controller is returned.
166
	 * @return
167
	 */
168
	public ICdmRepository getCdmAppController(boolean createNew, boolean omitTermLoading){
169
		if (cdmApp == null || createNew == true){
170
			cdmApp = CdmApplicationController.NewInstance(this.getSource(), this.getDbSchemaValidation(), omitTermLoading);
171
		}
172
		return cdmApp;
173
	}
174

    
175

    
176
	/**
177
	 * @return
178
	 */
179
	@Override
180
    public boolean isValid(){
181
		boolean result = true;
182
//		if (source == null && this.getCdmAppController() == null ){
183
//			logger.warn("Connection to CDM could not be established");
184
//			result = false;
185
//		}
186
		if (destination == null && getTarget() != TARGET.EXPORT_DATA){
187
			logger.warn("Invalid export destination");
188
			result = false;
189
		}
190

    
191
		return result;
192
	}
193

    
194
	@Override
195
    public String getSourceNameString() {
196
		if (this.getSource() == null) {
197
			return null;
198
		} else {
199
			return this.getSource().getName();
200
		}
201
	}
202

    
203
	@Override
204
	public ExportResultType getResultType(){return resultType;}
205
	public TaxonNodeFilter getTaxonNodeFilter() {
206
        return taxonNodeFilter;
207
    }
208

    
209

    
210
    public void setTaxonNodeFilter(TaxonNodeFilter taxonNodeFilter) {
211
        this.taxonNodeFilter = taxonNodeFilter;
212
    }
213

    
214
}
(18-18/63)