40 |
40 |
import eu.etaxonomy.cdm.model.taxon.Classification;
|
41 |
41 |
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
42 |
42 |
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
|
43 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
43 |
44 |
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
44 |
45 |
|
45 |
46 |
|
... | ... | |
53 |
54 |
|
54 |
55 |
private static final String pluralString = "species";
|
55 |
56 |
private static final String dbTableName = "[tblPESIfungi-IFdata]";
|
56 |
|
private final Set<UUID> infraspecificTaxaUUIDs = new HashSet<UUID>();
|
|
57 |
|
57 |
58 |
|
58 |
59 |
public IndexFungorumSpeciesImport(){
|
59 |
60 |
super(pluralString, dbTableName, null);
|
... | ... | |
89 |
90 |
@Override
|
90 |
91 |
protected void doInvoke(IndexFungorumImportState state){
|
91 |
92 |
System.out.println("start make " + getPluralString() + " ...");
|
92 |
|
IndexFungorumImportConfigurator config = state.getConfig();
|
93 |
|
Source source = config.getSource();
|
94 |
|
|
95 |
93 |
super.doInvoke(state);
|
96 |
|
Classification classification = getClassification(state);
|
97 |
|
List<TaxonBase> infraspecificTaxa = new ArrayList<TaxonBase>();
|
98 |
|
for (UUID uuid: infraspecificTaxaUUIDs){
|
99 |
|
infraspecificTaxa.add(getTaxonService().load(uuid));
|
100 |
|
}
|
101 |
|
|
102 |
|
System.out.println("create infraspecific - specific relationship: " + infraspecificTaxa.size() + " taxa");
|
103 |
|
for (TaxonBase infraspecificTaxon: infraspecificTaxa){
|
104 |
|
HibernateProxyHelper.deproxy(infraspecificTaxon);
|
105 |
|
TaxonNameBase name = infraspecificTaxon.getName();
|
106 |
|
|
107 |
|
UUID uuid = getNameService().saveOrUpdate(name);
|
108 |
|
String parentNameString = getParentNameInfraSpecific(name);
|
109 |
|
System.out.println("Parent name string: " + parentNameString);
|
110 |
|
MatchingTaxonConfigurator matchingConfig = new MatchingTaxonConfigurator();
|
111 |
|
matchingConfig.setTaxonNameTitle(parentNameString);
|
112 |
|
List<String> propertyPaths = new ArrayList<String>();
|
113 |
|
propertyPaths.add("taxonNodes.*");
|
114 |
|
propertyPaths.add("taxonNodes.classification");
|
115 |
|
propertyPaths.add("taxonNodes.childNodes.*");
|
116 |
|
propertyPaths.add("taxonNodes.childNodes.taxon.*");
|
117 |
|
propertyPaths.add("taxonNodes.parent.*");
|
118 |
|
propertyPaths.add("taxonNodes.parent.taxon.*");
|
119 |
|
matchingConfig.setPropertyPath(propertyPaths);
|
120 |
|
List<TaxonBase> potentialParents = getTaxonService().findTaxaByName(matchingConfig);
|
121 |
|
//Taxon.class, parentNameString + "sec. ", MatchMode.BEGINNING, , pageSize, pageNumber, orderHints, propertyPaths)
|
122 |
|
//.searchNames(String uninomial,String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
|
123 |
|
if (potentialParents.size()>1){
|
124 |
|
for (TaxonBase potentialParent:potentialParents){
|
125 |
|
if (potentialParent.getTitleCache().equals(parentNameString + " sec*")){
|
126 |
|
classification.addParentChild((Taxon)potentialParent, (Taxon)infraspecificTaxon, null, null);
|
127 |
|
}
|
128 |
|
}
|
129 |
|
}else if (!potentialParents.isEmpty()){
|
130 |
|
Taxon parent = HibernateProxyHelper.deproxy(potentialParents.get(0), Taxon.class);
|
131 |
|
Taxon child = (Taxon)getTaxonService().load(infraspecificTaxon.getUuid(), propertyPaths);
|
132 |
|
classification.addParentChild(parent, child, null, null);
|
133 |
|
} else{
|
134 |
|
System.out.println("No parent for: " + name.getTitleCache());
|
135 |
|
}
|
136 |
|
getTaxonService().saveOrUpdate(infraspecificTaxon);
|
137 |
|
}
|
|
94 |
|
|
95 |
|
138 |
96 |
|
139 |
97 |
|
140 |
98 |
}
|
... | ... | |
188 |
146 |
//save
|
189 |
147 |
|
190 |
148 |
UUID uuidTaxon = getTaxonService().saveOrUpdate(taxon);
|
191 |
|
getNameService().saveOrUpdate(name);
|
|
149 |
//getNameService().saveOrUpdate(name);
|
192 |
150 |
if (name.isInfraSpecific()){
|
193 |
|
infraspecificTaxaUUIDs.add(uuidTaxon);
|
|
151 |
state.getInfraspecificTaxaUUIDs().add(uuidTaxon);
|
194 |
152 |
}
|
195 |
153 |
|
196 |
154 |
}
|
... | ... | |
206 |
164 |
}
|
207 |
165 |
|
208 |
166 |
|
209 |
|
/**
|
210 |
|
* @param taxon
|
211 |
|
* @return
|
212 |
|
*/
|
213 |
|
private String getParentNameInfraSpecific(TaxonNameBase taxonName){
|
214 |
|
NonViralName<NonViralName> name = HibernateProxyHelper.deproxy(taxonName, NonViralName.class);
|
215 |
|
String parentName = name.getGenusOrUninomial() + " " + name.getSpecificEpithet();
|
216 |
|
|
217 |
|
return parentName;
|
218 |
|
}
|
|
167 |
|
219 |
168 |
|
220 |
169 |
|
221 |
170 |
|