← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20309: Category option combo, made the categoryCombo association not-null in hibernate mapping

 

------------------------------------------------------------
revno: 20309
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-09-23 12:48:14 +0200
message:
  Category option combo, made the categoryCombo association not-null in hibernate mapping
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/minmax/MinMaxDataElementStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.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/DataElementCategoryOptionCombo.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2015-09-23 09:36:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryOptionCombo.java	2015-09-23 10:48:14 +0000
@@ -36,6 +36,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.BaseNameableObject;
 import org.hisp.dhis.common.DxfNamespaces;
@@ -318,7 +319,7 @@
             builder.delete( Math.max( builder.length() - 2, 0 ), builder.length() ).append( ")" );
         }
         
-        return  builder.toString();
+        return StringUtils.substring( builder.toString(), 0, 255 );
     }
 
     @Override

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2015-09-23 06:56:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2015-09-23 10:48:14 +0000
@@ -447,6 +447,7 @@
     @JsonProperty
     @JacksonXmlElementWrapper( localName = "references", namespace = DxfNamespaces.DXF_2_0 )
     @JacksonXmlProperty( localName = "reference", namespace = DxfNamespaces.DXF_2_0 )
+    @SuppressWarnings("rawtypes")
     public Set<Class> getReferences()
     {
         return getProperties().stream()

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml	2015-04-07 10:51:20 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElementCategoryOptionCombo.hbm.xml	2015-09-23 10:48:14 +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";>
+  "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.dataelement.DataElementCategoryOptionCombo" table="categoryoptioncombo">
@@ -11,15 +13,8 @@
     <id name="id" column="categoryoptioncomboid">
       <generator class="native" />
     </id>
-
-    <property name="uid" column="uid" length="11" />
-
-    <property name="code" column="code" not-null="false" unique="true" length="50" />
-
-    <property name="created" type="timestamp" />
-
-    <property name="lastUpdated" type="timestamp" />
-
+    &identifiableProperties;
+    
     <set name="categoryOptions" table="categoryoptioncombos_categoryoptions">
       <cache usage="read-write" />
       <key column="categoryoptioncomboid" foreign-key="fk_categoryoptioncombos_categoryoptions_categoryoptioncomboid" />
@@ -31,7 +26,7 @@
 
     <join table="categorycombos_optioncombos">
       <key column="categoryoptioncomboid" />
-      <many-to-one name="categoryCombo" column="categorycomboid" />
+      <many-to-one name="categoryCombo" column="categorycomboid" not-null="true" />
     </join>
 
   </class>

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboServiceTest.java	2015-09-23 10:48:14 +0000
@@ -32,7 +32,6 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
-import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
@@ -41,6 +40,8 @@
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import com.google.common.collect.Sets;
+
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -115,10 +116,7 @@
     {
         categoryOptionComboA = new DataElementCategoryOptionCombo();
         
-        Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
-        
-        categoryOptions.add( categoryOptionA );
-        categoryOptions.add( categoryOptionB );        
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );        
         
         categoryOptionComboA.setCategoryCombo( categoryComboA );
         categoryOptionComboA.setCategoryOptions( categoryOptions );        
@@ -149,11 +147,8 @@
     public void testUpdateGetDataElementCategoryOptionCombo()
     {
         categoryOptionComboA = new DataElementCategoryOptionCombo();
-        
-        Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
-        
-        categoryOptions.add( categoryOptionA );
-        categoryOptions.add( categoryOptionB );        
+
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );        
         
         categoryOptionComboA.setCategoryCombo( categoryComboA );
         categoryOptionComboA.setCategoryOptions( categoryOptions );        
@@ -183,7 +178,17 @@
         categoryOptionComboA = new DataElementCategoryOptionCombo();
         categoryOptionComboB = new DataElementCategoryOptionCombo();
         categoryOptionComboC = new DataElementCategoryOptionCombo();
-        
+
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );     
+        
+        categoryOptionComboA.setCategoryCombo( categoryComboA );
+        categoryOptionComboB.setCategoryCombo( categoryComboA );
+        categoryOptionComboC.setCategoryCombo( categoryComboA );
+        
+        categoryOptionComboA.setCategoryOptions( categoryOptions );
+        categoryOptionComboB.setCategoryOptions( categoryOptions );
+        categoryOptionComboC.setCategoryOptions( categoryOptions );
+
         int idA = categoryService.addDataElementCategoryOptionCombo( categoryOptionComboA );
         int idB = categoryService.addDataElementCategoryOptionCombo( categoryOptionComboB );
         int idC = categoryService.addDataElementCategoryOptionCombo( categoryOptionComboC );
@@ -217,7 +222,17 @@
         categoryOptionComboA = new DataElementCategoryOptionCombo();
         categoryOptionComboB = new DataElementCategoryOptionCombo();
         categoryOptionComboC = new DataElementCategoryOptionCombo();
-        
+
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );     
+        
+        categoryOptionComboA.setCategoryCombo( categoryComboA );
+        categoryOptionComboB.setCategoryCombo( categoryComboA );
+        categoryOptionComboC.setCategoryCombo( categoryComboA );
+        
+        categoryOptionComboA.setCategoryOptions( categoryOptions );
+        categoryOptionComboB.setCategoryOptions( categoryOptions );
+        categoryOptionComboC.setCategoryOptions( categoryOptions );
+
         categoryService.addDataElementCategoryOptionCombo( categoryOptionComboA );
         categoryService.addDataElementCategoryOptionCombo( categoryOptionComboB );
         categoryService.addDataElementCategoryOptionCombo( categoryOptionComboC );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java	2015-06-16 05:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryOptionComboStoreTest.java	2015-09-23 10:48:14 +0000
@@ -40,6 +40,8 @@
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import com.google.common.collect.Sets;
+
 /**
  * @author Lars Helge Overland
  */
@@ -115,11 +117,8 @@
     public void testAddGetDataElementCategoryOptionCombo()
     {
         categoryOptionComboA = new DataElementCategoryOptionCombo();
-        
-        Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
-        
-        categoryOptions.add( categoryOptionA );
-        categoryOptions.add( categoryOptionB );        
+
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );        
         
         categoryOptionComboA.setCategoryCombo( categoryComboA );
         categoryOptionComboA.setCategoryOptions( categoryOptions );        
@@ -137,11 +136,8 @@
     public void testUpdateGetDataElementCategoryOptionCombo()
     {
         categoryOptionComboA = new DataElementCategoryOptionCombo();
-        
-        Set<DataElementCategoryOption> categoryOptions = new HashSet<>();
-        
-        categoryOptions.add( categoryOptionA );
-        categoryOptions.add( categoryOptionB );        
+
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );        
         
         categoryOptionComboA.setCategoryCombo( categoryComboA );
         categoryOptionComboA.setCategoryOptions( categoryOptions );        
@@ -171,7 +167,17 @@
         categoryOptionComboA = new DataElementCategoryOptionCombo();
         categoryOptionComboB = new DataElementCategoryOptionCombo();
         categoryOptionComboC = new DataElementCategoryOptionCombo();
-        
+
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );     
+        
+        categoryOptionComboA.setCategoryCombo( categoryComboA );
+        categoryOptionComboB.setCategoryCombo( categoryComboA );
+        categoryOptionComboC.setCategoryCombo( categoryComboA );
+        
+        categoryOptionComboA.setCategoryOptions( categoryOptions );
+        categoryOptionComboB.setCategoryOptions( categoryOptions );
+        categoryOptionComboC.setCategoryOptions( categoryOptions );
+
         int idA = categoryOptionComboStore.save( categoryOptionComboA );
         int idB = categoryOptionComboStore.save( categoryOptionComboB );
         int idC = categoryOptionComboStore.save( categoryOptionComboC );
@@ -205,7 +211,17 @@
         categoryOptionComboA = new DataElementCategoryOptionCombo();
         categoryOptionComboB = new DataElementCategoryOptionCombo();
         categoryOptionComboC = new DataElementCategoryOptionCombo();
-        
+
+        Set<DataElementCategoryOption> categoryOptions = Sets.newHashSet( categoryOptionA, categoryOptionB );     
+        
+        categoryOptionComboA.setCategoryCombo( categoryComboA );
+        categoryOptionComboB.setCategoryCombo( categoryComboA );
+        categoryOptionComboC.setCategoryCombo( categoryComboA );
+        
+        categoryOptionComboA.setCategoryOptions( categoryOptions );
+        categoryOptionComboB.setCategoryOptions( categoryOptions );
+        categoryOptionComboC.setCategoryOptions( categoryOptions );
+
         categoryOptionComboStore.save( categoryOptionComboA );
         categoryOptionComboStore.save( categoryOptionComboB );
         categoryOptionComboStore.save( categoryOptionComboC );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/minmax/MinMaxDataElementStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/minmax/MinMaxDataElementStoreTest.java	2015-09-15 09:54:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/minmax/MinMaxDataElementStoreTest.java	2015-09-23 10:48:14 +0000
@@ -48,14 +48,13 @@
 
 /**
  * @author Kristian Nordal
- * @version $Id: MinMaxDataElementStoreTest.java 5012 2008-04-24 21:14:40Z larshelg $
  */
 public class MinMaxDataElementStoreTest
     extends DhisSpringTest
 {
     @Autowired
     private DataElementService dataElementService;
-
+    
     @Autowired
     private OrganisationUnitService organisationUnitService;
 
@@ -107,26 +106,18 @@
         dataElementService.addDataElement( dataElement3 );
         dataElementService.addDataElement( dataElement4 );
 
-        DataElementCategoryOptionCombo optionCombo1 = new DataElementCategoryOptionCombo();
-        categoryService.addDataElementCategoryOptionCombo( optionCombo1 );
-
-        DataElementCategoryOptionCombo optionCombo2 = new DataElementCategoryOptionCombo();
-        categoryService.addDataElementCategoryOptionCombo( optionCombo2 );
-
-        MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement( source1, dataElement1, optionCombo1, 0, 100, false );
-        MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement( source2, dataElement2, optionCombo1, 0, 100, false );
-        MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement( source2, dataElement3, optionCombo1, 0, 100, false );
-        MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement( source2, dataElement4, optionCombo1, 0, 100, false );
-
-        MinMaxDataElement minMaxDataElement5 = new MinMaxDataElement( source1, dataElement1, optionCombo2, 0, 100, false );
+        DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+        
+        MinMaxDataElement minMaxDataElement1 = new MinMaxDataElement( source1, dataElement1, optionCombo, 0, 100, false );
+        MinMaxDataElement minMaxDataElement2 = new MinMaxDataElement( source2, dataElement2, optionCombo, 0, 100, false );
+        MinMaxDataElement minMaxDataElement3 = new MinMaxDataElement( source2, dataElement3, optionCombo, 0, 100, false );
+        MinMaxDataElement minMaxDataElement4 = new MinMaxDataElement( source2, dataElement4, optionCombo, 0, 100, false );
 
         int mmdeid1 = minMaxDataElementStore.save( minMaxDataElement1 );
-
         minMaxDataElementStore.save( minMaxDataElement2 );
         minMaxDataElementStore.save( minMaxDataElement3 );
         minMaxDataElementStore.save( minMaxDataElement4 );
-        minMaxDataElementStore.save( minMaxDataElement5 );
-
+        
         // ----------------------------------------------------------------------
         // Assertions
         // ----------------------------------------------------------------------
@@ -143,11 +134,11 @@
         dataElements2.add( dataElement3 );
         dataElements2.add( dataElement4 );
 
-        assertNotNull( minMaxDataElementStore.get( source1, dataElement1, optionCombo1 ) );
-        assertNull( minMaxDataElementStore.get( source2, dataElement1, optionCombo1 ) );
+        assertNotNull( minMaxDataElementStore.get( source1, dataElement1, optionCombo ) );
+        assertNull( minMaxDataElementStore.get( source2, dataElement1, optionCombo ) );
 
-        assertTrue( minMaxDataElementStore.get( source1, dataElements1 ).size() == 2 );
-        assertTrue( minMaxDataElementStore.get( source2, dataElements2 ).size() == 3 );
+        assertEquals( 1, minMaxDataElementStore.get( source1, dataElements1 ).size() );
+        assertEquals( 3, minMaxDataElementStore.get( source2, dataElements2 ).size() );
 
         minMaxDataElementStore.delete( minMaxDataElement1 );
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java	2015-09-14 10:15:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java	2015-09-23 10:48:14 +0000
@@ -28,7 +28,13 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.google.common.collect.Lists;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Iterator;
+
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
@@ -37,14 +43,10 @@
 import org.hisp.dhis.schema.Schema;
 import org.hisp.dhis.schema.SchemaService;
 import org.jfree.data.time.Year;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import java.util.Collection;
-import java.util.Iterator;
-
-import static org.junit.Assert.*;
+import com.google.common.collect.Lists;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>