bringing the titleCache of TeamOrPersonBase back to the REST services
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 25 May 2011 12:10:43 +0000 (12:10 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Wed, 25 May 2011 12:10:43 +0000 (12:10 +0000)
.gitattributes
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/agent/TeamOrPersonBase.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/controller/AgentController.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TaxonNodeDaoBeanProcessor.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TeamOrPersonBaseBeanProcessor.java [new file with mode: 0644]
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/matcher/CdmProxyBeanProcessorMatcher.java
cdmlib-remote/src/main/resources/eu/etaxonomy/cdm/remote/json/jsonConfigurations.xml

index b86ebc7b6d5a6ac975c00804d906d8ceb465efb5..cf73a5dc4aabe7a6aa38c4b7d19fdec47d85847c 100644 (file)
@@ -1576,6 +1576,7 @@ cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TaxonNam
 cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TaxonNodeBeanProcessor.java -text
 cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TaxonNodeDaoBeanProcessor.java -text
 cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TaxonRelationshipBeanProcessor.java -text
+cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TeamOrPersonBaseBeanProcessor.java -text
 cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TermBaseBeanProcessor.java -text
 cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TextDataBeanProcessor.java -text
 cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TypeDesignationBaseBeanProcessor.java -text
index baa1f5e6a457fafd9546ec593296e0ff8005dae8..4bdf121e5bb2f3eb945b2dfa2a01134a6b7ad46b 100644 (file)
@@ -1,8 +1,8 @@
 /**\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
@@ -31,7 +31,7 @@ import eu.etaxonomy.cdm.validation.annotation.NullOrNotEmpty;
 /**\r
  * The abstract class for such {@link AgentBase agents} ({@link Person persons} or {@link Team teams}) who might also be used\r
  * for authorship of {@link eu.etaxonomy.cdm.model.reference.Reference references} or of {@link eu.etaxonomy.cdm.model.name.TaxonNameBase taxon names}.\r
- * \r
+ *\r
  * @author a.mueller\r
  * @version 1.0\r
  * @created 17-APR-2008\r
@@ -56,11 +56,11 @@ public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<?>> extends Ag
        @Transient\r
        @XmlTransient\r
        protected boolean isGeneratingTitleCache = false;\r
-       \r
+\r
        /**\r
         * Returns the identification string (nomenclatural abbreviation) used in\r
         * nomenclature for this {@link Person person} or this {@link Team team}.\r
-        * \r
+        *\r
         * @see  INomenclaturalAuthor#getNomenclaturalTitle()\r
         */\r
        @Transient\r
@@ -72,7 +72,7 @@ public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<?>> extends Ag
                return result;\r
        }\r
 \r
-       /** \r
+       /**\r
         * @see     #getNomenclaturalTitle()\r
         */\r
        public void setNomenclaturalTitle(String nomenclaturalTitle) {\r
@@ -83,7 +83,16 @@ public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<?>> extends Ag
         * @see eu.etaxonomy.cdm.model.common.IdentifiableEntity#getTitleCache()\r
         */\r
        @Override\r
-       @Transient //TODO a.kohlbecker remove??\r
+       @Transient /*\r
+                               TODO  is this still needed, can't we remove this ??\r
+                               @Transient is an absolutely special case and thus leads to several\r
+                               special implementations in order to harmonize this exception again\r
+                               in other parts of the library:\r
+                                - eu.etaxonomy.cdm.remote.controller.AgentController.doGetTitleCache()\r
+                                - eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor\r
+\r
+                               [a.kohlbecker May 2011]\r
+               */\r
        public String getTitleCache() {\r
                isGeneratingTitleCache = true;\r
                String result = super.getTitleCache();\r
@@ -105,6 +114,6 @@ public abstract class TeamOrPersonBase<T extends TeamOrPersonBase<?>> extends Ag
                }\r
                return result;\r
        }\r
-       \r
-       \r
+\r
+\r
 }\r
index 567b484721fb43e58b8f087729da44f794e506b5..0ce84283a115044450f254901dd223c8bb8f5a4b 100644 (file)
@@ -1,18 +1,27 @@
 // $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
 \r
 package eu.etaxonomy.cdm.remote.controller;\r
 \r
+import java.io.IOException;\r
+import java.util.Map;\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.servlet.ModelAndView;\r
 \r
 import eu.etaxonomy.cdm.api.service.IAgentService;\r
 import eu.etaxonomy.cdm.api.service.pager.Pager;\r
@@ -31,29 +40,29 @@ import eu.etaxonomy.cdm.model.common.Annotation;
  * Methods mapped at type level, inherited from super classes ({@link BaseController}):\r
  * <blockquote>\r
  * URI: <b>&#x002F;{datasource-name}&#x002F;agent&#x002F;name&#x002F;{agent-uuid}</b>\r
- * \r
+ *\r
  * Get the {@link AgentBase} instance identified by the <code>{agent-uuid}</code>.\r
  * The returned AgentBase is initialized by\r
  * the default initialization strategy: {@link #DEFAULT_INIT_STRATEGY}\r
  * </blockquote>\r
  * <blockquote>\r
  * URI: <b>&#x002F;{datasource-name}&#x002F;agent&#x002F;name&#x002F;{agent-uuid}&#x002F;annotation</b>\r
- * \r
+ *\r
  * Returns a {@link Pager} on the {@link Annotation}s for the {@link AgentBase} instance identified by the\r
  * <code>{agent-uuid}</code>.\r
  * The returned AgentBase instances are initialized by\r
  * the following strategy: {@link #ANNOTATION_INIT_STRATEGY}\r
  * </blockquote>\r
- * \r
+ *\r
  * @author a.kohlbecker\r
  * @date 24.03.2009\r
  */\r
 @Controller\r
 @RequestMapping(value = {"/agent/{uuid}"})\r
-public class AgentController extends AnnotatableController<AgentBase, IAgentService>\r
+public class AgentController extends BaseController<AgentBase, IAgentService>\r
 {\r
 \r
-       \r
+\r
        /* (non-Javadoc)\r
         * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)\r
         */\r
@@ -63,4 +72,30 @@ public class AgentController extends AnnotatableController<AgentBase, IAgentServ
                this.service = service;\r
        }\r
 \r
+       /**\r
+        * This method is only needed for\r
+        * {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase} or sub classes\r
+        * which are also handled by this controller.\r
+        *\r
+        * The method\r
+        * {@link eu.etaxonomy.cdm.model.agent.TeamOrPersonBase#getTitleCache() } is\r
+        * annotated with @Transient and thus it is not automatically made available\r
+        * by the BaseController.\r
+        *\r
+        * @param uuid\r
+        * @param request\r
+        * @param response\r
+        * @return\r
+        * @throws IOException\r
+        */\r
+       @RequestMapping(value = {"titleCache"})\r
+       public ModelAndView doGetTitleCache(@PathVariable("uuid") UUID uuid,\r
+                       HttpServletRequest request, HttpServletResponse response) throws IOException {\r
+               ModelAndView mv = new ModelAndView();\r
+               AgentBase agentbase = service.load(uuid);\r
+               mv.addObject(agentbase.getTitleCache());\r
+               return mv;\r
+\r
+       }\r
+\r
 }\r
index 2807f6e5e925c60cfd574c00c6e56c995f32473c..478e11410e0eea3d3454c75b5eb15afbedd3b165 100644 (file)
@@ -1,9 +1,9 @@
 // $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
@@ -32,7 +32,7 @@ public class TaxonNodeDaoBeanProcessor implements JsonBeanProcessor {
         */\r
        @Override\r
        public JSONObject processBean(Object bean, JsonConfig jsonConfig) {\r
-               \r
+\r
                TaxonNode node = (TaxonNode)bean;\r
                JSONObject json = new JSONObject();\r
                json.element("class", "TaxonNodeDao");\r
@@ -42,12 +42,12 @@ public class TaxonNodeDaoBeanProcessor implements JsonBeanProcessor {
                json.element("taggedTitle", taggedTitle, jsonConfig);\r
                json.element("taxonUuid", node.getTaxon().getUuid(), jsonConfig);\r
                //Sec can be null (web services can return null for sec)\r
-               //comparation made for avoding view exceptions\r
+               //comparation made for avoiding view exceptions\r
                if (node.getTaxon().getSec() == null){\r
                        json.element("secUuid", "null");\r
                }else{\r
                        json.element("secUuid", node.getTaxon().getSec().getUuid(), jsonConfig);\r
-               }       \r
+               }\r
                json.element("taxonomicChildrenCount", node.getCountChildren(), jsonConfig);\r
                json.element("unplaced", node.getTaxon().isUnplaced());\r
                json.element("excluded", node.getTaxon().isExcluded());\r
@@ -57,7 +57,7 @@ public class TaxonNodeDaoBeanProcessor implements JsonBeanProcessor {
                }\r
                json.element("rankLabel", ranklabel, jsonConfig);\r
                //json.element("treeUuid", node.getClassification().getUuid(), jsonConfig);\r
-               \r
+\r
                return json;\r
        }\r
 \r
diff --git a/cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TeamOrPersonBaseBeanProcessor.java b/cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/json/processor/bean/TeamOrPersonBaseBeanProcessor.java
new file mode 100644 (file)
index 0000000..1f372bd
--- /dev/null
@@ -0,0 +1,44 @@
+// $Id$\r
+/**\r
+* Copyright (C) 2009 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\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
+package eu.etaxonomy.cdm.remote.json.processor.bean;\r
+\r
+import java.util.List;\r
+\r
+import net.sf.json.JSONObject;\r
+import net.sf.json.JsonConfig;\r
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
+\r
+/**\r
+ * @author a.kohlbecker\r
+ * @date 20.10.2010\r
+ *\r
+ */\r
+public class TeamOrPersonBaseBeanProcessor extends AbstractBeanProcessor<TeamOrPersonBase> {\r
+\r
+       /* (non-Javadoc)\r
+        * @see eu.etaxonomy.cdm.remote.json.processor.bean.AbstractBeanProcessor#getIgnorePropNames()\r
+        */\r
+       @Override\r
+       public List<String> getIgnorePropNames() {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see eu.etaxonomy.cdm.remote.json.processor.bean.AbstractBeanProcessor#processBeanSecondStep(java.lang.Object, net.sf.json.JSONObject, net.sf.json.JsonConfig)\r
+        */\r
+       @Override\r
+       public JSONObject processBeanSecondStep(TeamOrPersonBase bean, JSONObject json,\r
+                       JsonConfig jsonConfig) {\r
+               json.element("titleCache", bean.getTitleCache());\r
+               return json;\r
+       }\r
+\r
+}\r
index dbb45090be3cb39459f4eb59614516ce3d86bfd6..b3b3e34b54ef1d84263c1c84cf437ed46c51203c 100644 (file)
@@ -2,7 +2,7 @@
 /**\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
@@ -16,6 +16,7 @@ import net.sf.json.processors.JsonBeanProcessorMatcher;
 import org.apache.log4j.Logger;\r
 import org.hibernate.proxy.HibernateProxy;\r
 \r
+import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
 import eu.etaxonomy.cdm.model.common.TermBase;\r
 import eu.etaxonomy.cdm.model.media.Media;\r
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
@@ -25,22 +26,22 @@ import eu.etaxonomy.cdm.model.taxon.Taxon;
 \r
 /**\r
  * can handle HibernateProxys\r
- * \r
+ *\r
  * @author a.kohlbecker\r
  *\r
  */\r
 public class CdmProxyBeanProcessorMatcher extends JsonBeanProcessorMatcher {\r
 \r
        public static final Logger logger = Logger.getLogger(CdmProxyBeanProcessorMatcher.class);\r
-       \r
+\r
        /* (non-Javadoc)\r
         * @see net.sf.json.processors.JsonBeanProcessorMatcher#getMatch(java.lang.Class, java.util.Set)\r
         */\r
        @SuppressWarnings("unchecked")\r
        @Override\r
        public Object getMatch(Class target, Set set) {\r
-               \r
-               \r
+\r
+\r
                if (HibernateProxy.class.isAssignableFrom(target)) {\r
                        if(logger.isDebugEnabled()){\r
                                logger.debug("Found HibernateProxy object of class " + target.getClass() + " returning " + HibernateProxy.class);\r
@@ -56,12 +57,9 @@ public class CdmProxyBeanProcessorMatcher extends JsonBeanProcessorMatcher {
                if (TermBase.class.isAssignableFrom(target)) {\r
                        return DEFAULT.getMatch(TermBase.class, set);\r
                }\r
-//             if (NameRelationship.class.isAssignableFrom(target)) {\r
-//                     return DEFAULT.getMatch(NameRelationship.class, set);\r
-//             }\r
-//             if (TaxonRelationship.class.isAssignableFrom(target)) {\r
-//                     return DEFAULT.getMatch(TaxonRelationship.class, set);\r
-//             }\r
+               if (TeamOrPersonBase.class.isAssignableFrom(target)) {\r
+                       return DEFAULT.getMatch(TeamOrPersonBase.class, set);\r
+               }\r
                if (Media.class.isAssignableFrom(target)) {\r
                        return DEFAULT.getMatch(Media.class, set);\r
                }\r
@@ -74,6 +72,6 @@ public class CdmProxyBeanProcessorMatcher extends JsonBeanProcessorMatcher {
 \r
                return DEFAULT.getMatch(target, set);\r
        }\r
-       \r
-       \r
+\r
+\r
 }\r
index 4f2fc5affe7306731dda3f8b714aea786d95c4b6..d31982625f4948a8757c513aa4bfd8e3bab44b35 100644 (file)
@@ -7,7 +7,7 @@
     http://www.springframework.org/schema/context   http://www.springframework.org/schema/context/spring-context-2.5.xsd\r
     http://www.springframework.org/schema/tx   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd\r
     ">\r
-    \r
+\r
     <bean id="genericApiCardinalityPropertyFilter" class="eu.etaxonomy.cdm.remote.json.util.CardinalityPropertyFilter">\r
        <property name="includeToOneRelations" value="false" />\r
        <property name="includeToManyRelations" value="false" />\r
 \r
              <value>TreeNode.data</value>\r
              <value>TreeNode.data</value>\r
-             \r
+\r
              <value>PolytomousKey.root</value>\r
              <value>PolytomousKeyNode.children</value>\r
              <value>PolytomousKeyNode.question</value>\r
              <value>PolytomousKeyNode.statement</value>\r
-             <value>PolytomousKeyNode.modifyingText</value> \r
-             \r
+             <value>PolytomousKeyNode.modifyingText</value>\r
+\r
              <value>Media.representations</value>\r
              <value>MediaRepresentation.parts</value>\r
-             \r
+\r
              <!-- CardinalityPropertyFilter should allow defining exceptions for abstract super classes : -->\r
-             <!-- <value>eu.etaxonomy.cdm.model.description.DescriptionElementBase.feature</value> --> \r
-             \r
+             <!-- <value>eu.etaxonomy.cdm.model.description.DescriptionElementBase.feature</value> -->\r
+\r
              <value>TextData.feature</value>\r
              <value>CategoricalData.feature</value>\r
              <value>CommonTaxonName.feature</value>\r
@@ -45,9 +45,9 @@
        </property>\r
      </bean>\r
 \r
-       <!-- \r
+       <!--\r
          =================================================\r
-            default configuration for RESTful read(/write) service         \r
+            default configuration for RESTful read(/write) service\r
          =================================================\r
     -->\r
        <bean name="jsonConfig" class="eu.etaxonomy.cdm.remote.json.JsonConfigFactoryBean"\r
             <entry key="eu.etaxonomy.cdm.model.description.KeyStatement">\r
                 <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.KeyStatementBeanProcessor" />\r
             </entry>\r
+            <entry key="eu.etaxonomy.cdm.model.agent.TeamOrPersonBase">\r
+                <bean class="eu.etaxonomy.cdm.remote.json.processor.bean.TeamOrPersonBaseBeanProcessor" />\r
+            </entry>\r
+\r
                  </map>\r
                </property>\r
                <property name="jsonPropertyFilter">\r
                                </entry>\r
                            <entry key="java.net.URI">\r
                     <bean class="eu.etaxonomy.cdm.remote.json.processor.value.URIJSONValueProcessor"/>\r
-                </entry>     \r
+                </entry>\r
                        </map>\r
                </property>\r
                <property name="ignoreDefaultExcludes" value="true" />\r
                </property>\r
        </bean>\r
 \r
-       <!-- \r
+       <!--\r
          =================================================\r
-            configuration for RESTful classification service \r
+            configuration for RESTful classification service\r
          =================================================\r
     -->\r
        <bean name="jsonConfigClassification" class="eu.etaxonomy.cdm.remote.json.JsonConfigFactoryBean"\r
                 </entry>\r
                 <entry key="java.net.URI">\r
                     <bean class="eu.etaxonomy.cdm.remote.json.processor.value.URIJSONValueProcessor"/>\r
-                </entry>    \r
+                </entry>\r
                        </map>\r
                </property>\r
                <property name="ignoreDefaultExcludes" value="true" />\r
                </property>\r
        </bean>\r
 \r
-       <!-- \r
+       <!--\r
             =================================================\r
-              configuration for RESTful portal service \r
+              configuration for RESTful portal service\r
             =================================================\r
        -->\r
 \r
                 </entry>\r
                 <entry key="java.net.URI">\r
                     <bean class="eu.etaxonomy.cdm.remote.json.processor.value.URIJSONValueProcessor"/>\r
-                </entry>    \r
+                </entry>\r
                        </map>\r
                </property>\r
                <property name="ignoreDefaultExcludes" value="true" />\r
                                <value>inDescription</value>\r
                        </list>\r
                </property>\r
-       </bean> \r
+       </bean>\r
 </beans>
\ No newline at end of file