// $Id$\r
/**\r
* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
+* European Distributed Institute of Taxonomy\r
* http://www.e-taxonomy.eu\r
-* \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
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.PathVariable;\r
import org.springframework.web.bind.annotation.RequestMapping;\r
import org.springframework.web.bind.annotation.RequestMethod;\r
import org.springframework.web.servlet.ModelAndView;\r
\r
-import eu.etaxonomy.cdm.api.service.AnnotatableServiceBase;\r
+import eu.etaxonomy.cdm.api.service.IDescriptionService;\r
import eu.etaxonomy.cdm.api.service.INameService;\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
+import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;\r
+import eu.etaxonomy.cdm.model.description.TaxonNameDescription;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.persistence.dao.common.IAnnotatableDao;\r
+import eu.etaxonomy.cdm.model.name.TypeDesignationBase;\r
\r
/**\r
+ * The NamePortalController class is a Spring MVC Controller.\r
+ * <p>\r
+ * The syntax of the mapped service URIs contains the the {datasource-name} path element.\r
+ * The available {datasource-name}s are defined in a configuration file which\r
+ * is loaded by the {@link UpdatableRoutingDataSource}. If the\r
+ * UpdatableRoutingDataSource is not being used in the actual application\r
+ * context any arbitrary {datasource-name} may be used.\r
+ * <p>\r
+ * Methods mapped at type level, inherited from super classes ({@link BaseController}):\r
+ * <blockquote>\r
+ * URI: <b>/{datasource-name}/portal/name/{name-uuid}</b>\r
+ *\r
+ * Get the {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.\r
+ * The returned TaxonNameBase is initialized by\r
+ * the following strategy: -- NONE --\r
+ * </blockquote>\r
+ *\r
* @author a.kohlbecker\r
* @date 24.03.2009\r
*/\r
\r
@Controller\r
-@RequestMapping(value = {"/*/portal/name/*","/*/portal/name/*/typedesignations"})\r
+@RequestMapping(value = {"/portal/name/{uuid}"})\r
public class NamePortalController extends BaseController<TaxonNameBase, INameService>\r
{\r
- \r
- private static final List<String> TYPE_INIT_STRATEGY = Arrays.asList(new String []{\r
- "citation.authorTeam",\r
- "typeName.$",\r
- "typeName.taggedName",\r
- "typeStatus.representations",\r
- "typeSpecimen.media.representations.parts"\r
- });\r
-\r
- public NamePortalController(){\r
- super();\r
- setUuidParameterPattern("^/(?:[^/]+)/portal/name/([^/?#&\\.]+).*");\r
- setInitializationStrategy(Arrays.asList(new String[]{"$"}));\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(INameService service) {\r
- this.service = service;\r
- }\r
-\r
- @RequestMapping(\r
- value = {"/*/portal/name/*/typedesignations"},\r
- method = RequestMethod.GET)\r
- public ModelAndView doGetTypeDesignations(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
- ModelAndView mv = new ModelAndView();\r
- TaxonNameBase name = getCdmBase(request, response, null, TaxonNameBase.class);\r
- Pager p = service.getTypeDesignations(name, null, null, null, TYPE_INIT_STRATEGY);\r
- mv.addObject(p.getRecords());\r
- return mv;\r
- }\r
+\r
+ private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{\r
+ "typeName.$",\r
+ "typeSpecimen",\r
+ "typeStatus.representations",\r
+ "typifiedNames.nomenclaturalReference.authorTeam",\r
+ "citation.authorTeam.$",\r
+ "typeSpecimen.media"\r
+ });\r
+\r
+\r
+ private static final List<String> NAMEDESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{\r
+ "uuid",\r
+ "feature",\r
+ "elements.$",\r
+ "elements.multilanguageText",\r
+ "elements.media",\r
+ });\r
+\r
+\r
+// public NamePortalController(){\r
+// super();\r
+// setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO required???\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(INameService service) {\r
+ this.service = service;\r
+ }\r
+\r
+ @Autowired\r
+ private IDescriptionService descriptionService;\r
+\r
+ /**\r
+ * Get the list of {@link TypeDesignationBase}s of the\r
+ * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/name/{name-uuid}/typeDesignations</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link TypeDesignationBase} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #TYPEDESIGNATION_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @SuppressWarnings("unchecked")\r
+ @RequestMapping(\r
+ value = {"typeDesignations"},\r
+ method = RequestMethod.GET)\r
+ public List<TypeDesignationBase> doGetTypeDesignations(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ ModelAndView mv = new ModelAndView();\r
+ TaxonNameBase tnb = getCdmBaseInstance(uuid, response, (List<String>)null);\r
+ Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null, null, null, TYPEDESIGNATION_INIT_STRATEGY);\r
+ return p.getRecords();\r
+ }\r
+\r
+ /**\r
+ * Get the list of {@link TaxonNameDescription}s of the Name associated with the\r
+ * {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.\r
+ * <p>\r
+ * URI: <b>/{datasource-name}/portal/name/{name-uuid}/descriptions</b>\r
+ *\r
+ * @param request\r
+ * @param response\r
+ * @return a List of {@link TaxonNameDescription} entities which are initialized\r
+ * using the following initialization strategy:\r
+ * {@link #NAMEDESCRIPTION_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"taxonNameDescriptions"},\r
+ method = RequestMethod.GET)\r
+ public List<TaxonNameDescription> doGetNameDescriptions(@PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ logger.info("doGetNameDescriptions()" + request.getRequestURI());\r
+ TaxonNameBase tnb = service.load(uuid, null);\r
+ Pager<TaxonNameDescription> p = descriptionService.getTaxonNameDescriptions(tnb, null, null, NAMEDESCRIPTION_INIT_STRATEGY);\r
+ return p.getRecords();\r
+ }\r
\r
\r
}\r