+ checkNameConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, hybString, name);
+ }
+
+ private NonViralName<?> importName(RedListGefaesspflanzenImportState state, ResultSet rs, Set<TaxonNameBase> namesToSave) throws SQLException {
+
+ long id = rs.getLong(RedListUtil.NAMNR);
+ String taxNameString = rs.getString(RedListUtil.TAXNAME);
+ String rangString = rs.getString(RedListUtil.RANG);
+ String ep1String = rs.getString(RedListUtil.EPI1);
+ String ep2String = rs.getString(RedListUtil.EPI2);
+ String ep3String = rs.getString(RedListUtil.EPI3);
+ String nomZusatzString = rs.getString(RedListUtil.NOM_ZUSATZ);
+ String hybString = rs.getString(RedListUtil.HYB);
+ String formelString = rs.getString(RedListUtil.FORMEL);
+
+ if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
+ RedListUtil.logMessage(id, "No name found!", logger);
+ }
+
+ NonViralName<?> name = null;
+ Rank rank = makeRank(id, state, rangString, ep3String!=null);
+ //cultivar
+ if(rank!= null && rank.equals(Rank.CULTIVAR())){
+ CultivarPlantName cultivar = CultivarPlantName.NewInstance(rank);
+ cultivar.setGenusOrUninomial(ep1String);
+ cultivar.setSpecificEpithet(ep2String);
+ cultivar.setCultivarName(ep3String);
+ name = cultivar;
+ }
+ //botanical names
+ else{
+ name = BotanicalName.NewInstance(rank);
+
+ //ep1 should always be present
+ if(CdmUtils.isBlank(ep1String)){
+ RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
+ }
+ name.setGenusOrUninomial(ep1String);
+ if(CdmUtils.isNotBlank(ep2String)){
+ if(rank!=null && rank.isInfraGenericButNotSpeciesGroup()){
+ name.setInfraGenericEpithet(ep2String);
+ }
+ else{
+ name.setSpecificEpithet(ep2String);
+ }
+ }
+ if(CdmUtils.isNotBlank(ep3String)){
+ name.setInfraSpecificEpithet(ep3String);
+ }
+
+
+ //nomenclatural status
+ if(CdmUtils.isNotBlank(nomZusatzString)){
+ NomenclaturalStatusType statusType = makeNomenclaturalStatus(id, state, nomZusatzString);
+ if(statusType!=null){
+ NomenclaturalStatus status = NomenclaturalStatus.NewInstance(statusType);
+ //special case for invalid names where the DB entry contains
+ //additional information in brackets e.g. "nom. inval. (sine basion.)"
+ if(statusType.equals(NomenclaturalStatusType.INVALID())){
+ Pattern pattern = Pattern.compile("\\((.*?)\\)");
+ Matcher matcher = pattern.matcher(nomZusatzString);
+ if (matcher.find()){
+ status.setRuleConsidered(matcher.group(1));
+ }
+ }
+ name.addStatus(status);
+ }
+ }
+ //hybrid
+ if(CdmUtils.isNotBlank(hybString)){
+ //save hybrid formula
+ if(CdmUtils.isNotBlank(formelString)){
+ Annotation annotation = Annotation.NewDefaultLanguageInstance(formelString);
+ annotation.setAnnotationType(AnnotationType.TECHNICAL());
+ name.addAnnotation(annotation);
+ }
+ //more than two hybrids not yet handled by name parser
+ //TODO: use parser when implemented to fully support hybrids
+ if(taxNameString.split(RedListUtil.HYB_SIGN).length>2){
+ name = BotanicalName.NewInstance(rank);
+ name.setTitleCache(taxNameString, true);
+ }
+ else if(hybString.equals(RedListUtil.HYB_X)){
+ name.setBinomHybrid(true);
+ }
+ else if(hybString.equals(RedListUtil.HYB_G)){
+ name.setMonomHybrid(true);
+ }
+ else if(hybString.equals(RedListUtil.HYB_XF)){
+ name.setHybridFormula(true);
+ if(ep1String.contains(RedListUtil.HYB_SIGN)){
+ RedListUtil.logMessage(id, "EPI1 has hybrid signs but with flag: "+RedListUtil.HYB_XF, logger);
+ }
+ else if(ep2String.contains(RedListUtil.HYB_SIGN)){
+ String[] split = ep2String.split(RedListUtil.HYB_SIGN);
+ String hybridFormula1 = ep1String+" "+split[0].trim();
+ String hybridFormula2 = ep1String+" "+split[1].trim();
+ //check if the specific epithets are from the same genus or not like e.g. EPI2 = pratensis × Lolium multiflorum
+ String[] secondHybrid = split[1].trim().split(" ");
+ if(secondHybrid.length>1 && secondHybrid[0].matches("[A-Z].*")){
+ hybridFormula2 = split[1];
+ }
+ if(CdmUtils.isNotBlank(ep3String)){
+ hybridFormula1 += " "+ep3String;
+ hybridFormula2 += " "+ep3String;
+ }
+ String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
+ name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
+ }
+ else if(ep3String.contains(RedListUtil.HYB_SIGN)){
+ String[] split = ep3String.split(RedListUtil.HYB_SIGN);
+ String hybridFormula1 = ep1String+" "+ep2String+" "+split[0];
+ String hybridFormula2 = ep1String+" "+ep2String+" "+split[1];
+ String fullFormula = hybridFormula1+" "+RedListUtil.HYB_SIGN+" "+hybridFormula2;
+ name = NonViralNameParserImpl.NewInstance().parseFullName(fullFormula, NomenclaturalCode.ICNAFP, rank);
+ }
+ }
+ else if(hybString.equals(RedListUtil.HYB_N)){
+ name = NonViralNameParserImpl.NewInstance().parseFullName(taxNameString, NomenclaturalCode.ICNAFP, rank);
+ }
+ else if(hybString.equals(RedListUtil.HYB_GF)){
+ if(ep1String.contains(RedListUtil.HYB_SIGN)){
+ name = NonViralNameParserImpl.NewInstance().parseFullName(ep1String, NomenclaturalCode.ICNAFP, rank);
+ }
+ else{
+ RedListUtil.logMessage(id, "HYB is "+hybString+" but "+RedListUtil.HYB+" does not contain "+RedListUtil.HYB_SIGN, logger);
+ }
+ }
+ else if(hybString.equals(RedListUtil.HYB_XS)){
+ //nothing to do
+ }
+ else{
+ logger.error("HYB value "+hybString+" not yet handled");
+ }
+ }
+ }
+ //add source
+ ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
+
+ namesToSave.add(name);
+ return name;
+ }
+
+ private void checkNameConsistency(long id, String nomZusatzString, String taxZusatzString,
+ String zusatzString, String authorString, String hybString, NonViralName<?> name) {