Revision 51688d00
Added by Andreas Müller almost 7 years ago
cdm-pesi/src/main/java/eu/etaxonomy/cdm/io/pesi/erms/ErmsTaxonRelationImport.java | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Copyright (C) 2007 EDIT |
3 |
* European Distributed Institute of Taxonomy
|
|
3 |
* European Distributed Institute of Taxonomy |
|
4 | 4 |
* http://www.e-taxonomy.eu |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
... | ... | |
26 | 26 |
import eu.etaxonomy.cdm.io.common.mapping.ICheckIgnoreMapper; |
27 | 27 |
import eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper; |
28 | 28 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
29 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
|
29 |
import eu.etaxonomy.cdm.model.name.TaxonName; |
|
30 | 30 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase; |
31 | 31 |
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType; |
32 | 32 |
|
... | ... | |
38 | 38 |
public class ErmsTaxonRelationImport extends ErmsImportBase<TaxonBase<?>> implements ICheckIgnoreMapper{ |
39 | 39 |
@SuppressWarnings("unused") |
40 | 40 |
private static final Logger logger = Logger.getLogger(ErmsTaxonRelationImport.class); |
41 |
|
|
41 |
|
|
42 | 42 |
private DbImportMapping<ErmsImportState, ErmsImportConfigurator> mapping; |
43 |
|
|
43 |
|
|
44 | 44 |
private static final String pluralString = "taxon relations"; |
45 | 45 |
private static final String dbTableName = "tu"; |
46 | 46 |
|
47 | 47 |
private static final Class<?> cdmTargetClass = TaxonBase.class; |
48 |
|
|
48 |
|
|
49 | 49 |
private ErmsImportState state; //ERMS import will never run in more then one instance |
50 |
|
|
50 |
|
|
51 | 51 |
public ErmsTaxonRelationImport(){ |
52 | 52 |
super(pluralString, dbTableName, cdmTargetClass); |
53 | 53 |
} |
... | ... | |
57 | 57 |
protected DbImportMapping<ErmsImportState, ErmsImportConfigurator> getMapping() { |
58 | 58 |
if (mapping == null){ |
59 | 59 |
mapping = new DbImportMapping<ErmsImportState, ErmsImportConfigurator>(); |
60 |
|
|
60 |
|
|
61 | 61 |
mapping.addMapper(DbImportTaxIncludedInMapper.NewInstance("id", TAXON_NAMESPACE, "parentId", TAXON_NAMESPACE, "accParentId", TAXON_NAMESPACE, null));//there is only one tree |
62 |
|
|
62 |
|
|
63 | 63 |
TaxonRelationshipType taxonRelationshipType = getTaxonRelationshipType(state, ErmsTransformer.uuidTaxRelTypeIsTaxonSynonymOf, "is taxon synonym of", "is synonym of relation used by synonym that are of class Taxon as they can not be handled differently", null, null); |
64 |
mapping.addMapper(DbImportSynonymMapper.NewInstance("id", "tu_acctaxon", TAXON_NAMESPACE, null, taxonRelationshipType));
|
|
64 |
mapping.addMapper(DbImportSynonymMapper.NewInstance("id", "tu_acctaxon", TAXON_NAMESPACE, null, taxonRelationshipType)); |
|
65 | 65 |
mapping.addMapper(DbImportNameTypeDesignationMapper.NewInstance("id", "tu_typetaxon", ErmsTaxonImport.NAME_NAMESPACE, "tu_typedesignationstatus")); |
66 | 66 |
// mapping.addMapper(DbNotYetImplementedMapper.NewInstance("tu_acctaxon")); |
67 | 67 |
} |
68 | 68 |
return mapping; |
69 | 69 |
} |
70 |
|
|
70 |
|
|
71 | 71 |
|
72 | 72 |
/* (non-Javadoc) |
73 | 73 |
* @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getRecordQuery(eu.etaxonomy.cdm.io.erms.ErmsImportConfigurator) |
74 | 74 |
*/ |
75 |
protected String getRecordQuery(ErmsImportConfigurator config) { |
|
75 |
@Override |
|
76 |
protected String getRecordQuery(ErmsImportConfigurator config) { |
|
76 | 77 |
//TODO get automatic by second path mappers |
77 | 78 |
String selectAttributes = " myTaxon.id, myTaxon.tu_parent, myTaxon.tu_typetaxon, myTaxon.tu_typedesignation, " + |
78 |
" myTaxon.tu_acctaxon, myTaxon.tu_status, parent.tu_status AS parentStatus, parent.id AS parentId, " +
|
|
79 |
" accParent.tu_status AS accParentStatus, accParent.id AS accParentId ";
|
|
80 |
String strRecordQuery =
|
|
81 |
" SELECT " + selectAttributes +
|
|
79 |
" myTaxon.tu_acctaxon, myTaxon.tu_status, parent.tu_status AS parentStatus, parent.id AS parentId, " + |
|
80 |
" accParent.tu_status AS accParentStatus, accParent.id AS accParentId "; |
|
81 |
String strRecordQuery = |
|
82 |
" SELECT " + selectAttributes + |
|
82 | 83 |
" FROM tu AS myTaxon LEFT OUTER JOIN " + |
83 | 84 |
" tu AS accTaxon ON myTaxon.tu_acctaxon = accTaxon.id LEFT OUTER JOIN " + |
84 |
" tu AS accParent RIGHT OUTER JOIN " +
|
|
85 |
" tu AS accParent RIGHT OUTER JOIN " + |
|
85 | 86 |
" tu AS parent ON accParent.id = parent.tu_acctaxon ON myTaxon.tu_parent = parent.id " + |
86 | 87 |
" WHERE ( myTaxon.id IN (" + ID_LIST_TOKEN + ") )"; |
87 | 88 |
return strRecordQuery; |
88 | 89 |
} |
89 |
|
|
90 |
|
|
90 | 91 |
|
91 | 92 |
@Override |
92 | 93 |
protected void doInvoke(ErmsImportState state) { |
... | ... | |
100 | 101 |
Class<?> cdmClass; |
101 | 102 |
Set<String> idSet; |
102 | 103 |
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<Object, Map<String, ? extends CdmBase>>(); |
103 |
|
|
104 |
|
|
104 | 105 |
try{ |
105 | 106 |
Set<String> taxonIdSet = new HashSet<String>(); |
106 | 107 |
Set<String> nameIdSet = new HashSet<String>(); |
... | ... | |
110 | 111 |
handleForeignKey(rs, taxonIdSet, "tu_acctaxon"); |
111 | 112 |
handleForeignKey(rs, taxonIdSet, "id"); |
112 | 113 |
handleForeignKey(rs, nameIdSet, "tu_typetaxon"); |
113 |
handleForeignKey(rs, nameIdSet, "id");
|
|
114 |
handleForeignKey(rs, nameIdSet, "id"); |
|
114 | 115 |
} |
115 |
|
|
116 |
|
|
116 | 117 |
//name map |
117 | 118 |
nameSpace = ErmsTaxonImport.NAME_NAMESPACE; |
118 |
cdmClass = TaxonNameBase.class;
|
|
119 |
cdmClass = TaxonName.class; |
|
119 | 120 |
idSet = nameIdSet; |
120 |
Map<String, TaxonNameBase<?,?>> nameMap = (Map<String, TaxonNameBase<?,?>>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
121 |
Map<String, TaxonName> nameMap = (Map<String, TaxonName>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace);
|
|
121 | 122 |
result.put(nameSpace, nameMap); |
122 |
|
|
123 |
|
|
123 |
|
|
124 |
|
|
124 | 125 |
//taxon map |
125 | 126 |
nameSpace = ErmsTaxonImport.TAXON_NAMESPACE; |
126 | 127 |
cdmClass = TaxonBase.class; |
... | ... | |
133 | 134 |
} |
134 | 135 |
return result; |
135 | 136 |
} |
136 |
|
|
137 |
|
|
137 | 138 |
|
138 | 139 |
/* (non-Javadoc) |
139 | 140 |
* @see eu.etaxonomy.cdm.io.erms.ICheckIgnoreMapper#checkIgnoreMapper(eu.etaxonomy.cdm.io.common.mapping.IDbImportMapper, java.sql.ResultSet) |
140 | 141 |
*/ |
141 |
public boolean checkIgnoreMapper(IDbImportMapper mapper, ResultSet rs) throws SQLException{ |
|
142 |
@Override |
|
143 |
public boolean checkIgnoreMapper(IDbImportMapper mapper, ResultSet rs) throws SQLException{ |
|
142 | 144 |
boolean result = false; |
143 | 145 |
if (mapper instanceof DbImportTaxIncludedInMapper){ |
144 | 146 |
//old |
... | ... | |
146 | 148 |
// if (tu_status != 1){ |
147 | 149 |
// result = true; |
148 | 150 |
// } |
149 |
|
|
151 |
|
|
150 | 152 |
int id = rs.getInt("id"); |
151 | 153 |
if (state.getAcceptedTaxaKeys().contains(id)){ |
152 | 154 |
return false; |
... | ... | |
161 | 163 |
// }else{ |
162 | 164 |
// return false; |
163 | 165 |
// }t.tu_acctaxon <> t.id |
164 |
|
|
166 |
|
|
165 | 167 |
int id = rs.getInt("id"); |
166 | 168 |
Object accTaxonId = rs.getObject("tu_acctaxon"); |
167 | 169 |
if (accTaxonId == null){ |
... | ... | |
178 | 180 |
} |
179 | 181 |
return result; |
180 | 182 |
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
183 | 185 |
@Override |
184 | 186 |
protected boolean doCheck(ErmsImportState state){ |
185 | 187 |
// IOValidator<ErmsImportState> validator = new ErmsTaxonImportValidator(); |
186 | 188 |
// return validator.validate(state); |
187 | 189 |
return true; |
188 | 190 |
} |
189 |
|
|
191 |
|
|
190 | 192 |
@Override |
191 | 193 |
protected boolean isIgnore(ErmsImportState state){ |
192 | 194 |
return ! state.getConfig().isDoRelTaxa(); |
Also available in: Unified diff
ref #6368 , ref #6671, ref #6630 adapt pesi to no taxon name model