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
import org.springframework.web.bind.annotation.RequestMapping;\r
import org.springframework.web.bind.annotation.RequestMethod;\r
import org.springframework.web.bind.annotation.RequestParam;\r
-import org.springframework.web.servlet.ModelAndView;\r
\r
import eu.etaxonomy.cdm.api.service.ITermService;\r
import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
import eu.etaxonomy.cdm.api.service.pager.Pager;\r
import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
-import eu.etaxonomy.cdm.model.common.OrderedTermBase;\r
import eu.etaxonomy.cdm.model.common.TermVocabulary;\r
import eu.etaxonomy.cdm.model.location.NamedArea;\r
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;\r
+import eu.etaxonomy.cdm.model.location.NamedAreaType;\r
\r
/**\r
* TODO write controller documentation\r
*\r
*/\r
@Controller\r
-@RequestMapping(value = {"/*/term/", "/*/term/?*", "/*/term/?*/*", "/*/term/*/compareTo/?*"})\r
-public class TermListController extends BaseListController<DefinedTermBase, ITermService> {\r
- \r
- private static final List<String> VOCABULARY_LIST_INIT_STRATEGY = Arrays.asList(new String []{\r
- "representations"\r
- });\r
- \r
- private static final List<String> TERM_COMPARE_INIT_STRATEGY = Arrays.asList(new String []{\r
- "vocabulary"\r
- });\r
- \r
- private static final List<String> VOCABULARY_INIT_STRATEGY = Arrays.asList(new String []{\r
- "$",\r
- "representations",\r
- "terms.representations"\r
- });\r
- \r
- private IVocabularyService vocabularyService;\r
- \r
- @Autowired\r
- public void setVocabularyService(IVocabularyService vocabularyService) {\r
- this.vocabularyService = vocabularyService;\r
- }\r
+@RequestMapping(value = {"/term"})\r
+public class TermListController extends IdentifiableListController<DefinedTermBase, ITermService> {\r
+\r
\r
/* (non-Javadoc)\r
* @see eu.etaxonomy.cdm.remote.controller.AbstractListController#setService(eu.etaxonomy.cdm.api.service.IService)\r
public void setService(ITermService service) {\r
this.service = service;\r
}\r
- \r
- /**\r
- * TODO write controller method documentation\r
- * \r
- * @param page\r
- * @param pageSize\r
- * @return\r
- */\r
- @SuppressWarnings("unchecked")\r
- @RequestMapping(method = RequestMethod.GET,\r
- value = "/*/term/")\r
- public Pager<TermVocabulary> doGetVocabularies(\r
- @RequestParam(value = "page", required = false) Integer page,\r
- @RequestParam(value = "pageSize", required = false) Integer pageSize) {\r
- \r
- if(page == null){ page = DEFAULT_PAGE_NUMBER;}\r
- if(pageSize == null){ pageSize = DEFAULT_PAGESIZE;}\r
- \r
- return (Pager<TermVocabulary>) vocabularyService.page(null,pageSize, page, null, VOCABULARY_LIST_INIT_STRATEGY);\r
- }\r
- \r
- /**\r
- * TODO write controller method documentation\r
- * \r
- * @param request\r
- * @param response\r
- * @return\r
- * @throws IOException\r
- */\r
- @RequestMapping(method = RequestMethod.GET,\r
- value = "/*/term/?*")\r
- public TermVocabulary<DefinedTermBase> doGetTerms(HttpServletRequest request, HttpServletResponse response) throws IOException {\r
- UUID uuid = readValueUuid(request, "^/(?:[^/]+)/term/([^/?#&\\.]+).*");\r
- TermVocabulary<DefinedTermBase> vocab = vocabularyService.load(uuid, VOCABULARY_INIT_STRATEGY);\r
- return vocab;\r
- }\r
- \r
- /**\r
- * TODO write controller method documentation\r
- * \r
- * @param request\r
- * @param response\r
- * @return\r
- * @throws IOException\r
- */\r
- @RequestMapping(method = RequestMethod.GET,\r
- value = "/*/term/*/compareTo/?*")\r
- public ModelAndView doCompare(HttpServletRequest request, HttpServletResponse response) throws IOException {\r
- ModelAndView mv = new ModelAndView();\r
- UUID uuidThis = readValueUuid(request, "^/(?:[^/]+)/term/([^/?#&\\.]+).*");\r
- UUID uuidThat = readValueUuid(request, "^/(?:[^/]+)/term/(?:[^/]+)/compareTo/([^/?#&\\.]+).*");\r
- DefinedTermBase thisTerm = service.load(uuidThis, TERM_COMPARE_INIT_STRATEGY);\r
- DefinedTermBase thatTerm = service.load(uuidThat, TERM_COMPARE_INIT_STRATEGY);\r
- if(thisTerm.getVocabulary().equals(thatTerm.getVocabulary())){\r
- if(OrderedTermBase.class.isAssignableFrom(thisTerm.getClass())){\r
- Integer result = ((OrderedTermBase)thisTerm).compareTo((OrderedTermBase)thatTerm);\r
- mv.addObject(result);\r
- return mv;\r
- }\r
- response.sendError(400, "Only ordered term types can be compared");\r
- return mv;\r
- }\r
- response.sendError(400, "Terms of different vocabuaries can not be compared");\r
- return mv;\r
- }\r
+\r
\r
/**\r
* TODO write controller method documentation\r
* @throws IOException\r
*/\r
@RequestMapping(method = RequestMethod.GET,\r
- value = "/*/term/tdwg/*")\r
+ value = "/term/tdwg/*")\r
public List<NamedArea> doGetTdwgLevel(HttpServletRequest request, HttpServletResponse response) throws IOException {\r
\r
String path = request.getServletPath();\r
String[] pathTokens = path.split("/");\r
- String levelStr = pathTokens[4];\r
+ String levelStr = pathTokens[3];\r
if(levelStr.indexOf('.') > -1){\r
levelStr = levelStr.substring(0, levelStr.indexOf('.'));\r
}\r
case 3: level = NamedAreaLevel.TDWG_LEVEL3(); break;\r
case 4: level = NamedAreaLevel.TDWG_LEVEL4(); break;\r
}\r
- Pager<NamedArea> p = service.list(level, null, null, null, null, null);\r
+ Pager<NamedArea> p = service.list(level, (NamedAreaType)null, null, null, null, null);\r
return p.getRecords();\r
}\r
\r