fix #9617 rename ICNB to ICNP in cdmlib
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / specimen / SpecimenImportBase.java
index 15cf69b876dc6abc49f2147cd010c5edef8b0518..2eb7ea22fc2e6afb4a524fd29c22a1fcb4a5ec5a 100755 (executable)
@@ -11,6 +11,7 @@ package eu.etaxonomy.cdm.io.specimen;
 
 
 import java.util.ArrayList;
+import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -38,6 +39,7 @@ import eu.etaxonomy.cdm.model.common.IdentifiableSource;
 import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
+import eu.etaxonomy.cdm.model.description.DescriptionType;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
@@ -287,7 +289,7 @@ public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STA
                    }
                }
                else if (state.getDataHolder().getNomenclatureCode() != null && (state.getDataHolder().getNomenclatureCode().toString().equals("Bacterial") || state.getDataHolder().getNomenclatureCode().toString().contains("ICBN"))) {
-                   taxonName = (TaxonName)nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNB, rank);
+                   taxonName = (TaxonName)nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNP, rank);
                    if (taxonName.hasProblem()) {
                        problem = true;
                    }
@@ -446,7 +448,7 @@ public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STA
                        return taxonName;
                    }
                }
-               else if (state.getDataHolder().getNomenclatureCode().equals("Bacterial") || state.getDataHolder().getNomenclatureCode().equals(NomenclaturalCode.ICNB.getUuid())) {
+               else if (state.getDataHolder().getNomenclatureCode().equals("Bacterial") || state.getDataHolder().getNomenclatureCode().equals(NomenclaturalCode.ICNP.getUuid())) {
                    TaxonName taxonName = TaxonNameFactory.NewBacterialInstance(null);
                    taxonName.setFullTitleCache(fullName, true);
                    taxonName.setGenusOrUninomial(getFromMap(atomisedMap, "Genus"));
@@ -478,7 +480,7 @@ public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STA
                        taxonName.setBasionymAuthorship(team);
                    }
                    if (taxonName.hasProblem()) {
-                       logger.info("pb ICNB");
+                       logger.info("pb ICNP");
                        problem = true;
                    }
                    else {
@@ -1203,30 +1205,36 @@ public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STA
 
                TaxonDescription taxonDescription = null;
                Set<TaxonDescription> descriptions= taxon.getDescriptions();
-               if (state.getDescriptionPerTaxon(taxon.getUuid()) != null){
-                   taxonDescription = state.getDescriptionPerTaxon(taxon.getUuid());
+               if (state.getIndividualsAssociationDescriptionPerTaxon(taxon.getUuid()) != null){
+                   taxonDescription = state.getIndividualsAssociationDescriptionPerTaxon(taxon.getUuid());
                }
               if (taxonDescription == null && !descriptions.isEmpty() && state.getConfig().isReuseExistingDescriptiveGroups()){
-                  taxonDescription = descriptions.iterator().next();
+                  for (TaxonDescription desc: descriptions){
+                      if (desc.getTypes().contains(DescriptionType.INDIVIDUALS_ASSOCIATION)){
+                          taxonDescription = desc;
+                          break;
+                      }
+                  }
               }
 
               if (taxonDescription == null){
                    taxonDescription = TaxonDescription.NewInstance(taxon, false);
+                   taxonDescription.setTypes(EnumSet.of(DescriptionType.INDIVIDUALS_ASSOCIATION));
                    if(sourceNotLinkedToElement(taxonDescription,state.getRef(),null)) {
                        taxonDescription.addSource(OriginalSourceType.Import, null, null, state.getRef(), null);
                    }
-                   state.setDescriptionGroup(taxonDescription);
+                   state.setIndividualsAssociationDescriptionPerTaxon(taxonDescription);
                    taxon.addDescription(taxonDescription);
                }
 
                //PREPARE REFERENCE QUESTIONS
 
-               Map<String,OriginalSourceBase<?>> sourceMap = new HashMap<String, OriginalSourceBase<?>>();
+               Map<String,OriginalSourceBase> sourceMap = new HashMap<>();
 
                List<IdentifiableSource> issTmp = new ArrayList<>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
                List<DescriptionElementSource> issTmp2 = new ArrayList<>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
 
-               Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
+               Set<OriginalSourceBase> osbSet = new HashSet<>();
                if(issTmp2!=null) {
                    osbSet.addAll(issTmp2);
                }
@@ -1242,7 +1250,7 @@ public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STA
                 taxonDescription.addSource(OriginalSourceType.Import,null, null, state.getRef(), null);
             }
 
-               state.setDescriptionGroup(taxonDescription);
+               state.setIndividualsAssociationDescriptionPerTaxon(taxonDescription);
 
                IndividualsAssociation indAssociation = IndividualsAssociation.NewInstance();
                Feature feature = makeFeature(state.getDerivedUnitBase());
@@ -1322,7 +1330,7 @@ public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STA
                return true;
            }
 
-           private <T extends OriginalSourceBase<?>> boolean  sourceNotLinkedToElement(ISourceable<T> sourcable, Reference reference, String microReference) {
+           private <T extends OriginalSourceBase> boolean  sourceNotLinkedToElement(ISourceable<T> sourcable, Reference reference, String microReference) {
                Set<T> linkedSources = sourcable.getSources();
                for (T is:linkedSources){
                    Reference unitReference = is.getCitation();
@@ -1392,8 +1400,8 @@ public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STA
             * @param sourceMap
             * @param osbSet
             */
-           protected void addToSourceMap(Map<String, OriginalSourceBase<?>> sourceMap, Set<OriginalSourceBase> osbSet) {
-               for( OriginalSourceBase<?> osb:osbSet) {
+           protected void addToSourceMap(Map<String, OriginalSourceBase> sourceMap, Set<OriginalSourceBase> osbSet) {
+               for( OriginalSourceBase osb:osbSet) {
                    if(osb.getCitation()!=null && osb.getCitationMicroReference() !=null  && !osb.getCitationMicroReference().isEmpty()) {
                        try{
                            sourceMap.put(osb.getCitation().getTitleCache()+ "---"+osb.getCitationMicroReference(),osb);