Merge branch 'release/4.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / DescriptionHelper.java
index 4a7133574d9d9ddbb11cf7feab11458bed5b68ef..b1f806cb4cc81b6e9be7b27dd584ef7db89405b6 100644 (file)
@@ -43,6 +43,7 @@ import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
 import eu.etaxonomy.cdm.model.description.Distribution;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
+import eu.etaxonomy.cdm.model.description.KeyStatement;
 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
 import eu.etaxonomy.cdm.model.description.QuantitativeData;
 import eu.etaxonomy.cdm.model.description.SpecimenDescription;
@@ -88,9 +89,11 @@ public class DescriptionHelper {
         */
        public static String getCache(DescriptionElementBase element,
                        Language language) {
-               
+
                String mainElementLabel= null;
                DescriptionBase<?> descr = element.getInDescription();
+               descr = CdmBase.deproxy(descr, DescriptionBase.class);
+
                if (descr != null){
                        if (descr.isInstanceOf(TaxonDescription.class)){
                                Taxon taxon = CdmBase.deproxy(descr, TaxonDescription.class).getTaxon();
@@ -109,10 +112,12 @@ public class DescriptionHelper {
                                }
                        }
                }
-               
+
+
                String cache = null;
                if (element instanceof TextData) {
-                       cache = ((TextData) element).getText(language);
+                       //cache = ((TextData) element).getText(language);
+                   cache = "Text Data";
                }
                if (element instanceof CommonTaxonName) {
                        cache = ((CommonTaxonName) element).getName();
@@ -205,19 +210,20 @@ public class DescriptionHelper {
         * @return a {@link java.lang.String} object.
         */
        public static String getObjectDescription(Object element) {
+           String resultString = null;
                if (element instanceof IdentifiableEntity) {
                        try{
-                               return ((IdentifiableEntity) element).getTitleCache();
+                           resultString = ((IdentifiableEntity) element).getTitleCache();
                        }catch(LazyInitializationException e){
                                String result = "No Session to initialize title cache for IdentifiableEntity";
                                MessagingUtils.error(DescriptionHelper.class, result, e);
-                               return "TODO: " + result;
+                               resultString = "TODO: " + result;
                        }
                }else if (element instanceof OriginalSourceBase) {
                        try{
                                OriginalSourceBase<?> originalSource = (OriginalSourceBase<?>) element;
 //                             ISourceable sourcedObject = originalSource.getSourcedObj();
-                               //due to #5743 the bidirectionality for sourced object had to be removed 
+                               //due to #5743 the bidirectionality for sourced object had to be removed
                                String sourceObjectTitle = "sourced object data not available (#5743)";
 //                             if(sourcedObject instanceof IIdentifiableEntity){
 //                                     sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
@@ -227,40 +233,48 @@ public class DescriptionHelper {
 //                                     throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
 //                             }
 
-                               return CdmUtils.concat("; ", new String[]{originalSource.getIdNamespace(), originalSource.getIdInSource(), sourceObjectTitle});
+                               resultString = CdmUtils.concat("; ", new String[]{originalSource.getIdNamespace(), originalSource.getIdInSource(), sourceObjectTitle});
                        }catch(LazyInitializationException e){
                                String result = "Error initializing title cache for ISourceable of an OriginalSourceBase";
                                MessagingUtils.error(DescriptionHelper.class, result, e);
-                               return "TODO: " + result;
+                               resultString = "TODO: " + result;
                        }
                }else if (element instanceof LanguageStringBase) {
-                       return ((LanguageStringBase) element).getText();
+                   resultString = ((LanguageStringBase) element).getText();
                }else if (element instanceof DescriptionElementBase) {
-                       return getCache((DescriptionElementBase) element);
+                   resultString = getCache((DescriptionElementBase) element);
                }else if (element instanceof RelationshipBase<?, ?, ?>) {
-                       return getCache((RelationshipBase<?, ?, ?>) element);
+                   resultString = getCache((RelationshipBase<?, ?, ?>) element);
                }else if (element instanceof TypeDesignationBase<?>) {
-                       return getCache((TypeDesignationBase<?>) element);
+                   resultString = getCache((TypeDesignationBase<?>) element);
                }else if (element instanceof HomotypicalGroup) {
-                       return getCache((HomotypicalGroup) element);
+                   resultString = getCache((HomotypicalGroup) element);
                }else if (element instanceof TaxonNode) {
-                       return getCache((TaxonNode) element);
+                   resultString = getCache((TaxonNode) element);
                }else if (element instanceof DeterminationEvent) {
-                       return getCache((DeterminationEvent) element);
+                   resultString = getCache((DeterminationEvent) element);
                }else if (element instanceof Marker) {
                        Marker marker = (Marker) element;
                        MarkerType type = marker.getMarkerType();
-                       return (type == null ? "- no marker type -" : marker.getMarkerType().getLabel()) + " (" + marker.getFlag() + ")";
+                       resultString = (type == null ? "- no marker type -" : marker.getMarkerType().getLabel()) + " (" + marker.getFlag() + ")";
                }else if (element instanceof User) {
                        User user = (User) element;
-                       return user.getUsername();
+                       resultString = user.getUsername();
                }else if (element instanceof Group) {
                        Group group = (Group) element;
-                       return group.getName();
-               }else{
+                       resultString = group.getName();
+               }else if (element instanceof KeyStatement) {
+            KeyStatement keyStatement = (KeyStatement) element;
+            resultString = getCache(keyStatement);
+        }else{
                        // TODO write return texts for HomotypicalGroup, etc.
-                       return element.toString();
+            resultString = element.toString();
+               }
+
+               if (resultString == null){
+                   resultString = element.toString();
                }
+               return resultString;
        }
 
 
@@ -278,8 +292,8 @@ public class DescriptionHelper {
                if (StringUtils.isBlank(taxonStr)){
                        taxonStr = "no or unlabled taxon";
                }
-                       
-                       
+
+
                //unit
                SpecimenOrObservationBase<?> unit = detEvent.getIdentifiedUnit();
                String unitStr;
@@ -291,7 +305,7 @@ public class DescriptionHelper {
                }else{
                        unitStr = "no unit";
                }
-               
+
                String result = CdmUtils.concat(" determined as ", unitStr, taxonStr);
 
                return result;
@@ -325,7 +339,7 @@ public class DescriptionHelper {
                        }
                }
                result = CdmUtils.concat(": ", result, parentStr);
-               
+
                return result;
        }
 
@@ -338,7 +352,7 @@ public class DescriptionHelper {
                if (designation.isInstanceOf(SpecimenTypeDesignation.class)){
                        to = ((SpecimenTypeDesignation)designation).getTypeSpecimen();
                }else if (designation.isInstanceOf(NameTypeDesignation.class)){
-                       to = ((NameTypeDesignation)designation).getTypeName();  
+                       to = ((NameTypeDesignation)designation).getTypeName();
                }else{
                        throw new RuntimeException("Type Designation class not supported: " +  designation.getClass().getName());
                }
@@ -365,7 +379,7 @@ public class DescriptionHelper {
                for (TaxonNameBase<?,?> name : from){
                        CdmUtils.concat(",", fromString, name.getTitleCache());
                }
-               String result = CdmUtils.concat(" ", new String[]{from == null ? null : fromString, 
+               String result = CdmUtils.concat(" ", new String[]{from == null ? null : fromString,
                                typeLabel, to == null? null : to.getTitleCache()});
                return result;
        }
@@ -416,11 +430,11 @@ public class DescriptionHelper {
                if (StringUtils.isBlank(typeLabel)){
                        typeLabel = "->";
                }
-               String result = CdmUtils.concat(" ", new String[]{from == null ? null : from.getTitleCache(), 
+               String result = CdmUtils.concat(" ", new String[]{from == null ? null : from.getTitleCache(),
                                typeLabel, to == null? null : to.getTitleCache()});
                return result;
        }
-       
+
 
        private static String getCache(HomotypicalGroup hg) {
                String result = "";
@@ -433,6 +447,14 @@ public class DescriptionHelper {
                return result;
        }
 
+       private static String getCache(KeyStatement ks) {
+        String result = "";
+
+        result = "KeyStatement";
+
+        return result;
+    }
+
        /**
         * <p>getObjectClassname</p>
         *