Project

General

Profile

Download (5.31 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.logging.log4j.LogManager;import org.apache.logging.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 = LogManager.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 = TaxonNodeFilter.NewInstance();
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
//	@Override
102
	public IDatabase getSourceReference() {
103
		//TODO //needed
104
		if (this.sourceReference == null){
105
			sourceReference = ReferenceFactory.newDatabase();
106
			if (getSource() != null){
107
				sourceReference.setTitleCache(getSource().getDatabase(), true);
108
			}
109
		}
110
		return sourceReference;
111
	}
112

    
113
	@Override
114
    public Class<ICdmIO>[] getIoClassList(){
115
		return ioClassList;
116
	}
117

    
118
	@Override
119
    public CHECK getCheck() {
120
		return this.check;
121
	}
122

    
123
	public void setCheck(CHECK check) {
124
		this.check = check;
125
	}
126

    
127
	@Override
128
	public TARGET getTarget() {
129
	    return this.target;
130
	}
131

    
132
	@Override
133
	public void setTarget(TARGET target) {
134
	    this.target = target;
135
	}
136

    
137

    
138
	/**
139
	 * Returns a new instance of <code>CdmApplicationController</code> created by the values of this configuration.
140
	 * @return
141
	 */
142
	public ICdmRepository getNewCdmAppController(){
143
		return getCdmAppController(true, false);
144
	}
145

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

    
156

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

    
170

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

    
186
		return result;
187
	}
188

    
189
	@Override
190
    public String getSourceNameString() {
191
		if (this.getSource() == null) {
192
			return null;
193
		} else {
194
			return this.getSource().getName();
195
		}
196
	}
197

    
198
	@Override
199
	public ExportResultType getResultType(){return resultType;}
200

    
201
	public TaxonNodeFilter getTaxonNodeFilter() {
202
        return taxonNodeFilter;
203
    }
204
    public void setTaxonNodeFilter(TaxonNodeFilter taxonNodeFilter) {
205
        this.taxonNodeFilter = taxonNodeFilter;
206
    }
207

    
208
}
(18-18/65)