-// $Id$\r
-/**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
-\r
-package eu.etaxonomy.cdm.remote.controller;\r
-\r
-import java.io.IOException;\r
-import java.util.Arrays;\r
-import java.util.List;\r
-import java.util.UUID;\r
-\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-\r
-import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.stereotype.Controller;\r
-import org.springframework.web.bind.annotation.RequestMapping;\r
-import org.springframework.web.bind.annotation.RequestMethod;\r
-\r
-import eu.etaxonomy.cdm.api.service.AnnotatableServiceBase;\r
-import eu.etaxonomy.cdm.api.service.IDescriptionService;\r
-import eu.etaxonomy.cdm.api.service.IFeatureTreeService;\r
-import eu.etaxonomy.cdm.api.service.pager.Pager;\r
-import eu.etaxonomy.cdm.model.description.DescriptionBase;\r
-import eu.etaxonomy.cdm.model.description.FeatureTree;\r
-import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
-import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
-import eu.etaxonomy.cdm.persistence.dao.common.IAnnotatableDao;\r
-\r
-/**\r
- * TODO write controller documentation\r
- * \r
- * @author a.kohlbecker\r
- * @date 24.03.2009\r
- */\r
-\r
-@Controller\r
-@RequestMapping(value = {"/*/description/*","/*/description/*/annotation", "/*/featuretree/*"})\r
-public class DescriptionController extends AnnotatableController<DescriptionBase, IDescriptionService>\r
-{\r
- @Autowired\r
- private IFeatureTreeService featureTreeService;\r
- \r
- public DescriptionController(){\r
- super();\r
- setUuidParameterPattern("^/(?:[^/]+)/(?:[^/]+)/([^/?#&\\.]+).*");\r
- }\r
- \r
- private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(\r
- new String[]{\r
- "representations",\r
- "root.feature.representations",\r
- "root.children.feature.representations",\r
- //TODO implement recursive INIT_STRATEGY for children e.g: \r
- // "root.children{<children;limit=0}.feature.representations",\r
- });\r
- \r
- \r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)\r
- */\r
- @Autowired\r
- @Override\r
- public void setService(IDescriptionService service) {\r
- this.service = service;\r
- }\r
- \r
- /**\r
- * TODO write controller method documentation\r
- * \r
- * @param request\r
- * @param response\r
- * @return\r
- * @throws IOException\r
- */\r
- @RequestMapping(\r
- value = {"/*/featuretree/*"},\r
- method = RequestMethod.GET)\r
- public FeatureTree doGetFeatureTree(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- UUID featureTreeUuid = readValueUuid(request, null);\r
- FeatureTree featureTree = featureTreeService.load(featureTreeUuid, FEATURETREE_INIT_STRATEGY);\r
- if(featureTree == null){\r
- HttpStatusMessage.UUID_NOT_FOUND.send(response);\r
- }\r
- return featureTree;\r
- }\r
-\r
-}\r
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.remote.controller;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.WebDataBinder;
+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.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.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.UuidList;
+import eu.etaxonomy.cdm.remote.l10n.LocaleContext;
+
+/**
+ * TODO write controller documentation
+ *
+ * @author a.kohlbecker
+ * @date 24.03.2009
+ */
+
+@Controller
+@RequestMapping(value = {"/description/{uuid}", "/description/{uuid_list}"})
+public class DescriptionController extends BaseController<DescriptionBase, IDescriptionService>
+{
+ @Autowired
+ private IFeatureTreeService featureTreeService;
+
+
+ public DescriptionController(){
+ super();
+ }
+
+ private static final List<String> FEATURETREE_INIT_STRATEGY = Arrays.asList(
+ new String[]{
+ "representations",
+ "root.feature.representations",
+ "root.children.feature.representations",
+ "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.representations.parts",
+ "elements.media.title",
+ });
+
+ @InitBinder
+ @Override
+ public void initBinder(WebDataBinder binder) {
+ super.initBinder(binder);
+ binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
+ binder.registerCustomEditor(NamedAreaLevel.class, new NamedAreaLevelPropertyEditor());
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
+ */
+ @Autowired
+ @Override
+ public void setService(IDescriptionService service) {
+ this.service = service;
+ }
+
+ /**
+ * @param request
+ * @param response
+ * @return
+ * @throws IOException
+ */
+ @RequestMapping(value = {"/featureTree/{uuid}"}, method = RequestMethod.GET)
+ public FeatureTree doGetFeatureTree(
+ @PathVariable("uuid") UUID uuid,
+ HttpServletRequest request,
+ HttpServletResponse response)throws IOException {
+ FeatureTree featureTree = getCdmBaseInstance(FeatureTree.class, featureTreeService, uuid, response, FEATURETREE_INIT_STRATEGY);
+ return featureTree;
+ }
+
+
+ @RequestMapping(value = "/descriptionElement/{descriptionelement_uuid}/annotations", method = RequestMethod.GET)
+ public Pager<Annotation> getDescriptionElementAnnotations(
+ @PathVariable("descriptionelement_uuid") UUID uuid,
+ HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+ logger.info("getDescriptionElementAnnotations() - " + request.getServletPath());
+ DescriptionElementBase annotatableEntity = service.getDescriptionElementByUuid(uuid);
+ if(annotatableEntity == null){
+ HttpStatusMessage.UUID_INVALID.send(response);
+ // method will exit here
+ return null;
+ }
+
+ Pager<Annotation> annotations = service.getDescriptionElementAnnotations(annotatableEntity, null, null, 0, null, DEFAULT_INIT_STRATEGY);
+ return annotations;
+ }
+
+
+
+ @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(
+ @PathVariable("uuid_list") UuidList descriptionUuidList,
+ @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
+ //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
+ HttpServletRequest request, HttpServletResponse response) {
+ logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getServletPath());
+ Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
+ TaxonDescription description;
+ for (UUID descriptionUuid : descriptionUuidList) {
+ description = (TaxonDescription) service.load(descriptionUuid);
+ taxonDescriptions.add(description);
+ }
+ NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
+ return areaTree;
+ }
+ */
+
+ @RequestMapping(value = "/description/{uuid}/naturalLanguageDescription/{featuretree_uuid}", method = RequestMethod.GET)
+ public ModelAndView doGenerateNaturalLanguageDescription(
+ @PathVariable("uuid") UUID uuid,
+ @PathVariable("featuretree_uuid") UUID featureTreeUuid,
+ HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+ logger.info("doGenerateNaturalLanguageDescription() - " + request.getServletPath());
+
+ DescriptionBase description = service.load(uuid);
+
+ ModelAndView mv = new ModelAndView();
+
+ List<Language> languages = LocaleContext.getLanguages();
+
+ if(!(description instanceof TaxonDescription)){
+ HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
+ // will terminate thread
+ }
+
+ FeatureTree featureTree = featureTreeService.load(featureTreeUuid, null);
+ if(featureTree == null){
+ HttpStatusMessage.UUID_NOT_FOUND.send(response);
+ // will terminate thread
+ }
+
+ String naturalLanguageDescription = service.generateNaturalLanguageDescription(
+ featureTree,
+ (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,
+ HttpServletRequest request,
+ HttpServletResponse response) throws IOException {
+ logger.info("doHasStructuredData() - " + request.getServletPath());
+
+ ModelAndView mv = new ModelAndView();
+
+ DescriptionBase description = service.load(uuid);
+
+ if(!(description instanceof TaxonDescription)){
+ HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);
+ // will terminate thread
+ }
+
+ boolean hasStructuredData = service.hasStructuredData(description);
+
+ mv.addObject(hasStructuredData);
+
+ return mv;
+ }
+
+}
\ No newline at end of file