← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5360: merge with dxf2: added support for constant and sqlview

 

Merge authors:
  Morten Olav Hansen (mortenoh)
------------------------------------------------------------
revno: 5360 [merge]
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2011-12-11 01:23:27 +0100
message:
  merge with dxf2: added support for constant and sqlview
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ConstantXmlAdapter.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/SqlViewXmlAdapter.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constants.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViews.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SqlViewController.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java
  dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java


--
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
=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ConstantXmlAdapter.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ConstantXmlAdapter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/ConstantXmlAdapter.java	2011-12-11 00:00:06 +0000
@@ -0,0 +1,60 @@
+package org.hisp.dhis.common.adapter;
+
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.constant.Constant;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import java.util.UUID;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class ConstantXmlAdapter extends XmlAdapter<BaseIdentifiableObject, Constant>
+{
+    private BaseIdentifiableObjectXmlAdapter baseIdentifiableObjectXmlAdapter = new BaseIdentifiableObjectXmlAdapter();
+
+    @Override
+    public Constant unmarshal( BaseIdentifiableObject identifiableObject ) throws Exception
+    {
+        Constant constant = new Constant();
+
+        constant.setUid( identifiableObject.getUid() );
+        constant.setLastUpdated( identifiableObject.getLastUpdated() );
+        constant.setName( identifiableObject.getName() == null ? UUID.randomUUID().toString() : identifiableObject.getName() );
+
+        return constant;
+    }
+
+    @Override
+    public BaseIdentifiableObject marshal( Constant constant ) throws Exception
+    {
+        return baseIdentifiableObjectXmlAdapter.marshal( constant );
+    }
+}

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/SqlViewXmlAdapter.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/SqlViewXmlAdapter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/adapter/SqlViewXmlAdapter.java	2011-12-11 00:21:52 +0000
@@ -0,0 +1,60 @@
+package org.hisp.dhis.common.adapter;
+
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.sqlview.SqlView;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import java.util.UUID;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class SqlViewXmlAdapter extends XmlAdapter<BaseIdentifiableObject, SqlView>
+{
+    private BaseIdentifiableObjectXmlAdapter baseIdentifiableObjectXmlAdapter = new BaseIdentifiableObjectXmlAdapter();
+
+    @Override
+    public SqlView unmarshal( BaseIdentifiableObject identifiableObject ) throws Exception
+    {
+        SqlView sqlView = new SqlView();
+
+        sqlView.setUid( identifiableObject.getUid() );
+        sqlView.setLastUpdated( identifiableObject.getLastUpdated() );
+        sqlView.setName( identifiableObject.getName() == null ? UUID.randomUUID().toString() : identifiableObject.getName() );
+
+        return sqlView;
+    }
+
+    @Override
+    public BaseIdentifiableObject marshal( SqlView sqlView ) throws Exception
+    {
+        return baseIdentifiableObjectXmlAdapter.marshal( sqlView );
+    }
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java	2011-12-09 20:53:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constant.java	2011-12-11 00:00:06 +0000
@@ -38,7 +38,6 @@
 
 /**
  * @author Dang Duy Hieu
- * @version $Id Constant.java June 29, 2011$
  */
 @XmlRootElement( name = "constant", namespace = Dxf2Namespace.NAMESPACE )
 @XmlAccessorType( value = XmlAccessType.NONE )

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java	2011-07-12 12:15:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/ConstantService.java	2011-12-11 00:00:06 +0000
@@ -50,23 +50,25 @@
 
     Constant getConstant( int constantId );
 
+    public Constant getConstant( String uid );
+
     Constant getConstantByName( String constantName );
 
     Collection<Constant> getAllConstants();
-    
+
     Map<Integer, Double> getConstantMap();
-    
+
     Map<String, Double> getConstantParameterMap();
-    
+
     // -------------------------------------------------------------------------
     // Constant expanding
     // -------------------------------------------------------------------------
-    
+
     Collection<Constant> getConstantsBetween( int first, int max );
-    
+
     Collection<Constant> getConstantsBetweenByName( String name, int first, int max );
-    
+
     int getConstantCount();
-    
-    int getConstantCountByName( String name );    
+
+    int getConstantCountByName( String name );
 }

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constants.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constants.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/constant/Constants.java	2011-12-11 00:00:06 +0000
@@ -0,0 +1,68 @@
+package org.hisp.dhis.constant;
+
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.BaseLinkableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.common.adapter.ConstantXmlAdapter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@XmlRootElement( name = "constants", namespace = Dxf2Namespace.NAMESPACE )
+@XmlAccessorType( value = XmlAccessType.NONE )
+public class Constants extends BaseLinkableObject
+{
+    private List<Constant> constants = new ArrayList<Constant>();
+
+    @XmlElement( name = "constant" )
+    @XmlJavaTypeAdapter( ConstantXmlAdapter.class )
+    @JsonProperty( value = "constants" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    public List<Constant> getConstants()
+    {
+        return constants;
+    }
+
+    public void setConstants( List<Constant> constants )
+    {
+        this.constants = constants;
+    }
+}

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java	2010-08-11 08:38:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlView.java	2011-12-11 00:21:52 +0000
@@ -26,20 +26,26 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
 /**
  * @author Dang Duy Hieu
- * @version $Id SqlView.java July 06, 2010$
  */
-public class SqlView
+@XmlRootElement( name = "sqlView", namespace = Dxf2Namespace.NAMESPACE )
+@XmlAccessorType( value = XmlAccessType.NONE )
+public class SqlView extends BaseIdentifiableObject
 {
     // -------------------------------------------------------------------------
     // Variables
     // -------------------------------------------------------------------------
 
-    private int id;
-
-    private String name;
-
     private String description;
 
     private String sqlQuery;
@@ -50,6 +56,7 @@
 
     public SqlView()
     {
+
     }
 
     public SqlView( String name, String sqlQuery )
@@ -59,50 +66,6 @@
     }
 
     // -------------------------------------------------------------------------
-    // Getters and setters
-    // -------------------------------------------------------------------------
-
-    public int getId()
-    {
-        return id;
-    }
-
-    public void setId( int id )
-    {
-        this.id = id;
-    }
-
-    public String getName()
-    {
-        return name;
-    }
-
-    public void setName( String name )
-    {
-        this.name = name;
-    }
-
-    public String getDescription()
-    {
-        return description;
-    }
-
-    public void setDescription( String description )
-    {
-        this.description = description;
-    }
-
-    public String getSqlQuery()
-    {
-        return sqlQuery;
-    }
-
-    public void setSqlQuery( String sqlQuery )
-    {
-        this.sqlQuery = sqlQuery;
-    }
-
-    // -------------------------------------------------------------------------
     // hashCode, equals and toString
     // -------------------------------------------------------------------------
 
@@ -159,4 +122,31 @@
         return "[ Name: " + name + ",\n\n sqlQuery: " + sqlQuery + " ]";
     }
 
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    @XmlElement
+    @JsonProperty
+    public String getDescription()
+    {
+        return description;
+    }
+
+    public void setDescription( String description )
+    {
+        this.description = description;
+    }
+
+    @XmlElement
+    @JsonProperty
+    public String getSqlQuery()
+    {
+        return sqlQuery;
+    }
+
+    public void setSqlQuery( String sqlQuery )
+    {
+        this.sqlQuery = sqlQuery;
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2011-06-29 08:51:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViewService.java	2011-12-11 00:21:52 +0000
@@ -49,6 +49,8 @@
 
     SqlView getSqlView( int viewId );
 
+    SqlView getSqlViewByUid( String uid );
+
     SqlView getSqlView( String viewName );
 
     Collection<SqlView> getAllSqlViews();

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViews.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViews.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/sqlview/SqlViews.java	2011-12-11 00:21:52 +0000
@@ -0,0 +1,67 @@
+package org.hisp.dhis.sqlview;
+
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.BaseLinkableObject;
+import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.common.adapter.SqlViewXmlAdapter;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@XmlRootElement( name = "sqlViews", namespace = Dxf2Namespace.NAMESPACE )
+@XmlAccessorType( value = XmlAccessType.NONE )
+public class SqlViews extends BaseLinkableObject
+{
+    private List<SqlView> sqlViews = new ArrayList<SqlView>();
+
+    @XmlElement( name = "sqlView" )
+    @XmlJavaTypeAdapter( SqlViewXmlAdapter.class )
+    @JsonProperty( value = "sqlViews" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    public List<SqlView> getSqlViews()
+    {
+        return sqlViews;
+    }
+
+    public void setSqlViews( List<SqlView> sqlViews )
+    {
+        this.sqlViews = sqlViews;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2011-01-06 17:07:18 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/sqlview/DefaultSqlViewService.java	2011-12-11 00:21:52 +0000
@@ -26,11 +26,12 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-import java.util.Collection;
 
 import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.Collection;
+
 /**
  * @author Dang Duy Hieu
  * @version $Id DefaultSqlViewService.java July 06, 2010$
@@ -80,6 +81,12 @@
     }
 
     @Override
+    public SqlView getSqlViewByUid( String uid )
+    {
+        return sqlViewStore.getByUid( uid );
+    }
+
+    @Override
     public SqlView getSqlView( String viewName )
     {
         return sqlViewStore.getByName( viewName );
@@ -129,7 +136,7 @@
     public boolean createAllViewTables()
     {
         boolean success = true;
-        
+
         for ( SqlView sqlView : getAllSqlViews() )
         {
             if ( !createViewTable( sqlView ) )
@@ -137,10 +144,10 @@
                 success = false;
             }
         }
-        
+
         return success;
     }
-    
+
     @Override
     public boolean createViewTable( SqlView sqlViewInstance )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml'
--- dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml	2011-05-28 21:25:46 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/resources/org/hisp/dhis/sqlview/hibernate/SqlView.hbm.xml	2011-12-11 00:21:52 +0000
@@ -1,7 +1,9 @@
 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC
-  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
-  "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
+    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";
+    [<!ENTITY identifiableProperties SYSTEM "classpath://org/hisp/dhis/common/identifiableProperties.hbm">]
+    >
 
 <hibernate-mapping>
   <class name="org.hisp.dhis.sqlview.SqlView" table="sqlview">
@@ -9,10 +11,7 @@
     <id name="id" column="viewid">
       <generator class="native" />
     </id>
-
-    <property name="name">
-      <column name="name" not-null="true" unique="true" length="50" />
-    </property>
+    &identifiableProperties;
 
     <property name="description" type="text" />
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2011-12-10 23:03:56 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/IdentityPopulator.java	2011-12-11 00:21:52 +0000
@@ -51,7 +51,7 @@
 
     private static String[] tables = { "chart", "constant", "attribute", "indicatortype", "indicatorgroupset", "indicator",
         "indicatorgroup", "datadictionary", "validationrulegroup", "validationrule", "dataset", "orgunitlevel", "document",
-        "organisationunit", "orgunitgroup", "orgunitgroupset", "dataelementcategoryoption", "dataelementgroup",
+        "organisationunit", "orgunitgroup", "orgunitgroupset", "dataelementcategoryoption", "dataelementgroup", "sqlview",
         "dataelement", "dataelementgroupset", "dataelementcategory", "categorycombo", "categoryoptioncombo", "mapview" };
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java	2011-07-12 12:15:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/constant/DefaultConstantService.java	2011-12-11 00:00:06 +0000
@@ -76,6 +76,11 @@
         return constantStore.get( constantId );
     }
 
+    public Constant getConstant( String uid )
+    {
+        return constantStore.getByUid( uid );
+    }
+
     public Constant getConstantByName( String constantName )
     {
         return constantStore.getByName( constantName );

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/ConstantController.java	2011-12-11 00:00:06 +0000
@@ -0,0 +1,145 @@
+package org.hisp.dhis.api.controller;
+
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.api.utils.IdentifiableObjectParams;
+import org.hisp.dhis.api.utils.WebLinkPopulator;
+import org.hisp.dhis.constant.Constant;
+import org.hisp.dhis.constant.ConstantService;
+import org.hisp.dhis.constant.Constants;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+import java.util.ArrayList;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Controller
+@RequestMapping( value = ConstantController.RESOURCE_PATH )
+public class ConstantController
+{
+    public static final String RESOURCE_PATH = "/constants";
+
+    @Autowired
+    private ConstantService constantService;
+
+    //-------------------------------------------------------------------------------------------------------
+    // GET
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( method = RequestMethod.GET )
+    public String getConstants( IdentifiableObjectParams params, Model model, HttpServletRequest request )
+    {
+        Constants constants = new Constants();
+        constants.setConstants( new ArrayList<Constant>( constantService.getAllConstants() ) );
+
+        if ( params.hasLinks() )
+        {
+            WebLinkPopulator listener = new WebLinkPopulator( request );
+            listener.addLinks( constants );
+        }
+
+        model.addAttribute( "model", constants );
+
+        return "constants";
+    }
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
+    public String getConstant( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request )
+    {
+        Constant constant = constantService.getConstant( uid );
+
+        if ( params.hasLinks() )
+        {
+            WebLinkPopulator listener = new WebLinkPopulator( request );
+            listener.addLinks( constant );
+        }
+
+        model.addAttribute( "model", constant );
+
+        return "category";
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // POST
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} )
+    @ResponseStatus( value = HttpStatus.CREATED )
+    public void postConstantXML( HttpServletResponse response, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
+    }
+
+    @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} )
+    @ResponseStatus( value = HttpStatus.CREATED )
+    public void postConstantJSON( HttpServletResponse response, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // PUT
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/xml, text/xml"} )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void putConstantXML( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() );
+    }
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/json"} )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void putConstantJSON( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // DELETE
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void deleteConstant( @PathVariable( "uid" ) String uid ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() );
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SqlViewController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SqlViewController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/SqlViewController.java	2011-12-11 00:21:52 +0000
@@ -0,0 +1,145 @@
+package org.hisp.dhis.api.controller;
+
+/*
+ * Copyright (c) 2004-2011, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.hisp.dhis.api.utils.IdentifiableObjectParams;
+import org.hisp.dhis.api.utils.WebLinkPopulator;
+import org.hisp.dhis.sqlview.SqlView;
+import org.hisp.dhis.sqlview.SqlViewService;
+import org.hisp.dhis.sqlview.SqlViews;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.HttpRequestMethodNotSupportedException;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.InputStream;
+import java.util.ArrayList;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@Controller
+@RequestMapping( value = SqlViewController.RESOURCE_PATH )
+public class SqlViewController
+{
+    public static final String RESOURCE_PATH = "/sqlViews";
+
+    @Autowired
+    private SqlViewService sqlViewService;
+
+    //-------------------------------------------------------------------------------------------------------
+    // GET
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( method = RequestMethod.GET )
+    public String getSqlViews( IdentifiableObjectParams params, Model model, HttpServletRequest request )
+    {
+        SqlViews sqlViews = new SqlViews();
+        sqlViews.setSqlViews( new ArrayList<SqlView>( sqlViewService.getAllSqlViews() ) );
+
+        if ( params.hasLinks() )
+        {
+            WebLinkPopulator listener = new WebLinkPopulator( request );
+            listener.addLinks( sqlViews );
+        }
+
+        model.addAttribute( "model", sqlViews );
+
+        return "sqlViews";
+    }
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.GET )
+    public String getSqlView( @PathVariable( "uid" ) String uid, IdentifiableObjectParams params, Model model, HttpServletRequest request )
+    {
+        SqlView sqlView = sqlViewService.getSqlViewByUid( uid );
+
+        if ( params.hasLinks() )
+        {
+            WebLinkPopulator listener = new WebLinkPopulator( request );
+            listener.addLinks( sqlView );
+        }
+
+        model.addAttribute( "model", sqlView );
+
+        return "indicator";
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // POST
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml, text/xml"} )
+    @ResponseStatus( value = HttpStatus.CREATED )
+    public void postSqlViewXML( HttpServletResponse response, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
+    }
+
+    @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/json"} )
+    @ResponseStatus( value = HttpStatus.CREATED )
+    public void postSqlViewJSON( HttpServletResponse response, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.POST.toString() );
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // PUT
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/xml, text/xml"} )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void putSqlViewXML( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() );
+    }
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, headers = {"Content-Type=application/json"} )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void putSqlViewJSON( @PathVariable( "uid" ) String uid, InputStream input ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.PUT.toString() );
+    }
+
+    //-------------------------------------------------------------------------------------------------------
+    // DELETE
+    //-------------------------------------------------------------------------------------------------------
+
+    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
+    @ResponseStatus( value = HttpStatus.NO_CONTENT )
+    public void deleteSqlView( @PathVariable( "uid" ) String uid ) throws Exception
+    {
+        throw new HttpRequestMethodNotSupportedException( RequestMethod.DELETE.toString() );
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java	2011-12-10 23:22:51 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/utils/WebLinkPopulator.java	2011-12-11 00:21:52 +0000
@@ -38,6 +38,8 @@
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.BaseLinkableObject;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.constant.Constant;
+import org.hisp.dhis.constant.Constants;
 import org.hisp.dhis.dataelement.*;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSets;
@@ -47,6 +49,8 @@
 import org.hisp.dhis.mapping.MapView;
 import org.hisp.dhis.mapping.Maps;
 import org.hisp.dhis.organisationunit.*;
+import org.hisp.dhis.sqlview.SqlView;
+import org.hisp.dhis.sqlview.SqlViews;
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleGroup;
 import org.hisp.dhis.validation.ValidationRuleGroups;
@@ -269,6 +273,68 @@
         {
             populateValidationRuleGroup( (ValidationRuleGroup) source, true );
         }
+        else if ( source instanceof Constants )
+        {
+            populateConstants( (Constants) source, true );
+        }
+        else if ( source instanceof Constant )
+        {
+            populateConstant( (Constant) source, true );
+        }
+        else if ( source instanceof SqlViews )
+        {
+            populateSqlViews( (SqlViews) source, true );
+        }
+        else if ( source instanceof SqlView )
+        {
+            populateSqlView( (SqlView) source, true );
+        }
+    }
+
+    private void populateSqlViews( SqlViews sqlViews, boolean root )
+    {
+        sqlViews.setLink( getBasePath( sqlViews.getClass() ) );
+
+        if ( root )
+        {
+            for ( SqlView sqlView : sqlViews.getSqlViews() )
+            {
+                populateSqlView( sqlView, false );
+            }
+        }
+    }
+
+    private void populateSqlView( SqlView sqlView, boolean root )
+    {
+        populateIdentifiableObject( sqlView );
+
+        if ( root )
+        {
+
+        }
+    }
+
+    private void populateConstants( Constants constants, boolean root )
+    {
+        constants.setLink( getBasePath( constants.getClass() ) );
+
+        if ( root )
+        {
+            for ( Constant constant : constants.getConstants() )
+            {
+                populateConstant( constant, false );
+            }
+        }
+    }
+
+    private void populateConstant( Constant constant, boolean root )
+    {
+        populateIdentifiableObject( constant );
+
+        if ( root )
+        {
+
+        }
     }
 
     private void populateDocuments( Documents documents, boolean root )