Project

General

Profile

Download (3.76 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.stream;
11

    
12

    
13
import java.util.UUID;
14

    
15
import org.apache.commons.lang.StringUtils;
16
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
17

    
18
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
19
import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
20
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
21
import eu.etaxonomy.cdm.io.dwca.in.DwcaImport;
22
import eu.etaxonomy.cdm.io.stream.mapping.IImportMapping;
23
import eu.etaxonomy.cdm.io.stream.mapping.IImportMapping.MappingType;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
26

    
27
/**
28
 * Base class for all configurators for stream based imports.
29
 * @author a.mueller
30
 * @since 14.05.2013
31
 */
32
public abstract class StreamImportConfiguratorBase<STATE extends StreamImportStateBase, SOURCE extends Object> extends ImportConfiguratorBase<STATE, SOURCE> implements IImportConfigurator {
33
    private static final long serialVersionUID = 4200675007263433594L;
34

    
35
    @SuppressWarnings("unused")
36
	private static final Logger logger = LogManager.getLogger(StreamImportConfiguratorBase.class);
37

    
38
	//partitions
39
	private boolean usePartitions = true;
40
	private int defaultPartitionSize = 2000;
41

    
42
	private String sourceReferenceTitle = null;
43

    
44
	//mapping
45
	private IImportMapping.MappingType mappingType = MappingType.InMemoryMapping;
46

    
47
    private String databaseMappingFile;
48

    
49
    //the unique state for StreamImportStateBase, which is also used for StreamImportStateBase
50
    private UUID stateUuid;
51

    
52
	/**
53
	 * Constructor.
54
	 * @param transformer
55
	 */
56
	public StreamImportConfiguratorBase(IInputTransformer transformer) {
57
		super(transformer);
58
	}
59

    
60

    
61
	@Override
62
    @SuppressWarnings("unchecked")
63
	protected void makeIoClassList(){
64
		ioClassList = new Class[]{
65
			DwcaImport.class
66
		};
67
	}
68

    
69
	@Override
70
	public Reference getSourceReference() {
71
		if (this.sourceReference == null){
72
			sourceReference = ReferenceFactory.newGeneric();
73
			if (StringUtils.isBlank(this.sourceReferenceTitle )){
74
				sourceReference.setTitleCache(getDefaultSourceReferenceTitle(), true);
75
			}else{
76
				sourceReference.setTitleCache(this.sourceReferenceTitle, true);
77
			}
78
		}
79
		if (getSourceRefUuid() != null){
80
			sourceReference.setUuid(getSourceRefUuid());
81
		}else{
82
			setSourceRefUuid(sourceReference.getUuid());
83
		}
84
		return sourceReference;
85
	}
86

    
87
	protected abstract String getDefaultSourceReferenceTitle();
88

    
89

    
90

    
91
	public boolean isUsePartitions() {
92
		return usePartitions;
93
	}
94
	public void setUsePartitions(boolean usePartitions) {
95
		this.usePartitions = usePartitions;
96
	}
97

    
98
	public void setDefaultPartitionSize(int defaultPartitionSize) {
99
		this.defaultPartitionSize = defaultPartitionSize;
100
	}
101
	public int getDefaultPartitionSize() {
102
		return defaultPartitionSize;
103
	}
104

    
105
	public IImportMapping.MappingType getMappingType() {
106
		return mappingType;
107
	}
108
	public void setMappingType(IImportMapping.MappingType mappingType) {
109
		this.mappingType = mappingType;
110
	}
111

    
112
	@Override
113
    public String getSourceReferenceTitle() {
114
		return sourceReferenceTitle;
115
	}
116

    
117
	@Override
118
    public void setSourceReferenceTitle(String sourceReferenceTitle) {
119
		this.sourceReferenceTitle = sourceReferenceTitle;
120
	}
121

    
122

    
123
    public String getDatabaseMappingFile() {
124
        return databaseMappingFile;
125
    }
126
    public void setDatabaseMappingFile(String databaseMappingFile) {
127
        this.databaseMappingFile = databaseMappingFile;
128
    }
129

    
130

    
131
    public UUID getStateUuid() {
132
        return stateUuid;
133
    }
134
    public void setStateUuid(UUID stateUuid) {
135
        this.stateUuid = stateUuid;
136
    }
137

    
138

    
139
}
(18-18/21)