update annotations in webservice
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / dto / assembler / AnnotationAssembler.java
index 7a3daf8e3ab3f798d3d84b7e8dcadc25e04ac7ba..515c0efcc057d72b08e4c65603a2313a51cd0b37 100644 (file)
@@ -11,11 +11,15 @@ package eu.etaxonomy.cdm.remote.dto.assembler;
 
 import java.util.Enumeration;
 import java.util.Locale;
+import java.util.Set;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
 
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
 import eu.etaxonomy.cdm.model.common.Annotation;
+import eu.etaxonomy.cdm.remote.dto.AnnotationElementSTO;
 import eu.etaxonomy.cdm.remote.dto.AnnotationSTO;
 import eu.etaxonomy.cdm.remote.dto.AnnotationTO;
 
@@ -25,7 +29,7 @@ import eu.etaxonomy.cdm.remote.dto.AnnotationTO;
  * @version 1.0
  */
 @Component
-public class AnnotationAssembler extends AssemblerBase<AnnotationSTO, AnnotationTO, Annotation> {
+public class AnnotationAssembler extends AssemblerBase<AnnotationSTO, AnnotationTO, AnnotatableEntity> {
        private static Logger logger = Logger.getLogger(AnnotationAssembler.class);
 
 
@@ -33,7 +37,7 @@ public class AnnotationAssembler extends AssemblerBase<AnnotationSTO, Annotation
         * @see eu.etaxonomy.cdm.remote.dto.assembler.AssemblerBase#getSTO(eu.etaxonomy.cdm.model.common.CdmBase, java.util.Enumeration)
         */
        @Override
-       public AnnotationSTO getSTO(Annotation cdmObj, Enumeration<Locale> locales) {
+       public AnnotationSTO getSTO(AnnotatableEntity cdmObj, Enumeration<Locale> locales) {
                // TODO Auto-generated method stub
                return null;
        }
@@ -42,12 +46,34 @@ public class AnnotationAssembler extends AssemblerBase<AnnotationSTO, Annotation
         * @see eu.etaxonomy.cdm.remote.dto.assembler.AssemblerBase#getTO(eu.etaxonomy.cdm.model.common.CdmBase, java.util.Enumeration)
         */
        @Override
-       public AnnotationTO getTO(Annotation annotation, Enumeration<Locale> locales) {
+       public AnnotationTO getTO(AnnotatableEntity entity, Enumeration<Locale> locales) {
                
                AnnotationTO to = new AnnotationTO();
                
-               to.setText(annotation.getText());
+               to.setUuid(entity.getUuid().toString());
+               //
+               
+               Set<Annotation> annotations = entity.getAnnotations();
+               
+               for (Annotation annotation : annotations){
+                       to.addAnnotationElement(getAnnotationElementSTO(annotation));           
+               }
                
                return to;
        }
+       
+       private AnnotationElementSTO getAnnotationElementSTO(Annotation annotation){
+               AnnotationElementSTO sto = new AnnotationElementSTO();
+               
+               sto.setText(annotation.getText());
+               
+               sto.setCreated(annotation.getCreated());
+               
+               Person commentator = annotation.getCommentator();
+               if(commentator != null){
+                       //sto.setCommentator(annotation.getCommentator());
+               }
+                       
+               return sto;
+       }
 }