// $Id$\r
/**\r
* Copyright (C) 2009 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.util.ArrayList;\r
import java.util.Arrays;\r
import java.util.List;\r
-import java.util.Map;\r
-import java.util.Set;\r
import java.util.UUID;\r
\r
import javax.servlet.http.HttpServletRequest;\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.facade.DerivedUnitFacade;\r
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException;\r
import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
-import eu.etaxonomy.cdm.model.agent.AgentBase;\r
-import eu.etaxonomy.cdm.model.common.IdentifiableSource;\r
-import eu.etaxonomy.cdm.model.common.Language;\r
-import eu.etaxonomy.cdm.model.common.LanguageString;\r
-import eu.etaxonomy.cdm.model.location.NamedArea;\r
-import eu.etaxonomy.cdm.model.location.Point;\r
-import eu.etaxonomy.cdm.model.media.Media;\r
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.occurrence.Collection;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;\r
-import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;\r
-import eu.etaxonomy.cdm.model.occurrence.FieldObservation;\r
-import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;\r
-import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;\r
-import eu.etaxonomy.cdm.model.occurrence.Specimen;\r
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;\r
\r
*\r
*/\r
@Controller\r
-@RequestMapping(value = {"/derivedunitfacade/{uuid}"})\r
+@RequestMapping(value = {"/derivedUnitFacade/{uuid}"})\r
public class DerivedUnitFacadeController extends AbstractController{\r
\r
- \r
- private IOccurrenceService service;\r
- \r
- @Autowired\r
- public void setService(IOccurrenceService service) {\r
- this.service = service;\r
- }\r
\r
- @InitBinder\r
+ private IOccurrenceService service;\r
+\r
+ @Autowired\r
+ public void setService(IOccurrenceService service) {\r
+ this.service = service;\r
+ }\r
+\r
+ @InitBinder\r
public void initBinder(WebDataBinder binder) {\r
- binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());\r
- }\r
-\r
- @RequestMapping(method = RequestMethod.GET)\r
- public DerivedUnitFacade doGet(\r
- @PathVariable("uuid") UUID uuid,\r
- HttpServletRequest request,\r
- HttpServletResponse response) throws IOException {\r
-\r
- logger.info("getGet() - " + request.getServletPath());\r
- DerivedUnitFacade duf = newFacadeFrom(uuid, response, null);\r
- return duf;\r
- }\r
- \r
-// TODO \r
- @RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")\r
- public Object doGetCollectingAreas(\r
- @PathVariable("uuid") UUID uuid,\r
- HttpServletRequest request,\r
- HttpServletResponse response) throws IOException {\r
-\r
- logger.info("doGetCollectingAreas() - " + request.getServletPath());\r
- DerivedUnitFacade duf = newFacadeFrom(uuid, \r
- response, \r
- Arrays.asList(new String []{"ecology"}));\r
- return duf.getCollectingAreas();\r
- }\r
- \r
- @RequestMapping(method = RequestMethod.GET, value = "{uuid}/collection")\r
- public Object doGetCollection(\r
- @PathVariable("uuid") UUID uuid,\r
- HttpServletRequest request,\r
- HttpServletResponse response) throws IOException {\r
-\r
- logger.info("doGetCollection() - " + request.getServletPath());\r
- DerivedUnitFacade duf = newFacadeFrom(uuid, \r
- response, \r
- Arrays.asList(new String []{"collection"}));\r
- return duf.getCollection();\r
- }\r
- \r
- \r
- //TODO:\r
- // public Point getExactLocation() => valueProcessor?\r
- \r
-\r
- // public Collection getCollection() {\r
- // public AgentBase getCollector() {\r
- // public DerivedUnitBase getDerivedUnit() {\r
- // public Map<Language, LanguageString> getDerivedUnitDefinitions(){\r
- // public List<Media> getDerivedUnitMedia() {\r
- // public Set<DeterminationEvent> getDeterminations() {\r
- // public Set<Specimen> getDuplicates(){\r
- // public Map<Language, LanguageString> getEcologyAll(){\r
- // public Map<Language, LanguageString> getFieldObjectDefinition() {\r
- // public List<Media> getFieldObjectMedia() {\r
- // public FieldObservation getFieldObservation(){\r
- // public GatheringEvent getGatheringEvent() {\r
- // public String getGatheringEventDescription() {\r
- // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!\r
- // public PreservationMethod getPreservationMethod() \r
- // public Set<IdentifiableSource> getSources(){\r
- // public TaxonNameBase getStoredUnder() {\r
-\r
-\r
- private DerivedUnitFacade newFacadeFrom(UUID uuid, HttpServletResponse response, List<String> extendedInitStrategy)\r
- throws IOException {\r
- List<String> initStrategy = new ArrayList<String>(DEFAULT_INIT_STRATEGY);\r
- if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){\r
- initStrategy.addAll(extendedInitStrategy);\r
- }\r
- SpecimenOrObservationBase<?> sob = service.load(uuid, null);\r
- if(sob instanceof DerivedUnitBase<?>){\r
- try {\r
- return service.getDerivedUnitFacade(((DerivedUnitBase)sob), initStrategy);\r
- } catch (DerivedUnitFacadeNotSupportedException e) {\r
- logger.error(e); //TODO ...\r
- }\r
- } else {\r
- HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);\r
- }\r
- return null;\r
- }\r
-\r
- \r
- \r
- \r
- \r
- \r
- \r
- \r
- \r
- \r
+ binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());\r
+ }\r
+\r
+ @RequestMapping(method = RequestMethod.GET)\r
+ public DerivedUnitFacade doGet(\r
+ @PathVariable("uuid") UUID occurrenceUuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+\r
+ logger.info("getGet() - " + request.getServletPath());\r
+ DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response, null);\r
+ return duf;\r
+ }\r
+\r
+ @RequestMapping(value = {"derivedUnitMedia"}, method = RequestMethod.GET)\r
+ public ModelAndView doGetDerivedUnitMedia(\r
+ @PathVariable("uuid") UUID occurrenceUuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+\r
+ logger.info("doGetDerivedUnitMedia() - " + request.getServletPath());\r
+ ModelAndView mv = new ModelAndView();\r
+ DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response,Arrays.asList(new String []{\r
+ "derivedUnitMedia", "derivedUnitMedia.title"}));\r
+ if(duf != null){\r
+ mv.addObject(duf.getDerivedUnitMedia());\r
+ }\r
+ return mv;\r
+ }\r
+\r
+ @RequestMapping(value = {"fieldObjectMedia"}, method = RequestMethod.GET)\r
+ public ModelAndView doGetFieldObjectMedia(\r
+ @PathVariable("uuid") UUID occurrenceUuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+\r
+ logger.info("doGetFieldObjectMedia() - " + request.getServletPath());\r
+ ModelAndView mv = new ModelAndView();\r
+ DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid, response,Arrays.asList(new String []{\r
+ "fieldObjectMedia", "fieldObjectMedia.title"}));\r
+ mv.addObject(duf.getFieldObjectMedia());\r
+ return mv;\r
+ }\r
+\r
+// TODO\r
+ //@RequestMapping(method = RequestMethod.GET, value = "{uuid}/collectingareas")\r
+ @RequestMapping(\r
+ value = {"collectingareas"},\r
+ method = RequestMethod.GET)\r
+ public Object doGetCollectingAreas(\r
+ @PathVariable("uuid") UUID occurrenceUuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+\r
+ logger.info("doGetCollectingAreas() - " + request.getServletPath());\r
+ DerivedUnitFacade duf = newFacadeFrom(occurrenceUuid,\r
+ response,\r
+ Arrays.asList(new String []{"ecology"}));\r
+ return duf.getCollectingAreas();\r
+ }\r
+\r
+ @RequestMapping(method = RequestMethod.GET, value = "collection")\r
+ public Object doGetCollection(\r
+ @PathVariable("uuid") UUID uuid,\r
+ HttpServletRequest request,\r
+ HttpServletResponse response) throws IOException {\r
+\r
+ logger.info("doGetCollection() - " + request.getServletPath());\r
+ DerivedUnitFacade duf = newFacadeFrom(uuid,\r
+ response,\r
+ Arrays.asList(new String []{"collection"}));\r
+ return duf.getCollection();\r
+ }\r
+\r
+\r
+ //TODO:\r
+ // public Point getExactLocation() => valueProcessor?\r
+\r
+\r
+ // public Collection getCollection() {\r
+ // public AgentBase getCollector() {\r
+ // public DerivedUnitBase getDerivedUnit() {\r
+ // public Map<Language, LanguageString> getDerivedUnitDefinitions(){\r
+ // public List<Media> getDerivedUnitMedia() {\r
+ // public Set<DeterminationEvent> getDeterminations() {\r
+ // public Set<Specimen> getDuplicates(){\r
+ // public Map<Language, LanguageString> getEcologyAll(){\r
+ // public Map<Language, LanguageString> getFieldObjectDefinition() {\r
+ // public List<Media> getFieldObjectMedia() {\r
+ // public FieldObservation getFieldObservation(){\r
+ // public GatheringEvent getGatheringEvent() {\r
+ // public String getGatheringEventDescription() {\r
+ // public Map<Language, LanguageString> getPlantDescriptionAll(){ ==> representation !!\r
+ // public PreservationMethod getPreservationMethod()\r
+ // public Set<IdentifiableSource> getSources(){\r
+ // public TaxonNameBase getStoredUnder() {\r
+\r
+\r
+ /**\r
+ * @param occurrenceUuid\r
+ * @param response\r
+ * @param extendedInitStrategy\r
+ * @return the requesed <code>DerivedUnitFacade</code> instance or <code>null</code>\r
+ * @throws IOException\r
+ */\r
+ private DerivedUnitFacade newFacadeFrom(UUID occurrenceUuid, HttpServletResponse response, List<String> extendedInitStrategy)\r
+ throws IOException {\r
+ List<String> initStrategy = new ArrayList<String>(initializationStrategy);\r
+ if(extendedInitStrategy != null && extendedInitStrategy.size() > 0){\r
+ initStrategy.addAll(extendedInitStrategy);\r
+ }\r
+ SpecimenOrObservationBase<?> sob = service.load(occurrenceUuid, null);\r
+ if(sob instanceof DerivedUnitBase<?>){\r
+ try {\r
+ return service.getDerivedUnitFacade(((DerivedUnitBase)sob), initStrategy);\r
+ } catch (DerivedUnitFacadeNotSupportedException e) {\r
+ logger.error(e); //TODO ...\r
+ }\r
+ } else {\r
+ HttpStatusMessage.UUID_REFERENCES_WRONG_TYPE.send(response);\r
+ }\r
+ return null;\r
+ }\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
\r
}\r