← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4913: added code field to categoryoption

 

------------------------------------------------------------
revno: 4913
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Wed 2011-10-12 21:25:07 +0100
message:
  added code field to categoryoption
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionStoreTest.java
  dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementCategoryOptionBatchHandler.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
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java	2011-05-05 21:14:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOption.java	2011-10-12 20:25:07 +0000
@@ -29,9 +29,9 @@
 
 import java.util.HashSet;
 import java.util.Set;
-
 import org.hisp.dhis.common.AbstractNameableObject;
 
+
 /**
  * @author Abyot Asalefew
  * @version $Id$

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java	2011-09-27 15:51:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java	2011-10-12 20:25:07 +0000
@@ -148,7 +148,14 @@
      * @return the DataElementCategoryOption with the given name.
      */
     DataElementCategoryOption getDataElementCategoryOptionByName( String name );
-    
+
+    /**
+     * Retrieves the DataElementCategoryOption with the given code.
+     * @param code the code.
+     * @return the DataElementCategoryOption with the given code.
+     */
+    DataElementCategoryOption getDataElementCategoryOptionByCode( String code );
+
     /**
      * Returns all DataElementCategoryOptions.
      * 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2011-09-27 15:51:10 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java	2011-10-12 20:25:07 +0000
@@ -177,6 +177,12 @@
         return dataElementCategoryOptionStore.getByName( name );
     }
 
+    @Override
+    public DataElementCategoryOption getDataElementCategoryOptionByCode( String code )
+    {
+        return dataElementCategoryOptionStore.getByCode( code );
+    }
+
     public Collection<DataElementCategoryOption> getDataElementCategoryOptions( final Collection<Integer> identifiers )
     {
         Collection<DataElementCategoryOption> categoryOptions = getAllDataElementCategoryOptions();
@@ -544,4 +550,5 @@
     {
         return dataElementCategoryComboStore.getBetweenByName( name, first, max );
     }
+
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml	2011-05-28 21:25:46 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOption.hbm.xml	2011-10-12 20:25:07 +0000
@@ -3,18 +3,21 @@
   "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
   "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd";>
 
-<hibernate-mapping>
+<hibernate-mapping>
   <class name="org.hisp.dhis.dataelement.DataElementCategoryOption" table="dataelementcategoryoption">
 
     <cache usage="read-write" />
 
-    <id name="id" column="categoryoptionid">
-      <generator class="native" />
+    <id name="id" column="categoryoptionid">
+      <generator class="native" />
     </id>
 
-    <property name="uuid" length="40" />
-    <property name="name">
-      <column name="name" not-null="true" unique="true" length="160" />
+    <property name="uuid" length="40" />
+    <property name="name">
+      <column name="name" not-null="true" unique="true" length="160" />
+    </property>
+    <property name="code">
+      <column name="code" unique="true" length="160" />
     </property>
 
     <set name="categoryOptionCombos" table="categoryoptioncombos_categoryoptions" inverse="true">
@@ -28,6 +31,6 @@
       <key column="categoryoptionid" />
       <many-to-one column="categoryid" name="category" />
     </join>
-
-  </class>
-</hibernate-mapping>
+
+  </class>
+</hibernate-mapping>

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionServiceTest.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionServiceTest.java	2011-10-12 20:25:07 +0000
@@ -68,17 +68,28 @@
         categoryOptionA = new DataElementCategoryOption( "CategoryOptionA" );
         categoryOptionB = new DataElementCategoryOption( "CategoryOptionB" );
         categoryOptionC = new DataElementCategoryOption( "CategoryOptionC" );
-        
+
         int idA = categoryService.addDataElementCategoryOption( categoryOptionA );
         int idB = categoryService.addDataElementCategoryOption( categoryOptionB );
         int idC = categoryService.addDataElementCategoryOption( categoryOptionC );
-        
+
         assertEquals( categoryOptionA, categoryService.getDataElementCategoryOption( idA ) );
         assertEquals( categoryOptionB, categoryService.getDataElementCategoryOption( idB ) );
         assertEquals( categoryOptionC, categoryService.getDataElementCategoryOption( idC ) );
     }
 
     @Test
+    public void testCode()
+    {
+        categoryOptionA = new DataElementCategoryOption( "CategoryOptionA" );
+        categoryOptionA.setCode( "12345");
+
+        int idA = categoryService.addDataElementCategoryOption( categoryOptionA );
+
+        assertEquals( "12345", categoryService.getDataElementCategoryOption( idA ).getCode() );
+    }
+
+    @Test
     public void testDelete()
     {
         categoryOptionA = new DataElementCategoryOption( "CategoryOptionA" );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionStoreTest.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionStoreTest.java	2011-10-12 20:25:07 +0000
@@ -119,12 +119,47 @@
         categoryOptionStore.save( categoryOptionA );
         categoryOptionStore.save( categoryOptionB );
         categoryOptionStore.save( categoryOptionC );
-        
+
         Collection<DataElementCategoryOption> categoryOptions = categoryOptionStore.getAll();
-        
+
         assertEquals( 4, categoryOptions.size() ); // Including default
         assertTrue( categoryOptions.contains( categoryOptionA ) );
         assertTrue( categoryOptions.contains( categoryOptionB ) );
-        assertTrue( categoryOptions.contains( categoryOptionC ) );        
-    }
+        assertTrue( categoryOptions.contains( categoryOptionC ) );
+    }
+
+    @Test
+    public void testGetByCode()
+    {
+        categoryOptionA = new DataElementCategoryOption( "CategoryOptionA" );
+        categoryOptionA.setCode("CODE_RED");
+        categoryOptionB = new DataElementCategoryOption( "CategoryOptionB" );
+        categoryOptionC = new DataElementCategoryOption( "CategoryOptionC" );
+
+        categoryOptionStore.save( categoryOptionA );
+
+        categoryOptionStore.getByCode( "CODE_RED");
+
+        assertEquals( "CODE_RED", categoryOptionA.getCode() );
+        assertEquals( "CategoryOptionA", categoryOptionA.getName() );
+    }
+
+    @Test
+    public void testUniqueCode()
+    {
+        categoryOptionA = new DataElementCategoryOption( "CategoryOptionA" );
+        categoryOptionA.setCode("CODE_RED");
+        categoryOptionB = new DataElementCategoryOption( "CategoryOptionB" );
+        categoryOptionB.setCode("CODE_RED");
+
+        categoryOptionStore.save( categoryOptionA );
+
+        Exception ex = null;
+        try {
+            categoryOptionStore.save( categoryOptionB );
+        } catch (Exception ex2) { ex = ex2;}
+
+        assertEquals( "class org.hibernate.exception.ConstraintViolationException", ex.getClass().toString() );
+    }
+    
 }

=== modified file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementCategoryOptionBatchHandler.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementCategoryOptionBatchHandler.java	2010-11-23 16:12:57 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementCategoryOptionBatchHandler.java	2011-10-12 20:25:07 +0000
@@ -51,6 +51,7 @@
     // AbstractBatchHandler implementation
     // -------------------------------------------------------------------------
 
+    @Override
     protected void setTableName()
     {
         statementBuilder.setTableName( "dataelementcategoryoption" );
@@ -74,24 +75,32 @@
         statementBuilder.setIdentifierValue( categoryOption.getId() );
     }
     
+    @Override
     protected void setUniqueColumns()
     {
+        statementBuilder.setUniqueColumn( "code" );
         statementBuilder.setUniqueColumn( "name" );
     }
     
+    @Override
     protected void setUniqueValues( DataElementCategoryOption categoryOption )
     {        
+        statementBuilder.setUniqueValue( categoryOption.getCode() );
         statementBuilder.setUniqueValue( categoryOption.getName() );
     }
     
+    @Override
     protected void setColumns()
     {
+        statementBuilder.setColumn( "code" );
         statementBuilder.setColumn( "name" );
         statementBuilder.setColumn( "uuid" );
     }
     
+    @Override
     protected void setValues( DataElementCategoryOption categoryOption )
     {        
+        statementBuilder.setValue( categoryOption.getCode() );
         statementBuilder.setValue( categoryOption.getName() );
         statementBuilder.setValue( categoryOption.getUuid() );
     }