\r
package eu.etaxonomy.cdm.remote.controller;\r
\r
+import java.io.IOException;\r
+import java.util.ArrayList;\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.WebDataBinder;\r
+import org.springframework.web.bind.annotation.InitBinder;\r
import org.springframework.web.bind.annotation.RequestMapping;\r
+import org.springframework.web.bind.annotation.RequestMethod;\r
\r
import eu.etaxonomy.cdm.api.service.INameService;\r
+import eu.etaxonomy.cdm.api.service.pager.Pager;\r
+import eu.etaxonomy.cdm.model.name.NonViralName;\r
+import eu.etaxonomy.cdm.model.name.Rank;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
+import eu.etaxonomy.cdm.model.name.TypeDesignationBase;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.remote.dto.tdwg.voc.TaxonName;\r
+import eu.etaxonomy.cdm.remote.editor.RankPropertyEditor;\r
+import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;\r
\r
/**\r
+ * TODO write controller documentation\r
+ * \r
* @author a.kohlbecker\r
* @date 24.03.2009\r
*/\r
\r
@Controller\r
-@RequestMapping(value = {"/*/name/*","/*/name/annotation/*"})\r
+@RequestMapping(value = {"/name/*", "/name/{uuid}"})\r
public class NameController extends AnnotatableController<TaxonNameBase, INameService>\r
{\r
-\r
+ \r
+ private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{\r
+ "typeStatus.representations",\r
+ "typifiedNames.titleCache",\r
+ "typeSpecimen.titleCache",\r
+ \r
+ });\r
+ \r
+ private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{\r
+ "titleCache"\r
+ });\r
+ \r
public NameController(){\r
super();\r
- setUuidParameterPattern("^/(?:[^/]+)/name/([^/?#&\\.]+).*");\r
+ setUuidParameterPattern("^/name/([^/?#&\\.]+).*");\r
+ setInitializationStrategy(Arrays.asList(new String[]{"$"}));\r
}\r
\r
/* (non-Javadoc)\r
public void setService(INameService service) {\r
this.service = service;\r
}\r
-\r
+ \r
+ @InitBinder\r
+ public void initBinder(WebDataBinder binder) {\r
+ binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());\r
+ }\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}/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 {@link #TYPEDESIGNATION_INIT_STRATEGY}\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"*/typeDesignations"},\r
+ method = RequestMethod.GET)\r
+ public List<TypeDesignationBase> doGetNameTypeDesignations(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ TaxonNameBase tnb = getCdmBase(request, response, null, TaxonNameBase.class);\r
+ Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null, null, null, TYPEDESIGNATION_INIT_STRATEGY);\r
+ return p.getRecords();\r
+ }\r
+ \r
+ @RequestMapping(\r
+ value = {"*/nameCache"},\r
+ method = RequestMethod.GET)\r
+ public List<String> doGetNameCache(HttpServletRequest request, HttpServletResponse response)throws IOException {\r
+ TaxonNameBase tnb = getCdmBase(request, response, NAME_CACHE_INIT_STRATEGY, TaxonNameBase.class);\r
+ NonViralName nvn = (NonViralName) tnb;\r
+ String nameCacheString = nvn.getNameCache();\r
+ List result = new ArrayList<String>();\r
+ result.add(nameCacheString);\r
+ return result;\r
+ }\r
+ \r
}\r