/**\r
* Copyright (C) 2009 EDIT 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\r
* 1.1 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.EnumSet;\r
+import java.util.HashSet;\r
+import java.util.List;\r
+import java.util.Set;\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.PathVariable;\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
\r
import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
+import eu.etaxonomy.cdm.api.service.ITaxonService;\r
+import eu.etaxonomy.cdm.api.service.ITermService;\r
+import eu.etaxonomy.cdm.api.service.pager.Pager;\r
+import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;\r
+import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;\r
+import eu.etaxonomy.cdm.model.location.NamedArea;\r
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
+import eu.etaxonomy.cdm.model.taxon.Taxon;\r
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;\r
+import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
+import eu.etaxonomy.cdm.persistence.query.OrderHint;\r
+import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;\r
+import eu.etaxonomy.cdm.remote.controller.util.PagerParameters;\r
+import eu.etaxonomy.cdm.remote.editor.CdmTypePropertyEditor;\r
+import eu.etaxonomy.cdm.remote.editor.MatchModePropertyEditor;\r
+import eu.etaxonomy.cdm.remote.editor.NamedAreaPropertyEditor;\r
+import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;\r
+import eu.etaxonomy.cdm.remote.editor.UuidList;\r
\r
/**\r
* TODO write controller documentation\r
- * \r
+ *\r
* @author a.kohlbecker\r
* @date 24.03.2009\r
*/\r
@Controller\r
@RequestMapping(value = {"/occurrence"})\r
-public class OccurrenceListController extends BaseListController<SpecimenOrObservationBase, IOccurrenceService> {\r
-\r
- /* (non-Javadoc)\r
- * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)\r
- */\r
- @Override\r
- @Autowired\r
- public void setService(IOccurrenceService service) {\r
- this.service = service; \r
- } \r
+public class OccurrenceListController extends IdentifiableListController<SpecimenOrObservationBase, IOccurrenceService> {\r
+\r
+\r
+ @Autowired\r
+ private ITaxonService taxonService;\r
+\r
+ @Autowired\r
+ private ITermService termService;\r
+\r
+ /* (non-Javadoc)\r
+ * @see eu.etaxonomy.cdm.remote.controller.BaseListController#setService(eu.etaxonomy.cdm.api.service.IService)\r
+ */\r
+ @Override\r
+ @Autowired\r
+ public void setService(IOccurrenceService service) {\r
+ this.service = service;\r
+ }\r
+\r
+ @InitBinder\r
+ @Override\r
+ public void initBinder(WebDataBinder binder) {\r
+ super.initBinder(binder);\r
+ binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());\r
+ }\r
+\r
+ /**\r
+ * @param taxonUuid\r
+ * @param relationshipUuids e.g. CongruentTo; "60974c98-64ab-4574-bb5c-c110f6db634d"\r
+ * @param relationshipInversUuids\r
+ * @param maxDepth null for unlimited\r
+ * @param pageNumber\r
+ * @param pageSize\r
+ * @param request\r
+ * @param response\r
+ * @return\r
+ * @throws IOException\r
+ */\r
+ @RequestMapping(\r
+ value = {"byAssociatedTaxon"},\r
+ method = RequestMethod.GET)\r
+ public Pager<SpecimenOrObservationBase> doListByAssociatedTaxon(\r
+ @RequestParam(value = "taxonUuid", required = true) UUID taxonUuid,\r
+ @RequestParam(value = "relationships", required = false) UuidList relationshipUuids,\r
+ @RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,\r
+ @RequestParam(value = "maxDepth", required = false) Integer maxDepth,\r
+ @RequestParam(value = "pageNumber", required = false) Integer pageNumber,\r
+ @RequestParam(value = "pageSize", required = false) Integer pageSize,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+\r
+ logger.info("doListByAssociatedTaxon()" + request.getServletPath() + "?" + request.getQueryString());\r
+\r
+ Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(relationshipUuids, relationshipInversUuids, termService);\r
+\r
+ Taxon associatedTaxon = (Taxon) taxonService.find(taxonUuid);\r
+ PagerParameters pagerParams = new PagerParameters(pageSize, pageNumber);\r
+ pagerParams.normalizeAndValidate(response);\r
+\r
+ List<OrderHint> orderHints = null;\r
+\r
+ return service.pageByAssociatedTaxon(null, includeRelationships, associatedTaxon,\r
+ maxDepth, pagerParams.getPageSize(), pagerParams.getPageIndex(),\r
+ orderHints, DEFAULT_INIT_STRATEGY);\r
+\r
+ }\r
+\r
}
\ No newline at end of file