← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22100: applies patch from Viet, adds categoryCombo not-null=true to data element

 

------------------------------------------------------------
revno: 22100
committer: Morten Olav Hansen <morten@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2016-03-02 11:34:21 +0700
message:
  applies patch from Viet, adds categoryCombo not-null=true to data element
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/AnalyticsUtilsTest.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementOperandServiceTest.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/InMemoryQueryEngineTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/DefaultExportServiceTest.java
  dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/AggregatableDataElementFilterTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/AnalyticsUtilsTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/AnalyticsUtilsTest.java	2016-02-27 10:57:15 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/AnalyticsUtilsTest.java	2016-03-02 04:34:21 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.DhisSpringTest;
 import org.junit.Test;
 
 import com.google.common.collect.Lists;
@@ -45,12 +46,10 @@
 import java.util.List;
 import java.util.Map;
 
-import static org.hisp.dhis.DhisConvenienceTest.*;
-
 /**
  * @author Lars Helge Overland
  */
-public class AnalyticsUtilsTest
+public class AnalyticsUtilsTest extends DhisSpringTest
 {
     @Test
     public void testGetByDataDimensionType()

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2016-02-27 06:45:15 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/startup/TableAlteror.java	2016-03-02 04:34:21 +0000
@@ -208,6 +208,10 @@
 
         executeSql( "ALTER TABLE organisationunit DROP COLUMN hasPatients" );
 
+        // dataelement_categorycombo not null
+        executeSql( "update dataelement set categorycomboid = " + defaultCategoryComboId + " where categorycomboid is null" );
+        executeSql( "alter table dataelement add constraint fk_dataelement_categorycombo foreign key (categorycomboid) references categorycombo (categorycomboid) match simple;" );
+
         // categories_categoryoptions
         // set to 0 temporarily
         int c1 = executeSql( "UPDATE categories_categoryoptions SET sort_order=0 WHERE sort_order is NULL OR sort_order=0" );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml	2015-11-26 04:04:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataelement/hibernate/DataElement.hbm.xml	2016-03-02 04:34:21 +0000
@@ -41,7 +41,7 @@
     </property>
 
     <many-to-one name="categoryCombo" class="org.hisp.dhis.dataelement.DataElementCategoryCombo"
-      column="categorycomboid" foreign-key="fk_dataelement_categorycomboid" />
+      column="categorycomboid" not-null="true" foreign-key="fk_dataelement_categorycomboid" />
 
     <property name="url" />
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementOperandServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementOperandServiceTest.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementOperandServiceTest.java	2016-03-02 04:34:21 +0000
@@ -61,7 +61,7 @@
         deA = createDataElement( 'A' );
         deB = createDataElement( 'B' );
         deC = createDataElement( 'C' );
-        
+
         dataElementService.addDataElement( deA );
         dataElementService.addDataElement( deB );
         dataElementService.addDataElement( deC );

=== 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	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/minmax/MinMaxDataElementStoreTest.java	2016-03-02 04:34:21 +0000
@@ -73,33 +73,10 @@
         organisationUnitService.addOrganisationUnit( source1 );
         organisationUnitService.addOrganisationUnit( source2 );
 
-        DataElement dataElement1 = new DataElement();
-        dataElement1.setName( "DE1name" );
-        dataElement1.setShortName( "DE1sname" );
-        dataElement1.setAggregationType( AggregationType.SUM );
-        dataElement1.setValueType( ValueType.INTEGER );
-        dataElement1.setDomainType( DataElementDomain.AGGREGATE );
-
-        DataElement dataElement2 = new DataElement();
-        dataElement2.setName( "DE2name" );
-        dataElement2.setShortName( "DE2sname" );
-        dataElement2.setAggregationType( AggregationType.SUM );
-        dataElement2.setValueType( ValueType.INTEGER );
-        dataElement2.setDomainType( DataElementDomain.AGGREGATE );
-
-        DataElement dataElement3 = new DataElement();
-        dataElement3.setName( "DE3name" );
-        dataElement3.setShortName( "DE3sname" );
-        dataElement3.setAggregationType( AggregationType.SUM );
-        dataElement3.setValueType( ValueType.INTEGER );
-        dataElement3.setDomainType( DataElementDomain.AGGREGATE );
-
-        DataElement dataElement4 = new DataElement();
-        dataElement4.setName( "DE4name" );
-        dataElement4.setShortName( "DE4sname" );
-        dataElement4.setAggregationType( AggregationType.SUM );
-        dataElement4.setValueType( ValueType.INTEGER );
-        dataElement4.setDomainType( DataElementDomain.AGGREGATE );
+        DataElement dataElement1 = createDataElement( 'A' );
+        DataElement dataElement2 = createDataElement( 'B' );
+        DataElement dataElement3 = createDataElement( 'C' );
+        DataElement dataElement4 = createDataElement( 'D' );
 
         dataElementService.addDataElement( dataElement1 );
         dataElementService.addDataElement( dataElement2 );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java	2016-01-21 06:36:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/InMemoryQueryEngineTest.java	2016-03-02 04:34:21 +0000
@@ -345,6 +345,25 @@
     }
 
     @Test
+    public void testIsNotNull()
+    {
+        Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
+        query.setObjects( dataElements );
+        query.add( Restrictions.isNotNull( "categoryCombo" ) );
+
+        List<? extends IdentifiableObject> objects = queryEngine.query( query );
+
+        assertEquals( 6, objects.size() );
+
+        assertTrue( collectionContainsUid( objects, "deabcdefghA" ) );
+        assertTrue( collectionContainsUid( objects, "deabcdefghB" ) );
+        assertTrue( collectionContainsUid( objects, "deabcdefghC" ) );
+        assertTrue( collectionContainsUid( objects, "deabcdefghD" ) );
+        assertTrue( collectionContainsUid( objects, "deabcdefghE" ) );
+        assertTrue( collectionContainsUid( objects, "deabcdefghF" ) );
+    }
+
+    @Test
     public void testIsNull()
     {
         Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
@@ -353,25 +372,6 @@
 
         List<? extends IdentifiableObject> objects = queryEngine.query( query );
 
-        assertEquals( 6, objects.size() );
-
-        assertTrue( collectionContainsUid( objects, "deabcdefghA" ) );
-        assertTrue( collectionContainsUid( objects, "deabcdefghB" ) );
-        assertTrue( collectionContainsUid( objects, "deabcdefghC" ) );
-        assertTrue( collectionContainsUid( objects, "deabcdefghD" ) );
-        assertTrue( collectionContainsUid( objects, "deabcdefghE" ) );
-        assertTrue( collectionContainsUid( objects, "deabcdefghF" ) );
-    }
-
-    @Test
-    public void testIsNotNull()
-    {
-        Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
-        query.setObjects( dataElements );
-        query.add( Restrictions.isNotNull( "categoryCombo" ) );
-
-        List<? extends IdentifiableObject> objects = queryEngine.query( query );
-
         assertEquals( 0, objects.size() );
     }
 

=== 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	2016-01-05 10:16:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/query/QueryServiceTest.java	2016-03-02 04:34:21 +0000
@@ -510,10 +510,10 @@
     }
 
     @Test
-    public void testIsNull()
+    public void testIsNotNull()
     {
         Query query = Query.from( schemaService.getDynamicSchema( DataElement.class ) );
-        query.add( Restrictions.isNull( "categoryCombo" ) );
+        query.add( Restrictions.isNotNull( "categoryCombo" ) );
 
         List<? extends IdentifiableObject> objects = queryService.query( query );
 
@@ -528,9 +528,9 @@
     }
 
     @Test
-    public void testIsNullUrl() throws QueryParserException
+    public void testIsNotNullUrl() throws QueryParserException
     {
-        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "categoryCombo:null" ), Lists.<Order>newArrayList() );
+        Query query = queryService.getQueryFromUrl( DataElement.class, Lists.newArrayList( "categoryCombo:!null" ), Lists.<Order>newArrayList() );
         List<? extends IdentifiableObject> objects = queryService.query( query );
 
         assertEquals( 6, objects.size() );

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/DefaultExportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/DefaultExportServiceTest.java	2016-02-02 06:34:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/metadata/DefaultExportServiceTest.java	2016-03-02 04:34:21 +0000
@@ -91,9 +91,9 @@
     @Override
     public void setUpTest()
     {
-        deA = DhisConvenienceTest.createDataElement( 'A' );
-        deB = DhisConvenienceTest.createDataElement( 'B' );
-        deC = DhisConvenienceTest.createDataElement( 'C' );
+        deA = createDataElement( 'A' );
+        deB = createDataElement( 'B' );
+        deC = createDataElement( 'C' );
         dsA = DhisConvenienceTest.createDataSet( 'A', new MonthlyPeriodType() );
         ouA = DhisConvenienceTest.createOrganisationUnit( 'A' );
         ouB = DhisConvenienceTest.createOrganisationUnit( 'B' );

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/AggregatableDataElementFilterTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/AggregatableDataElementFilterTest.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/filter/AggregatableDataElementFilterTest.java	2016-03-02 04:34:21 +0000
@@ -30,11 +30,10 @@
 
 import com.google.common.collect.Sets;
 
-import org.hisp.dhis.DhisConvenienceTest;
+import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.common.ValueType;
 import org.hisp.dhis.commons.filter.FilterUtils;
 import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.system.filter.AggregatableDataElementFilter;
 import org.junit.Test;
 
 import java.util.Set;
@@ -45,7 +44,7 @@
  * @author Lars Helge Overland
  */
 public class AggregatableDataElementFilterTest
-    extends DhisConvenienceTest
+    extends DhisSpringTest
 {
     @Test
     public void filter()

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2016-02-01 09:41:43 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2016-03-02 04:34:21 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementDomain;
 import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataelement.DataElementGroupSet;
@@ -99,6 +100,7 @@
 import org.joda.time.DateTime;
 import org.springframework.aop.framework.Advised;
 import org.springframework.aop.support.AopUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
@@ -109,6 +111,7 @@
 import org.springframework.util.Assert;
 import org.xml.sax.InputSource;
 
+import javax.annotation.PostConstruct;
 import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.xpath.XPath;
@@ -162,6 +165,17 @@
 
     protected RenderService renderService;
 
+    @Autowired( required = false )
+    protected DataElementCategoryService _categoryService;
+
+    protected static DataElementCategoryService categoryService;
+
+    @PostConstruct
+    protected void initStaticServices()
+    {
+        categoryService = _categoryService;
+    }
+
     static
     {
         DateTime dateTime = new DateTime( 1970, 1, 1, 0, 0 );
@@ -364,6 +378,13 @@
         dataElement.setDomainType( DataElementDomain.AGGREGATE );
         dataElement.setAggregationType( AggregationType.SUM );
 
+        if ( categoryService != null )
+        {
+            DataElementCategoryCombo categoryCombo = categoryService.getDefaultDataElementCategoryCombo();
+            dataElement.setCategoryCombo( categoryCombo );
+        }
+
+
         return dataElement;
     }
 
@@ -372,17 +393,8 @@
      */
     public static DataElement createDataElement( char uniqueCharacter, ValueType valueType )
     {
-        DataElement dataElement = new DataElement();
-        dataElement.setAutoFields();
-
-        dataElement.setUid( BASE_DE_UID + uniqueCharacter );
-        dataElement.setName( "DataElement" + uniqueCharacter );
-        dataElement.setShortName( "DataElementShort" + uniqueCharacter );
-        dataElement.setCode( "DataElementCode" + uniqueCharacter );
-        dataElement.setDescription( "DataElementDescription" + uniqueCharacter );
+        DataElement dataElement = createDataElement( uniqueCharacter );
         dataElement.setValueType( valueType );
-        dataElement.setDomainType( DataElementDomain.AGGREGATE );
-        dataElement.setAggregationType( AggregationType.SUM );
 
         return dataElement;
     }
@@ -1654,4 +1666,5 @@
 
         return sw.toString();
     }
+
 }