← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5109: misc api stuff, mostly test code

 

------------------------------------------------------------
revno: 5109
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-11-03 17:43:51 +0100
message:
  misc api stuff, mostly test code
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm
  dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm
modified:
  dhis-2/dhis-web/dhis-web-api/pom.xml
  dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml
  dhis-2/pom.xml


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-api/pom.xml'
--- dhis-2/dhis-web/dhis-web-api/pom.xml	2011-11-02 11:14:35 +0000
+++ dhis-2/dhis-web/dhis-web-api/pom.xml	2011-11-03 16:43:51 +0000
@@ -34,6 +34,18 @@
       <groupId>org.springframework</groupId>
       <artifactId>spring-webmvc</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.codehaus.jackson</groupId>
+      <artifactId>jackson-mapper-asl</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>javax.xml.bind</groupId>
+      <artifactId>jaxb-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-oxm</artifactId>
+    </dependency>
   </dependencies>
 
   <properties>

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ElementController.java	2011-11-03 16:43:51 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.api.controller;
+
+import org.hisp.dhis.api.resources.Element;
+import org.hisp.dhis.api.resources.Elements;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+@RequestMapping( value = "/elements" )
+public class ElementController
+{
+    private Elements elements = new Elements();
+
+    public ElementController()
+    {
+        elements.getElements().add( new Element( 1, "Element #1" ) );
+        elements.getElements().add( new Element( 2, "Element #2" ) );
+        elements.getElements().add( new Element( 3, "Element #3" ) );
+        elements.getElements().add( new Element( 4, "Element #4" ) );
+        elements.getElements().add( new Element( 5, "Element #5" ) );
+    }
+
+    @RequestMapping
+    public String getElements( Model model )
+    {
+        model.addAttribute( "elements", elements );
+
+        return "elements";
+    }
+
+    @RequestMapping( value = "/{uid}" )
+    public String getElement( @PathVariable( "uid" ) Integer uid, Model model )
+    {
+        model.addAttribute( "element", elements.getElement( uid ) );
+
+        return "element";
+    }
+}

=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Element.java	2011-11-03 16:43:51 +0000
@@ -0,0 +1,53 @@
+package org.hisp.dhis.api.resources;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType( XmlAccessType.FIELD )
+public class Element
+{
+    @XmlAttribute
+    private Integer uid;
+
+    @XmlAttribute
+    private String name;
+
+    public Element()
+    {
+    }
+
+    public Element( String name )
+    {
+        this();
+        this.name = name;
+    }
+
+    public Element( Integer uid, String name )
+    {
+        this.uid = uid;
+        this.name = name;
+    }
+
+    public Integer getUid()
+    {
+        return uid;
+    }
+
+    public void setUid( Integer uid )
+    {
+        this.uid = uid;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/resources/Elements.java	2011-11-03 16:43:51 +0000
@@ -0,0 +1,40 @@
+package org.hisp.dhis.api.resources;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+@XmlAccessorType( XmlAccessType.FIELD )
+public class Elements
+{
+    @XmlElement( name = "element" )
+    private List<Element> elements = new ArrayList<Element>();
+
+    public List<Element> getElements()
+    {
+        return elements;
+    }
+
+    public void setElements( List<Element> elements )
+    {
+        this.elements = elements;
+    }
+
+    public Element getElement( Integer uid )
+    {
+        for ( Element el : elements )
+        {
+            if ( el.getUid().equals( uid ) )
+            {
+                return el;
+            }
+        }
+
+        return null;
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml	2011-11-02 11:14:35 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml	2011-11-03 16:43:51 +0000
@@ -11,4 +11,51 @@
 
   <context:component-scan base-package="org.hisp.dhis.api" />
 
+  <beans:bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
+    <beans:property name="classesToBeBound">
+      <beans:list>
+        <beans:value>org.hisp.dhis.api.resources.Elements</beans:value>
+        <beans:value>org.hisp.dhis.api.resources.Element</beans:value>
+      </beans:list>
+    </beans:property>
+  </beans:bean>
+
+  <beans:bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
+    <beans:property name="mediaTypes">
+      <beans:map>
+        <beans:entry key="html" value="text/html" />
+        <beans:entry key="xml" value="application/xml" />
+        <beans:entry key="json" value="application/json" />
+      </beans:map>
+    </beans:property>
+
+    <beans:property name="defaultViews">
+      <beans:list>
+        <beans:bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
+        <beans:bean class="org.springframework.web.servlet.view.xml.MarshallingView">
+          <beans:constructor-arg ref="jaxb2Marshaller" />
+        </beans:bean>
+      </beans:list>
+    </beans:property>
+
+    <beans:property name="defaultContentType" value="text/html" />
+  </beans:bean>
+
+  <beans:bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
+    <beans:property name="resourceLoaderPath" value="/WEB-INF/views/" />
+  </beans:bean>
+
+  <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
+    <beans:property name="cache" value="true" />
+    <beans:property name="prefix" value="" />
+    <beans:property name="suffix" value=".vm" />
+  </beans:bean>
+
+
+  <!-- <beans:bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> -->
+  <!-- <beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> -->
+  <!-- <beans:property name="prefix" value="/WEB-INF/views/" /> -->
+  <!-- <beans:property name="suffix" value=".jsp" /> -->
+  <!-- </beans:bean> -->
+
 </beans:beans>

=== added directory 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views'
=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm'
--- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/element.vm	2011-11-03 16:43:51 +0000
@@ -0,0 +1,6 @@
+
+<a href="../elements">All elements</a>
+
+<p>
+$element.name
+</p>

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm'
--- dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/webapp/WEB-INF/views/elements.vm	2011-11-03 16:43:51 +0000
@@ -0,0 +1,10 @@
+
+<p>
+Elements [<a href="elements.json">JSON</a>, <a href="elements.xml">XML</a>]</li>
+</p>
+
+<ul>
+#foreach( $element in $elements.elements )
+	<li><a href="elements/$element.uid">$element.name</a> [<a href="elements/${element.uid}.json">JSON</a>, <a href="elements/${element.uid}.xml">XML</a>]</li>	
+#end
+</ul>

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2011-11-02 11:14:35 +0000
+++ dhis-2/pom.xml	2011-11-03 16:43:51 +0000
@@ -314,6 +314,11 @@
       </dependency>
       <dependency>
         <groupId>org.springframework</groupId>
+        <artifactId>spring-oxm</artifactId>
+        <version>${spring.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework</groupId>
         <artifactId>spring-test</artifactId>
         <version>${spring.version}</version>
       </dependency>
@@ -749,6 +754,19 @@
         </exclusions>
       </dependency>
 
+      <!-- Jackson JSON Mapper -->
+      <dependency>
+        <groupId>org.codehaus.jackson</groupId>
+        <artifactId>jackson-mapper-asl</artifactId>
+        <version>1.6.4</version>
+      </dependency>
+
+      <dependency>
+        <groupId>javax.xml.bind</groupId>
+        <artifactId>jaxb-api</artifactId>
+        <version>2.0</version>
+      </dependency>
+
     </dependencies>
   </dependencyManagement>