Project

General

Profile

« Previous | Next » 

Revision 27f9f715

Added by Andreas Müller almost 2 years ago

cleanup and javadoc

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/StringComparator.java
11 11
import java.util.Comparator;
12 12

  
13 13
/**
14
 * Compares two {@link String}s null safe using the String.compareTo method.
15
 *
14 16
 * @author a.mueller
15 17
 * @since 10.01.2020
16 18
 */
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmApplicationAwareDefaultExport.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.common;
11

  
12
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16

  
17
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
18
import org.springframework.beans.BeansException;
19
import org.springframework.context.ApplicationContext;
20
import org.springframework.context.ApplicationContextAware;
21
import org.springframework.stereotype.Component;
22

  
23
import eu.etaxonomy.cdm.api.service.IService;
24
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
25
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor;
26
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
27
import eu.etaxonomy.cdm.model.common.CdmBase;
28

  
29
/**
30
 * This class is an default exporter class that is a spring bean and therefore it knows all other IO classes that are beans
31
 *
32
 * @author a.mueller
33
 * @since 20.06.2008
34
 */
35
@Component("defaultExport")
36
public class CdmApplicationAwareDefaultExport<T extends IExportConfigurator>
37
        implements ICdmExporter<T>, ApplicationContextAware {
38

  
39
    private static final Logger logger = LogManager.getLogger(CdmApplicationAwareDefaultExport.class);
40

  
41
	protected ApplicationContext applicationContext;
42

  
43
	@Override
44
    public void setApplicationContext(ApplicationContext applicationContext)
45
			throws BeansException {
46
		this.applicationContext = applicationContext;
47
	}
48

  
49

  
50
	//Constants
51
	final static boolean OBLIGATORY = true;
52
	final static boolean FACULTATIVE = false;
53
	final int modCount = 1000;
54

  
55
	private final IService service = null;
56

  
57
	//different type of stores that are used by the known imports
58
	Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<>();
59

  
60
	public CdmApplicationAwareDefaultExport(){
61
		stores.put(ICdmIO.TEAM_STORE, new MapWrapper<>(service));
62
		stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<>(service));
63
		stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<>(service));
64
		stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<>(service));
65
		stores.put(ICdmIO.TAXON_STORE, new MapWrapper<>(service));
66
		stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<>(service));
67
	}
68

  
69

  
70
	@Override
71
    public ExportResult invoke(T config){
72
	    ExportResult result;
73
	    if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_ONLY)){
74
		    result = ExportResult.NewInstance(config.getResultType());
75
		    boolean success =  doCheck(config);
76
		    if (! success){
77
		        result.setAborted();
78
		    }
79
		}else if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_AND_EXPORT)){
80
		    boolean success = doCheck(config);
81
		    if (success){
82
		        result = doExport(config);
83
		    }else{
84
		        result = ExportResult.NewInstance(config.getResultType());
85
	            result.setAborted();
86
		    }
87
		}else if (config.getCheck().equals(IExportConfigurator.CHECK.EXPORT_WITHOUT_CHECK)){
88
			result = doExport(config);
89
		}else{
90
		    result = ExportResult.NewInstance(config.getResultType());
91
            String message = "Unknown CHECK type";
92
            logger.error(message);
93
            result.addError(message);
94
 		}
95
		return result;
96
	}
97

  
98

  
99
    public ExportResult execute(T config) {
100
	    ExportResult result = ExportResult.NewInstance(config.getResultType());
101
	    if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_ONLY)){
102
	        boolean success =  doCheck(config);
103
            if (! success){
104
                result.setAborted();
105
            }
106
        } else if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_AND_EXPORT)){
107
            boolean success = doCheck(config);
108
            if (success){
109
                result = doExport(config);
110
            }else{
111
                result.setAborted();
112
            }
113
        } else if (config.getCheck().equals(IExportConfigurator.CHECK.EXPORT_WITHOUT_CHECK)){
114
            result = doExport(config);
115
        } else{
116
            String message = "Unknown CHECK type";
117
            logger.error(message);
118
            result.addError(message);
119
        }
120
	    return result;
121
	}
122

  
123
	@SuppressWarnings("unchecked")
124
	protected <S extends IExportConfigurator> boolean doCheck(S  config){
125

  
126
	    boolean result = true;
127

  
128
		//check
129
		if (config == null){
130
			logger.warn("CdmExportConfiguration is null");
131
//			result.setState(ExportResultState.ABORTED);
132
			return false;
133
		}else if (! config.isValid()){
134
			logger.warn("CdmExportConfiguration is not valid");
135
//			result.setState(ExportResultState.ABORTED);
136
            return false;
137
		}
138
		System.out.println("Start checking Source ("+ config.getSourceNameString() + ") ...");
139

  
140
		ExportStateBase state = config.getNewState();
141
		state.initialize(config);
142

  
143
		//do check for each class
144
		for (Class<ICdmExport> ioClass: config.getIoClassList()){
145
			try {
146
				String ioBeanName = getComponentBeanName(ioClass);
147
				ICdmIO cdmIo = applicationContext.getBean(ioBeanName, ICdmIO.class);
148
				if (cdmIo != null){
149
					registerObservers(config, cdmIo);
150
					result &= cdmIo.check(state);
151
					unRegisterObservers(config, cdmIo);
152
				}else{
153
				    String message = "cdmIO for class " + (ioClass == null ? "(null)" : ioClass.getSimpleName()) + " was null";
154
					logger.error(message);
155
					return false;
156
				}
157
			} catch (Exception e) {
158
					logger.error(e);
159
					e.printStackTrace();
160
					return false;
161
			}
162
		}
163

  
164
		//return
165
		System.out.println("End checking Source ("+ config.getSourceNameString() + ") for export from Cdm");
166
		return result;
167

  
168
	}
169

  
170

  
171
	private void registerObservers(IExportConfigurator config, ICdmIO io){
172
		for (IIoObserver observer : config.getObservers()){
173
			io.addObserver(observer);
174
		}
175
	}
176

  
177
	private void unRegisterObservers(IExportConfigurator config, ICdmIO io){
178
		for (IIoObserver observer : config.getObservers()){
179
			io.removeObserver(observer);
180
		}
181
	}
182

  
183

  
184

  
185
	/**
186
	 * Executes the whole
187
	 */
188
	protected <CONFIG extends T>  ExportResult doExport(CONFIG config){
189
		//validate
190
		if (config == null){
191
		    ExportResult result = ExportResult.NewInstance(null);
192
		    String message = "Configuration is null";
193
			logger.error(message);
194
			result.addError(message);
195
			result.setAborted();
196
			return result;
197
		}
198
		ExportResult result = ExportResult.NewInstance(config.getResultType());
199
		if (! config.isValid()){
200
			String message = "Configuration is not valid";
201
		    logger.error(message);
202
		    result.addError(message);
203
			result.setAborted();
204
			return result;
205
		}
206

  
207
		ExportStateBase state = config.getNewState();
208
		state.initialize(config);
209
		state.setResult(result);
210

  
211
		List<ICdmExport> ioList = makeIoList(state, config);
212

  
213
		List<Integer> stepCounts = countSteps(state, ioList);
214
		Integer totalCount = stepCounts.get(stepCounts.size()-1);
215
		config.getProgressMonitor().beginTask(config.getUserFriendlyIOName() != null? config.getUserFriendlyIOName():"Start Export", totalCount);
216
		config.getProgressMonitor().worked(1);
217
		IProgressMonitor parentMonitor = SubProgressMonitor
218
		        .NewStarted(config.getProgressMonitor(), 99, "Process data", totalCount);
219

  
220
		//do invoke for each class
221
		for (int i = 0; i< ioList.size(); i++){
222
		    ICdmExport export = ioList.get(i);
223
		    Integer counts = stepCounts.get(i);
224
			try {
225
			    String ioName = export.getClass().getSimpleName();
226
			    SubProgressMonitor ioMonitor = SubProgressMonitor
227
			            .NewStarted(parentMonitor, counts, ioName, counts );
228
//			    state.getConfig().setProgressMonitor(ioMonitor);
229
			    state.setCurrentIO(export);
230
				export.invoke(state);
231
				ioMonitor.done();
232
			} catch (Exception e) {
233
				String message = "Unexpected exception in " + export.getClass().getSimpleName()+ ": " + e.getMessage();
234
				logger.error(message);
235
				e.printStackTrace();
236
		        result.addException(e, message);
237
			}
238
		}
239

  
240
		System.out.println("End export from source '" + config.getSourceNameString()
241
				+ "' to destination '" + config.getDestinationNameString() + "' "
242
				+ "("+ result.toString() + ")"
243
				) ;
244
		return result;
245
	}
246

  
247
	/**
248
     * @param state
249
     * @param ioList
250
     * @return
251
     */
252
    private List<Integer> countSteps(ExportStateBase state, List<ICdmExport> ioList) {
253
        //do invoke for each class
254
        List<Integer> result = new ArrayList<>();
255
        int sum = 0;
256
        for (ICdmExport export: ioList){
257
            int count = 1;
258
            try {
259
//                state.setCurrentIO(export);
260
                count = ((Long)export.countSteps(state)).intValue();
261
            } catch (Exception e) {
262
                String message = "Unexpected exception when count steps for progress monitoring " + export.getClass().getSimpleName()+ ": " + e.getMessage();
263
                logger.error(message);
264
                e.printStackTrace();
265
                state.getResult().addException(e, message);
266
            }
267
            result.add(count);
268
            sum += count;
269
        }
270
        result.add(sum);
271
        return result;
272
    }
273

  
274

  
275
    /**
276
     * @param state
277
     * @param config
278
     * @return
279
     */
280
    private <CONFIG extends T>  List<ICdmExport> makeIoList(ExportStateBase state, CONFIG config) {
281

  
282
        List<ICdmExport> result = new ArrayList<>();
283

  
284
        for (Class<ICdmExport> ioClass: config.getIoClassList()){
285
            try {
286
                String ioBeanName = getComponentBeanName(ioClass);
287
                ICdmExport cdmIo = applicationContext.getBean(ioBeanName, ICdmExport.class);
288
                if (cdmIo != null){
289
                    result.add(cdmIo);
290
                }else{
291
                    String message = "cdmIO was null: " + ioBeanName;
292
                    logger.error(message);
293
                    state.getResult().addError(message);
294
                }
295
            } catch (Exception e) {
296
                    String message = "Unexpected exception in " + ioClass.getSimpleName()+ ": " + e.getMessage();
297
                    logger.error(message);
298
                    e.printStackTrace();
299
                    state.getResult().addException(e, message);
300
            }
301
        }
302
        return result;
303
    }
304

  
305

  
306
    private String getComponentBeanName(Class<ICdmExport> ioClass){
307
		Component component = ioClass.getAnnotation(Component.class);
308
		String ioBean = component.value();
309
		if ("".equals(ioBean)){
310
			ioBean = ioClass.getSimpleName();
311
			ioBean = ioBean.substring(0, 1).toLowerCase() + ioBean.substring(1); //make camelcase
312
		}
313
		return ioBean;
314
	}
315

  
316
}
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.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Map;
16

  
17
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.Logger;
19
import org.springframework.beans.BeansException;
20
import org.springframework.context.ApplicationContext;
21
import org.springframework.context.ApplicationContextAware;
22
import org.springframework.stereotype.Component;
23

  
24
import eu.etaxonomy.cdm.api.service.IService;
25
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
26
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor;
27
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29

  
30
/**
31
 * This class is an default exporter class that is a spring bean and therefore it knows all other IO classes that are beans
32
 *
33
 * @author a.mueller
34
 * @since 20.06.2008
35
 */
36
@Component("defaultExport")
37
public class CdmApplicationAwareDefaultExport<T extends IExportConfigurator>
38
        implements ICdmExporter<T>, ApplicationContextAware {
39

  
40
    private static final Logger logger = LogManager.getLogger(CdmApplicationAwareDefaultExport.class);
41

  
42
	protected ApplicationContext applicationContext;
43

  
44
	@Override
45
    public void setApplicationContext(ApplicationContext applicationContext)
46
			throws BeansException {
47
		this.applicationContext = applicationContext;
48
	}
49

  
50
	//Constants
51
	final static boolean OBLIGATORY = true;
52
	final static boolean FACULTATIVE = false;
53
	final int modCount = 1000;
54

  
55
	private final IService service = null;
56

  
57
	//different type of stores that are used by the known imports
58
	Map<String, MapWrapper<? extends CdmBase>> stores = new HashMap<>();
59

  
60
	public CdmApplicationAwareDefaultExport(){
61
		stores.put(ICdmIO.TEAM_STORE, new MapWrapper<>(service));
62
		stores.put(ICdmIO.REFERENCE_STORE, new MapWrapper<>(service));
63
		stores.put(ICdmIO.NOMREF_STORE, new MapWrapper<>(service));
64
		stores.put(ICdmIO.TAXONNAME_STORE, new MapWrapper<>(service));
65
		stores.put(ICdmIO.TAXON_STORE, new MapWrapper<>(service));
66
		stores.put(ICdmIO.SPECIMEN_STORE, new MapWrapper<>(service));
67
	}
68

  
69

  
70
	@Override
71
    public ExportResult invoke(T config){
72
	    ExportResult result;
73
	    if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_ONLY)){
74
		    result = ExportResult.NewInstance(config.getResultType());
75
		    boolean success =  doCheck(config);
76
		    if (! success){
77
		        result.setAborted();
78
		    }
79
		}else if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_AND_EXPORT)){
80
		    boolean success = doCheck(config);
81
		    if (success){
82
		        result = doExport(config);
83
		    }else{
84
		        result = ExportResult.NewInstance(config.getResultType());
85
	            result.setAborted();
86
		    }
87
		}else if (config.getCheck().equals(IExportConfigurator.CHECK.EXPORT_WITHOUT_CHECK)){
88
			result = doExport(config);
89
		}else{
90
		    result = ExportResult.NewInstance(config.getResultType());
91
            String message = "Unknown CHECK type";
92
            logger.error(message);
93
            result.addError(message);
94
 		}
95
		return result;
96
	}
97

  
98

  
99
    public ExportResult execute(T config) {
100
	    ExportResult result = ExportResult.NewInstance(config.getResultType());
101
	    if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_ONLY)){
102
	        boolean success =  doCheck(config);
103
            if (! success){
104
                result.setAborted();
105
            }
106
        } else if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_AND_EXPORT)){
107
            boolean success = doCheck(config);
108
            if (success){
109
                result = doExport(config);
110
            }else{
111
                result.setAborted();
112
            }
113
        } else if (config.getCheck().equals(IExportConfigurator.CHECK.EXPORT_WITHOUT_CHECK)){
114
            result = doExport(config);
115
        } else{
116
            String message = "Unknown CHECK type";
117
            logger.error(message);
118
            result.addError(message);
119
        }
120
	    return result;
121
	}
122

  
123
	@SuppressWarnings("unchecked")
124
	protected <S extends IExportConfigurator> boolean doCheck(S  config){
125

  
126
	    boolean result = true;
127

  
128
		//check
129
		if (config == null){
130
			logger.warn("CdmExportConfiguration is null");
131
//			result.setState(ExportResultState.ABORTED);
132
			return false;
133
		}else if (! config.isValid()){
134
			logger.warn("CdmExportConfiguration is not valid");
135
//			result.setState(ExportResultState.ABORTED);
136
            return false;
137
		}
138
		System.out.println("Start checking Source ("+ config.getSourceNameString() + ") ...");
139

  
140
		ExportStateBase state = config.getNewState();
141
		state.initialize(config);
142

  
143
		//do check for each class
144
		for (Class<ICdmExport> ioClass: config.getIoClassList()){
145
			try {
146
				String ioBeanName = getComponentBeanName(ioClass);
147
				ICdmIO cdmIo = applicationContext.getBean(ioBeanName, ICdmIO.class);
148
				if (cdmIo != null){
149
					registerObservers(config, cdmIo);
150
					result &= cdmIo.check(state);
151
					unRegisterObservers(config, cdmIo);
152
				}else{
153
				    String message = "cdmIO for class " + (ioClass == null ? "(null)" : ioClass.getSimpleName()) + " was null";
154
					logger.error(message);
155
					return false;
156
				}
157
			} catch (Exception e) {
158
					logger.error(e);
159
					e.printStackTrace();
160
					return false;
161
			}
162
		}
163

  
164
		//return
165
		System.out.println("End checking Source ("+ config.getSourceNameString() + ") for export from Cdm");
166
		return result;
167

  
168
	}
169

  
170

  
171
	private void registerObservers(IExportConfigurator config, ICdmIO io){
172
		for (IIoObserver observer : config.getObservers()){
173
			io.addObserver(observer);
174
		}
175
	}
176

  
177
	private void unRegisterObservers(IExportConfigurator config, ICdmIO io){
178
		for (IIoObserver observer : config.getObservers()){
179
			io.removeObserver(observer);
180
		}
181
	}
182

  
183

  
184

  
185
	/**
186
	 * Executes the whole
187
	 */
188
	protected <CONFIG extends T>  ExportResult doExport(CONFIG config){
189
		//validate
190
		if (config == null){
191
		    ExportResult result = ExportResult.NewInstance(null);
192
		    String message = "Configuration is null";
193
			logger.error(message);
194
			result.addError(message);
195
			result.setAborted();
196
			return result;
197
		}
198
		ExportResult result = ExportResult.NewInstance(config.getResultType());
199
		if (! config.isValid()){
200
			String message = "Configuration is not valid";
201
		    logger.error(message);
202
		    result.addError(message);
203
			result.setAborted();
204
			return result;
205
		}
206

  
207
		ExportStateBase state = config.getNewState();
208
		state.initialize(config);
209
		state.setResult(result);
210

  
211
		List<ICdmExport> ioList = makeIoList(state, config);
212

  
213
		List<Integer> stepCounts = countSteps(state, ioList);
214
		Integer totalCount = stepCounts.get(stepCounts.size()-1);
215
		config.getProgressMonitor().beginTask(config.getUserFriendlyIOName() != null? config.getUserFriendlyIOName():"Start Export", totalCount);
216
		config.getProgressMonitor().worked(1);
217
		IProgressMonitor parentMonitor = SubProgressMonitor
218
		        .NewStarted(config.getProgressMonitor(), 99, "Process data", totalCount);
219

  
220
		//do invoke for each class
221
		for (int i = 0; i< ioList.size(); i++){
222
		    ICdmExport export = ioList.get(i);
223
		    Integer counts = stepCounts.get(i);
224
			try {
225
			    String ioName = export.getClass().getSimpleName();
226
			    SubProgressMonitor ioMonitor = SubProgressMonitor
227
			            .NewStarted(parentMonitor, counts, ioName, counts );
228
//			    state.getConfig().setProgressMonitor(ioMonitor);
229
			    state.setCurrentIO(export);
230
				export.invoke(state);
231
				ioMonitor.done();
232
			} catch (Exception e) {
233
				String message = "Unexpected exception in " + export.getClass().getSimpleName()+ ": " + e.getMessage();
234
				logger.error(message);
235
				e.printStackTrace();
236
		        result.addException(e, message);
237
			}
238
		}
239

  
240
		System.out.println("End export from source '" + config.getSourceNameString()
241
				+ "' to destination '" + config.getDestinationNameString() + "' "
242
				+ "("+ result.toString() + ")"
243
				) ;
244
		return result;
245
	}
246

  
247
	/**
248
     * @param state
249
     * @param ioList
250
     * @return
251
     */
252
    private List<Integer> countSteps(ExportStateBase state, List<ICdmExport> ioList) {
253
        //do invoke for each class
254
        List<Integer> result = new ArrayList<>();
255
        int sum = 0;
256
        for (ICdmExport export: ioList){
257
            int count = 1;
258
            try {
259
//                state.setCurrentIO(export);
260
                count = ((Long)export.countSteps(state)).intValue();
261
            } catch (Exception e) {
262
                String message = "Unexpected exception when count steps for progress monitoring " + export.getClass().getSimpleName()+ ": " + e.getMessage();
263
                logger.error(message);
264
                e.printStackTrace();
265
                state.getResult().addException(e, message);
266
            }
267
            result.add(count);
268
            sum += count;
269
        }
270
        result.add(sum);
271
        return result;
272
    }
273

  
274

  
275
    /**
276
     * @param state
277
     * @param config
278
     * @return
279
     */
280
    private <CONFIG extends T>  List<ICdmExport> makeIoList(ExportStateBase state, CONFIG config) {
281

  
282
        List<ICdmExport> result = new ArrayList<>();
283

  
284
        for (Class<ICdmExport> ioClass: config.getIoClassList()){
285
            try {
286
                String ioBeanName = getComponentBeanName(ioClass);
287
                ICdmExport cdmIo = applicationContext.getBean(ioBeanName, ICdmExport.class);
288
                if (cdmIo != null){
289
                    result.add(cdmIo);
290
                }else{
291
                    String message = "cdmIO was null: " + ioBeanName;
292
                    logger.error(message);
293
                    state.getResult().addError(message);
294
                }
295
            } catch (Exception e) {
296
                    String message = "Unexpected exception in " + ioClass.getSimpleName()+ ": " + e.getMessage();
297
                    logger.error(message);
298
                    e.printStackTrace();
299
                    state.getResult().addException(e, message);
300
            }
301
        }
302
        return result;
303
    }
304

  
305

  
306
    private String getComponentBeanName(Class<ICdmExport> ioClass){
307
		Component component = ioClass.getAnnotation(Component.class);
308
		String ioBean = component.value();
309
		if ("".equals(ioBean)){
310
			ioBean = ioClass.getSimpleName();
311
			ioBean = ioBean.substring(0, 1).toLowerCase() + ioBean.substring(1); //make camelcase
312
		}
313
		return ioBean;
314
	}
315

  
316
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/IImportConfigurator.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

  
10
package eu.etaxonomy.cdm.io.common;
11

  
12
import java.util.UUID;
13

  
14
import eu.etaxonomy.cdm.database.DbSchemaValidation;
15
import eu.etaxonomy.cdm.database.ICdmDataSource;
16
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
17
import eu.etaxonomy.cdm.model.agent.Person;
18
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
19
import eu.etaxonomy.cdm.model.reference.Reference;
20

  
21
/**
22
 * @author a.mueller
23
 * @since 29.01.2009
24
 */
25
public interface IImportConfigurator extends IIoConfigurator {
26

  
27
    public static enum SOURCE_TYPE {
28
        URI,
29
        INPUTSTREAM
30
    }
31
    public static enum CHECK{
32
        CHECK_ONLY,
33
        IMPORT_WITHOUT_CHECK,
34
        CHECK_AND_IMPORT;
35

  
36
        public boolean isImport(){
37
            return this == IMPORT_WITHOUT_CHECK || this == CHECK_AND_IMPORT ;
38
        }
39
    }
40

  
41
    public static enum EDITOR{
42
        NO_EDITORS,  //leaves out createdBy and updatedBy information
43
        EDITOR_AS_ANNOTATION,//save createdBy and updatedBy in annotations
44
        EDITOR_AS_EDITOR, //save createdBy and updatedBy in createdBy and updatedBy
45
    }
46

  
47
    public static enum DO_REFERENCES{
48
        NONE,
49
        NOMENCLATURAL,
50
        CONCEPT_REFERENCES,
51
        ALL;
52

  
53
        public DO_REFERENCES invers(){
54
        	if (this == DO_REFERENCES.NONE){
55
        		return ALL;
56
        	}else if (this == ALL){
57
        		return NONE;
58
        	}else if (this == NOMENCLATURAL){  //don't change
59
        		return NOMENCLATURAL;
60
        	}else if (this == CONCEPT_REFERENCES){  //don't change
61
        		return CONCEPT_REFERENCES;
62
        	}else{
63
        		throw new RuntimeException("inverse for DO_REFERENCE type: " + this + " not yet handled");
64
        	}
65
        }
66
    }
67

  
68

  
69

  
70
    public boolean isValid();
71

  
72
    /**
73
     * Factory method. Creates a new state for the import type and adds this configuration to it.
74
     * @return
75
     */
76
    public <STATE extends ImportStateBase> STATE getNewState();
77

  
78
    /* ****************** GETTER/SETTER **************************/
79

  
80
    /**
81
     * @return the doReferences
82
     */
83
    public CHECK getCheck();
84

  
85
    /**
86
     * @param doReferences the doReferences to set
87
     */
88
    public void setCheck(CHECK check);
89

  
90
    /**
91
     * @return the editor
92
     */
93
    public EDITOR getEditor();
94

  
95
    /**
96
     * @param editor sets the way how editing (created, updated) information is handled
97
     */
98
    public void setEditor(EDITOR editor);
99

  
100
    /**
101
     * The destination data source for the import
102
     * Don't use when using a spring data source
103
     * @return
104
     */
105
    public ICdmDataSource getDestination();
106

  
107
    public void setDestination(ICdmDataSource destination);
108

  
109
    @Override
110
    public DbSchemaValidation getDbSchemaValidation();
111

  
112
    @Override
113
    public void setDbSchemaValidation(
114
            DbSchemaValidation dbSchemaValidation);
115

  
116
    /**
117
     * The reference that represents the source. E.g. if the import source is a database
118
     * the returned reference should be of type eu.etaxonomy.cdm.model.reference.Database and
119
     * should represent the according database.
120
     * If the import comes from a file (e.g. XML) the returned value should best represent the
121
     * source of this file (e.g. if the source of an XML file is a certain database this database
122
     * should be mentioned as the source. Otherwise a eu.etaxonomy.cdm.model.reference.Generic
123
     * reference with the name of the XML file should be returned value
124
     * @return
125
     */
126
    public Reference getSourceReference();
127

  
128

  
129

  
130
    /**
131
     * Any object that represents the Source. The implementing class must cast this to
132
     * the correct class type
133
     * @return
134
     */
135
    public Object getSource();
136

  
137
    //public abstract void setSource(Object url);
138

  
139
    public void setSourceReference(Reference sourceReference);
140

  
141
    public String getSourceReferenceTitle();
142

  
143
    public void setSourceReferenceTitle(String sourceReferenceTitle);
144

  
145
    public Person getCommentator();
146

  
147
    public void setCommentator(Person commentator);
148

  
149
    public NomenclaturalCode getNomenclaturalCode();
150

  
151
    public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode);
152

  
153
    public Class<ICdmImport>[] getIoClassList();
154

  
155
    public Object getSourceSecId();
156

  
157
     /**
158
      * If this import implicitly represents a classification in the destination CDM database
159
      * one can define the classification's uuid here. The congrete import class must support this
160
      * functionality otherwise it will have no effect.
161
      * @return
162
      */
163
    public UUID getClassificationUuid();
164
    public void setClassificationUuid(UUID treeUuid);
165

  
166
    /**
167
      * If one wants do define the uuid of the accepted taxa (except for missaplied names) this can be
168
      * done here
169
      * @return
170
      */
171
     public UUID getSecUuid();
172
    public void setSecUuid(UUID secUuid);
173

  
174

  
175
    /**
176
     * Returns the transformer used during import
177
     * @return
178
     */
179
    public IInputTransformer getTransformer();
180

  
181
    /**
182
     * Sets the transformer used during import
183
     * @param transformer
184
     */
185
    public void setTransformer(IInputTransformer transformer);
186

  
187

  
188
    /**
189
     * Defines if term loading should take place if a new application controller
190
     * is created. Usually should return false as imports run into existing databases.
191
     * However, some imports like the current implementation of the JAXB import require
192
     * to create ALL data anew and import the data itself. Therefore they need to
193
     * allow omitting term loading.
194
     * This may be replaced by a more sophisticated solution in future.
195
     * @return
196
     */
197
    public boolean isOmitTermLoading();
198

  
199
    /**
200
     * Defines if the database will be created anew. Usually should return false as imports
201
     * run into existing databases.
202
     * However, some imports like the current implementation of the JAXB import require
203
     * to create ALL data anew. Therefore they need to allow to create all data anew.
204
     * This may be replaced by a more sophisticated solution in future.
205
     * @return
206
     */
207
    public boolean isCreateNew();
208

  
209
}
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.common;
10

  
11
import java.util.UUID;
12

  
13
import eu.etaxonomy.cdm.database.DbSchemaValidation;
14
import eu.etaxonomy.cdm.database.ICdmDataSource;
15
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
16
import eu.etaxonomy.cdm.model.agent.Person;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18
import eu.etaxonomy.cdm.model.reference.Reference;
19

  
20
/**
21
 * @author a.mueller
22
 * @since 29.01.2009
23
 */
24
public interface IImportConfigurator extends IIoConfigurator {
25

  
26
    public static enum SOURCE_TYPE {
27
        URI,
28
        INPUTSTREAM
29
    }
30
    public static enum CHECK{
31
        CHECK_ONLY,
32
        IMPORT_WITHOUT_CHECK,
33
        CHECK_AND_IMPORT;
34

  
35
        public boolean isImport(){
36
            return this == IMPORT_WITHOUT_CHECK || this == CHECK_AND_IMPORT ;
37
        }
38
    }
39

  
40
    public static enum EDITOR{
41
        NO_EDITORS,  //leaves out createdBy and updatedBy information
42
        EDITOR_AS_ANNOTATION,//save createdBy and updatedBy in annotations
43
        EDITOR_AS_EDITOR, //save createdBy and updatedBy in createdBy and updatedBy
44
    }
45

  
46
    public static enum DO_REFERENCES{
47
        NONE,
48
        NOMENCLATURAL,
49
        CONCEPT_REFERENCES,
50
        ALL;
51

  
52
        public DO_REFERENCES invers(){
53
        	if (this == DO_REFERENCES.NONE){
54
        		return ALL;
55
        	}else if (this == ALL){
56
        		return NONE;
57
        	}else if (this == NOMENCLATURAL){  //don't change
58
        		return NOMENCLATURAL;
59
        	}else if (this == CONCEPT_REFERENCES){  //don't change
60
        		return CONCEPT_REFERENCES;
61
        	}else{
62
        		throw new RuntimeException("inverse for DO_REFERENCE type: " + this + " not yet handled");
63
        	}
64
        }
65
    }
66

  
67
    public boolean isValid();
68

  
69
    /**
70
     * Factory method. Creates a new state for the import type and adds this configuration to it.
71
     * @return
72
     */
73
    public <STATE extends ImportStateBase> STATE getNewState();
74

  
75
    /* ****************** GETTER/SETTER **************************/
76

  
77
    public CHECK getCheck();
78
    public void setCheck(CHECK check);
79

  
80
    /**
81
     * @return the editor
82
     */
83
    public EDITOR getEditor();
84

  
85
    /**
86
     * @param editor sets the way how editing (created, updated) information is handled
87
     */
88
    public void setEditor(EDITOR editor);
89

  
90
    /**
91
     * The destination data source for the import
92
     * Don't use when using a spring data source
93
     * @return
94
     */
95
    public ICdmDataSource getDestination();
96

  
97
    public void setDestination(ICdmDataSource destination);
98

  
99
    @Override
100
    public DbSchemaValidation getDbSchemaValidation();
101

  
102
    @Override
103
    public void setDbSchemaValidation(
104
            DbSchemaValidation dbSchemaValidation);
105

  
106
    /**
107
     * The reference that represents the source. E.g. if the import source is a database
108
     * the returned reference should be of type eu.etaxonomy.cdm.model.reference.Database and
109
     * should represent the according database.
110
     * If the import comes from a file (e.g. XML) the returned value should best represent the
111
     * source of this file (e.g. if the source of an XML file is a certain database this database
112
     * should be mentioned as the source. Otherwise a eu.etaxonomy.cdm.model.reference.Generic
113
     * reference with the name of the XML file should be returned value
114
     * @return
115
     */
116
    public Reference getSourceReference();
117

  
118
    /**
119
     * Any object that represents the Source. The implementing class must cast this to
120
     * the correct class type
121
     * @return
122
     */
123
    public Object getSource();
124

  
125
    //public abstract void setSource(Object url);
126

  
127
    public void setSourceReference(Reference sourceReference);
128

  
129
    public String getSourceReferenceTitle();
130

  
131
    public void setSourceReferenceTitle(String sourceReferenceTitle);
132

  
133
    public Person getCommentator();
134

  
135
    public void setCommentator(Person commentator);
136

  
137
    public NomenclaturalCode getNomenclaturalCode();
138

  
139
    public void setNomenclaturalCode(NomenclaturalCode nomenclaturalCode);
140

  
141
    public Class<ICdmImport>[] getIoClassList();
142

  
143
    public Object getSourceSecId();
144

  
145
     /**
146
      * If this import implicitly represents a classification in the destination CDM database
147
      * one can define the classification's uuid here. The congrete import class must support this
148
      * functionality otherwise it will have no effect.
149
      * @return
150
      */
151
    public UUID getClassificationUuid();
152
    public void setClassificationUuid(UUID treeUuid);
153

  
154
    /**
155
     * If one wants do define the uuid of the accepted taxa (except for missaplied names) this can be
156
     * done here
157
     */
158
    public UUID getSecUuid();
159
    public void setSecUuid(UUID secUuid);
160

  
161
    /**
162
     * Returns the transformer used during import
163
     */
164
    public IInputTransformer getTransformer();
165
    /**
166
     * Sets the transformer used during import
167
     * @param transformer
168
     */
169
    public void setTransformer(IInputTransformer transformer);
170

  
171
    /**
172
     * Defines if term loading should take place if a new application controller
173
     * is created. Usually should return false as imports run into existing databases.
174
     * However, some imports like the current implementation of the JAXB import require
175
     * to create ALL data anew and import the data itself. Therefore they need to
176
     * allow omitting term loading.
177
     * This may be replaced by a more sophisticated solution in future.
178
     * @return
179
     */
180
    public boolean isOmitTermLoading();
181

  
182
    /**
183
     * Defines if the database will be created anew. Usually should return false as imports
184
     * run into existing databases.
185
     * However, some imports like the current implementation of the JAXB import require
186
     * to create ALL data anew. Therefore they need to allow to create all data anew.
187
     * This may be replaced by a more sophisticated solution in future.
188
     * @return
189
     */
190
    public boolean isCreateNew();
191
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/ImportConfiguratorBase.java
350 350
    public void setRegisterAuditing(boolean registerAuditing) {
351 351
        this.hibernateConfig.setRegisterEnvers(registerAuditing);
352 352
    }
353

  
354
}
353
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/IoStateBase.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
package eu.etaxonomy.cdm.io.common;
10

  
11
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
12

  
13
import eu.etaxonomy.cdm.common.IoResultBase;
14

  
15
/**
16
 * @author a.mueller
17
 * @since 11.05.2009
18
 */
19
public abstract class IoStateBase<CONFIG
20
        extends IIoConfigurator, IO extends ICdmIO, RESULT extends IoResultBase> {
21

  
22
	@SuppressWarnings("unused")
23
	private static final Logger logger = LogManager.getLogger(IoStateBase.class);
24

  
25
	private IO currentIO;
26

  
27
	protected CONFIG config;
28

  
29
	private RESULT result;
30

  
31
    //TODO config not necessary ones it it implemented in constructor for IOs too.
32
	public void initialize(CONFIG config){
33
	    this.config = config;
34
	}
35

  
36
	public CONFIG getConfig() {
37
		return config;
38
	}
39
	public void setConfig(CONFIG config) {
40
		this.config = config;
41
	}
42

  
43
	public void setCurrentIO(IO currentIO) {
44
		this.currentIO = currentIO;
45
	}
46
	public IO getCurrentIO() {
47
		return currentIO;
48
	}
49

  
50
    public RESULT getResult() {
51
        return result;
52
    }
53
    public void setResult(RESULT result) {
54
        this.result = result;
55
    }
56

  
57
//    public IProgressMonitor getCurrentMonitor() {
58
//        return currentMonitor;
59
//    }
60
//    public void setCurrentMonitor(IProgressMonitor currentMonitor) {
61
//        this.currentMonitor = currentMonitor;
62
//    }
63
}
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
package eu.etaxonomy.cdm.io.common;
10

  
11
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.Logger;
13

  
14
import eu.etaxonomy.cdm.common.IoResultBase;
15

  
16
/**
17
 * @author a.mueller
18
 * @since 11.05.2009
19
 */
20
public abstract class IoStateBase<CONFIG
21
        extends IIoConfigurator, IO extends ICdmIO, RESULT extends IoResultBase> {
22

  
23
	@SuppressWarnings("unused")
24
	private static final Logger logger = LogManager.getLogger(IoStateBase.class);
25

  
26
	private IO currentIO;
27

  
28
	protected CONFIG config;
29

  
30
	private RESULT result;
31

  
32
    //TODO config not necessary ones it it implemented in constructor for IOs too.
33
	public void initialize(CONFIG config){
34
	    this.config = config;
35
	}
36

  
37
	public CONFIG getConfig() {
38
		return config;
39
	}
40
	public void setConfig(CONFIG config) {
41
		this.config = config;
42
	}
43

  
44
	public void setCurrentIO(IO currentIO) {
45
		this.currentIO = currentIO;
46
	}
47
	public IO getCurrentIO() {
48
		return currentIO;
49
	}
50

  
51
    public RESULT getResult() {
52
        return result;
53
    }
54
    public void setResult(RESULT result) {
55
        this.result = result;
56
    }
57
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/XmlImportConfiguratorBase.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.common;
10

  
11
import eu.etaxonomy.cdm.common.URI;
12
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
13

  
14
/**
15
 * @author a.mueller
16
 * @since 28.06.2011
17
 */
18
//<ImportConfiguratorBase, XmlImportBase>
19
public abstract class XmlImportConfiguratorBase<STATE extends XmlImportState> extends ImportConfiguratorBase<STATE, URI> {
20

  
21
	public XmlImportConfiguratorBase(IInputTransformer transformer) {
22
		super(transformer);
23
	}
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.common;
10

  
11
import eu.etaxonomy.cdm.common.URI;
12
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
13

  
14
/**
15
 * @author a.mueller
16
 * @since 28.06.2011
17
 */
18
//<ImportConfiguratorBase, XmlImportBase>
19
public abstract class XmlImportConfiguratorBase<STATE extends XmlImportState>
20
        extends ImportConfiguratorBase<STATE, URI> {
21

  
22
	public XmlImportConfiguratorBase(IInputTransformer transformer) {
23
		super(transformer);
24
	}
24 25
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/XmlImportState.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.common;
11

  
12
import javax.xml.stream.XMLEventReader;
13

  
14
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
15

  
16
/**
17
 * @author a.mueller
18
 * @since 11.05.2009
19
 */
20
public class XmlImportState<CONFIG extends XmlImportConfiguratorBase, IO extends XmlImportBase> extends ImportStateBase<CONFIG, IO> {
21
	@SuppressWarnings("unused")
22
	private static final Logger logger = LogManager.getLogger(XmlImportState.class);
23

  
24
	private XMLEventReader reader;
25

  
26
	
27
	public XmlImportState(CONFIG config) {
28
		super(config);
29
	}
30

  
31
	
32

  
33
	/**
34
	 * @return the reader
35
	 */
36
	public XMLEventReader getReader() {
37
		return reader;
38
	}
39

  
40
	public void setReader(XMLEventReader reader) {
41
		this.reader = reader;
42
		
43
	}
44

  
45

  
46

  
47
	
48

  
49
}
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
package eu.etaxonomy.cdm.io.common;
10

  
11
import javax.xml.stream.XMLEventReader;
12

  
13
import org.apache.logging.log4j.LogManager;
14
import org.apache.logging.log4j.Logger;
15

  
16
/**
17
 * @author a.mueller
18
 * @since 11.05.2009
19
 */
20
public class XmlImportState<CONFIG extends XmlImportConfiguratorBase, IO extends XmlImportBase>
21
        extends ImportStateBase<CONFIG, IO> {
22

  
23
    @SuppressWarnings("unused")
24
	private static final Logger logger = LogManager.getLogger(XmlImportState.class);
25

  
26
	private XMLEventReader reader;
27

  
28
	public XmlImportState(CONFIG config) {
29
		super(config);
30
	}
31

  
32
	public XMLEventReader getReader() {
33
		return reader;
34
	}
35
	public void setReader(XMLEventReader reader) {
36
		this.reader = reader;
37
	}
38
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/descriptive/word/out/WordTermExport.java
123 123
            }
124 124
            addChildNode(childNode, mainDocumentPart, indent+1);
125 125
        }
126

  
127 126
    }
128 127

  
129 128
    @Override
130 129
    protected boolean isIgnore(WordTermExportState state) {
131 130
        return false;
132 131
    }
133

  
134
}
132
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/sdd/in/SDDImportConfigurator.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.sdd.in;
11

  
12
import java.io.InputStream;
13
import java.net.MalformedURLException;
14
import eu.etaxonomy.cdm.common.URI;
15
import java.net.URL;
16

  
17
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
18
import org.jdom.Element;
19
import org.jdom.Namespace;
20

  
21
import eu.etaxonomy.cdm.common.XmlHelp;
22
import eu.etaxonomy.cdm.database.ICdmDataSource;
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
24
import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator;
25
import eu.etaxonomy.cdm.io.common.XmlImportConfiguratorBase;
26
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
27
import eu.etaxonomy.cdm.io.sdd.SDDTransformer;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30

  
31
/**
32
 * @author h.fradin
33
 * @since 24.10.2008
34
 */
35
public class SDDImportConfigurator extends XmlImportConfiguratorBase<SDDImportState> implements IImportConfigurator, IMatchingImportConfigurator {
36
    private static final long serialVersionUID = -960998183005112130L;
37

  
38
    private static final Logger logger = LogManager.getLogger(SDDImportConfigurator.class);
39

  
40
	//TODO
41
	private static IInputTransformer defaultTransformer = new SDDTransformer();
42

  
43
	private boolean doMatchTaxa = true;
44

  
45
	//xml xmlNamespace
46
	Namespace sddNamespace;
47

  
48
	@Override
49
    protected void makeIoClassList(){
50
		ioClassList = new Class[]{
51
				SDDImport.class
52
		};
53
	};
54

  
55
	public static SDDImportConfigurator NewInstance(URI uri, ICdmDataSource destination){
56
		return new SDDImportConfigurator(uri, destination);
57
	}
58

  
59

  
60
	/**
61
	 * @param berlinModelSource
62
	 * @param sourceReference
63
	 * @param destination
64
	 */
65
	private SDDImportConfigurator(URI uri, ICdmDataSource destination) {
66
		super(defaultTransformer);
67
		setSource(uri);
68
		setDestination(destination);
69
	}
70

  
71

  
72
	@Override
73
    public SDDImportState getNewState() {
74
		return new SDDImportState(this);
75
	}
76

  
77

  
78
	/**
79
	 * @return
80
	 */
81
	public Element getSourceRoot(){
82
		try {
83
			URL url;
84
			url = getSource().toURL();
85
			Object o = url.getContent();
86
			InputStream is = (InputStream)o;
87
			Element root = XmlHelp.getRoot(is);
88
			makeNamespaces(root);
89
			return root;
90
		} catch (MalformedURLException e) {
91
			e.printStackTrace();
92
		}catch (Exception e) {
93
			// TODO Auto-generated catch block
94
			e.printStackTrace();
95
		}
96
		return null;
97
	}
98

  
99
	private boolean makeNamespaces(Element root){
100
		sddNamespace = root.getNamespace();
101
		return true;
102
	}
103

  
104
	@Override
105
	public Reference getSourceReference() {
106
		//TODO
107
		if (this.sourceReference == null){
108
			logger.warn("getSource Reference not yet fully implemented");
109
			sourceReference = ReferenceFactory.newDatabase();
110
			sourceReference.setTitleCache("XXX", true);
111
		}
112
		return sourceReference;
113
	}
114

  
115
	@Override
116
    public String getSourceNameString() {
117
		if (this.getSource() == null){
118
			return null;
119
		}else{
120
			return this.getSource().toString();
121
		}
122
	}
123

  
124
	public Namespace getSddNamespace() {
125
		return sddNamespace;
126
	}
127

  
128
	public void setSddNamespace(Namespace xmlNamespace) {
129
		this.sddNamespace = xmlNamespace;
130
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff