1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.io.pesi.erms;
|
12
|
|
13
|
import java.sql.ResultSet;
|
14
|
import java.sql.SQLException;
|
15
|
import java.util.HashMap;
|
16
|
import java.util.HashSet;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
|
20
|
import org.apache.log4j.Logger;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
|
23
|
import eu.etaxonomy.cdm.io.common.IOValidator;
|
24
|
import eu.etaxonomy.cdm.io.common.mapping.DbImportDescriptionElementSourceCreationMapper;
|
25
|
import eu.etaxonomy.cdm.io.common.mapping.DbImportMapping;
|
26
|
import eu.etaxonomy.cdm.io.pesi.erms.validation.ErmsVernacularSourceImportValidator;
|
27
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
28
|
import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
|
29
|
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
|
30
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
* @created 12.03.2010
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
@Component
|
38
|
public class ErmsNotesSourcesImport extends ErmsImportBase<CommonTaxonName> {
|
39
|
@SuppressWarnings("unused")
|
40
|
private static final Logger logger = Logger.getLogger(ErmsNotesSourcesImport.class);
|
41
|
|
42
|
|
43
|
//************************** VARIABLES ********************************************
|
44
|
|
45
|
private static String pluralString = "note sources";
|
46
|
private static String dbTableName = "notes_sources";
|
47
|
private static final Class cdmTargetClass = DescriptionElementSource.class;
|
48
|
|
49
|
private DbImportMapping mapping;
|
50
|
|
51
|
|
52
|
//******************************************* CONSTRUCTOR *******************************
|
53
|
|
54
|
/**
|
55
|
* @param dbTableName
|
56
|
* @param pluralString
|
57
|
* @param dbTableName
|
58
|
*/
|
59
|
public ErmsNotesSourcesImport() {
|
60
|
super(pluralString, dbTableName, cdmTargetClass);
|
61
|
}
|
62
|
|
63
|
|
64
|
/* (non-Javadoc)
|
65
|
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getRecordQuery(eu.etaxonomy.cdm.io.erms.ErmsImportConfigurator)
|
66
|
*/
|
67
|
@Override
|
68
|
protected String getRecordQuery(ErmsImportConfigurator config) {
|
69
|
String strQuery =
|
70
|
" SELECT * " +
|
71
|
" FROM vernaculars_sources " +
|
72
|
" WHERE vernacular_id IN (" + ID_LIST_TOKEN + ") AND " +
|
73
|
" source_id IN (" + ID_LIST_TOKEN + ")";
|
74
|
return strQuery;
|
75
|
}
|
76
|
|
77
|
/* (non-Javadoc)
|
78
|
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getIdQuery()
|
79
|
*/
|
80
|
@Override
|
81
|
protected String getIdQuery() {
|
82
|
String strQuery =
|
83
|
" SELECT vernacular_id, source_id " +
|
84
|
" FROM vernaculars_sources "
|
85
|
;
|
86
|
return strQuery;
|
87
|
}
|
88
|
|
89
|
/* (non-Javadoc)
|
90
|
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getMapping()
|
91
|
*/
|
92
|
protected DbImportMapping getMapping() {
|
93
|
if (mapping == null){
|
94
|
mapping = new DbImportMapping();
|
95
|
String vernacularNamespace = ErmsVernacularImport.VERNACULAR_NAMESPACE;
|
96
|
String referenceNamespace = ErmsReferenceImport.REFERENCE_NAMESPACE;
|
97
|
mapping.addMapper(DbImportDescriptionElementSourceCreationMapper.NewInstance("vernacular_id", vernacularNamespace, "source_id", referenceNamespace ));
|
98
|
}
|
99
|
return mapping;
|
100
|
}
|
101
|
|
102
|
/* (non-Javadoc)
|
103
|
* @see eu.etaxonomy.cdm.io.common.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
|
104
|
*/
|
105
|
public Map getRelatedObjectsForPartition(ResultSet rs) {
|
106
|
String nameSpace;
|
107
|
Class cdmClass;
|
108
|
Set<String> idSet;
|
109
|
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>();
|
110
|
|
111
|
try{
|
112
|
Set<String> vernacularIdSet = new HashSet<String>();
|
113
|
Set<String> sourceIdSet = new HashSet<String>();
|
114
|
while (rs.next()){
|
115
|
handleForeignKey(rs, vernacularIdSet, "vernacular_id");
|
116
|
handleForeignKey(rs, sourceIdSet, "source_id");
|
117
|
}
|
118
|
|
119
|
//vernacular map
|
120
|
nameSpace = ErmsVernacularImport.VERNACULAR_NAMESPACE;
|
121
|
cdmClass = CommonTaxonName.class;
|
122
|
idSet = vernacularIdSet;
|
123
|
Map<String, CommonTaxonName> vernacularMap = (Map<String, CommonTaxonName>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
124
|
result.put(nameSpace, vernacularMap);
|
125
|
|
126
|
|
127
|
//reference map
|
128
|
nameSpace = ErmsReferenceImport.REFERENCE_NAMESPACE;
|
129
|
cdmClass = Reference.class;
|
130
|
idSet = sourceIdSet;
|
131
|
Map<String, Reference> referenceMap = (Map<String, Reference>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
132
|
result.put(nameSpace, referenceMap);
|
133
|
|
134
|
} catch (SQLException e) {
|
135
|
throw new RuntimeException(e);
|
136
|
}
|
137
|
return result;
|
138
|
}
|
139
|
|
140
|
|
141
|
/* (non-Javadoc)
|
142
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
|
143
|
*/
|
144
|
@Override
|
145
|
protected boolean doCheck(ErmsImportState state) {
|
146
|
IOValidator<ErmsImportState> validator = new ErmsVernacularSourceImportValidator();
|
147
|
return validator.validate(state);
|
148
|
}
|
149
|
|
150
|
|
151
|
/* (non-Javadoc)
|
152
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
|
153
|
*/
|
154
|
@Override
|
155
|
protected boolean isIgnore(ErmsImportState state) {
|
156
|
boolean isDo = state.getConfig().isDoVernaculars() && state.getConfig().isDoVernaculars();
|
157
|
return ! isDo ;
|
158
|
}
|
159
|
}
|