a little bit documentation
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / DescriptionController.java
index 1608c52ef3ada2eb6928b4bdfed1eea0448b5035..bcaf226a2618e03ed161a5ccd10f826a949e8175 100644 (file)
@@ -25,24 +25,28 @@ import org.springframework.web.bind.annotation.InitBinder;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.servlet.ModelAndView;
 
 import eu.etaxonomy.cdm.api.service.IDescriptionService;
 import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
 import eu.etaxonomy.cdm.api.service.pager.Pager;
+
 import eu.etaxonomy.cdm.model.common.Annotation;
 import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.Representation;
+import eu.etaxonomy.cdm.model.description.CategoricalData;
 import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.cdm.model.description.StateData;
 import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.description.TextData;
 import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
+import eu.etaxonomy.cdm.persistence.query.MatchMode;
+import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;
 import eu.etaxonomy.cdm.remote.editor.NamedAreaLevelPropertyEditor;
 import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
-import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
 import eu.etaxonomy.cdm.remote.editor.UuidList;
 import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
 
@@ -73,6 +77,17 @@ public class DescriptionController extends BaseController<DescriptionBase, IDesc
                 "root.children.children.feature.representations",
             });
 
+
+
+    protected static final List<String> TAXONDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
+            "$",
+            "elements.$",
+            "elements.sources.citation.authorTeam",
+            "elements.sources.nameUsedInSource.originalNameString",
+            "elements.multilanguageText",
+            "elements.media",
+    });
+
     @InitBinder
     @Override
     public void initBinder(WebDataBinder binder) {
@@ -105,13 +120,28 @@ public class DescriptionController extends BaseController<DescriptionBase, IDesc
         return featureTree;
     }
 
+    @RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}", method = RequestMethod.GET)
+    public ModelAndView doGetDescriptionElement(
+            @PathVariable("descriptionelement_uuid") UUID uuid,
+            HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+
+        ModelAndView mv = new ModelAndView();
+        logger.info("doGetDescriptionElement() - " + request.getServletPath());
+        DescriptionElementBase element = service.getDescriptionElementByUuid(uuid);
+        if(element == null) {
+            HttpStatusMessage.UUID_NOT_FOUND.send(response);
+        }
+        mv.addObject(element);
+        return mv;
+    }
 
     @RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}/annotations", method = RequestMethod.GET)
-    public Pager<Annotation> getAnnotations(
+    public Pager<Annotation> doGetDescriptionElementAnnotations(
             @PathVariable("descriptionelement_uuid") UUID uuid,
             HttpServletRequest request,
             HttpServletResponse response) throws IOException {
-        logger.info("getAnnotations() - " + request.getServletPath());
+        logger.info("doGetDescriptionElementAnnotations() - " + request.getServletPath());
         DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
         if(annotatableEntity == null){
             HttpStatusMessage.UUID_INVALID.send(response);
@@ -123,6 +153,59 @@ public class DescriptionController extends BaseController<DescriptionBase, IDesc
         return annotations;
     }
 
+    @RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}/states", method = RequestMethod.GET)
+    public ModelAndView doGetDescriptionElementStates(
+            @PathVariable("descriptionelement_uuid") UUID uuid,
+            HttpServletRequest request,
+            HttpServletResponse response) throws IOException {
+        logger.info("doGetDescriptionElementStates() - " + request.getServletPath());
+
+        ModelAndView mv = new ModelAndView();
+
+        DescriptionElementBase descriptionElement = service.loadDescriptionElement(uuid,
+                Arrays.asList( new String[]{
+                        "states.state.representations",
+                        "modifiers",
+                        "modifyingText"
+                        } ));
+        if(descriptionElement == null){
+            HttpStatusMessage.UUID_INVALID.send(response);
+            // method will exit here
+            return null;
+        }
+
+        if(descriptionElement instanceof CategoricalData){
+
+        }
+        List<StateData> states = ((CategoricalData)descriptionElement).getStates();
+        mv.addObject(states);
+        return mv;
+    }
+
+
+
+    @RequestMapping(value = "/descriptionElement/find", method = RequestMethod.GET)
+    public Pager<DescriptionElementBase> doFindDescriptionElements(
+            @RequestParam(value = "query", required = true) String queryString,
+            @RequestParam(value = "type", required = false) Class type,
+            @RequestParam(value = "pageSize", required = false) Integer pageSize,
+            @RequestParam(value = "pageNumber", required = false) Integer pageNumber,
+            @RequestParam(value = "matchMode", required = false) MatchMode matchMode,
+            HttpServletRequest request,
+            HttpServletResponse response
+            )
+             throws IOException {
+
+        logger.info("doFindDescriptionElements : " + request.getRequestURI() + "?" + request.getQueryString() );
+
+        PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);
+        pagerParams.normalizeAndValidate(response);
+
+        Pager<DescriptionElementBase> pager = service.searchElements(type, queryString, pageSize, pageNumber, null, DEFAULT_INIT_STRATEGY);
+
+        return pager;
+    }
+
     /*
     @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
     public NamedAreaTree doGetOrderedDistributions(
@@ -172,16 +255,12 @@ public class DescriptionController extends BaseController<DescriptionBase, IDesc
                 (TaxonDescription)description,
                 languages,
                 ", ");
-
         TextData textData = TextData.NewInstance(Feature.DESCRIPTION());
         textData.putText(Language.DEFAULT(), naturalLanguageDescription);
-
         mv.addObject(textData);
-
         return mv;
     }
 
-
     @RequestMapping(value = "/description/{uuid}/hasStructuredData", method = RequestMethod.GET)
     public ModelAndView doHasStructuredData(
             @PathVariable("uuid") UUID uuid,