Project

General

Profile

Download (3.91 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.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.dwca.in.IImportMapping;
23
import eu.etaxonomy.cdm.io.dwca.in.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
 * @created 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 = Logger.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

    
95
	public void setUsePartitions(boolean usePartitions) {
96
		this.usePartitions = usePartitions;
97
	}
98

    
99
	public void setDefaultPartitionSize(int defaultPartitionSize) {
100
		this.defaultPartitionSize = defaultPartitionSize;
101
	}
102

    
103
	public int getDefaultPartitionSize() {
104
		return defaultPartitionSize;
105
	}
106

    
107
	public IImportMapping.MappingType getMappingType() {
108
		return mappingType;
109
	}
110

    
111
	public void setMappingType(IImportMapping.MappingType mappingType) {
112
		this.mappingType = mappingType;
113
	}
114

    
115
	@Override
116
    public String getSourceReferenceTitle() {
117
		return sourceReferenceTitle;
118
	}
119

    
120
	@Override
121
    public void setSourceReferenceTitle(String sourceReferenceTitle) {
122
		this.sourceReferenceTitle = sourceReferenceTitle;
123
	}
124

    
125

    
126
    /**
127
     * @return the databaseMappingFile
128
     */
129
    public String getDatabaseMappingFile() {
130
        return databaseMappingFile;
131
    }
132

    
133
    /**
134
     * @param databaseMappingFile the databaseMappingFile to set
135
     */
136
    public void setDatabaseMappingFile(String databaseMappingFile) {
137
        this.databaseMappingFile = databaseMappingFile;
138
    }
139

    
140

    
141
    /**
142
     * @return the stateUuid
143
     */
144
    public UUID getStateUuid() {
145
        return stateUuid;
146
    }
147
    /**
148
     * @param stateuuid
149
     */
150
    public void setStateUuid(UUID stateUuid) {
151
        this.stateUuid = stateUuid;
152
    }
153

    
154

    
155
}
(3-3/5)