← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3829: Fix bug: Filter indicator by dictionary.

 

------------------------------------------------------------
revno: 3829
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-06-02 10:22:21 +0700
message:
  Fix bug: Filter indicator by dictionary.
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datadictionary/DataDictionaryStore.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/hibernate/
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/hibernate/HibernateDataDictionaryStore.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/datadictionary/DataDictionaryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.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/datadictionary/DataDictionaryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datadictionary/DataDictionaryService.java	2010-12-04 00:17:59 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datadictionary/DataDictionaryService.java	2011-06-02 03:22:21 +0000
@@ -30,6 +30,7 @@
 import java.util.Collection;
 
 import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.indicator.Indicator;
 
 /**
  * @author Lars Helge Overland
@@ -97,6 +98,12 @@
      */
     Collection<DataElement> getDataElementsByDictionaryId( int dictionaryId );
     
+    Collection<DataElement> getDataElementsByDictionaryId( String key, int dictionaryId );
+    
+    Collection<Indicator> getIndicatorsByDictionaryId( int dictionaryId );
+    
+    Collection<Indicator> getIndicatorsByDictionaryId( String key, int dictionaryId );
+    
     Collection<DataDictionary> getDataDictionarysBetween( int first, int max );
     
     Collection<DataDictionary> getDataDictionarysBetweenByName( String name, int first, int max );

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datadictionary/DataDictionaryStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datadictionary/DataDictionaryStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datadictionary/DataDictionaryStore.java	2011-06-02 03:22:21 +0000
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2004-2009, 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.
+ */
+
+package org.hisp.dhis.datadictionary;
+
+import java.util.Collection;
+
+import org.hisp.dhis.common.GenericIdentifiableObjectStore;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.indicator.Indicator;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ DataDictionaryStore.java Jun 1, 2011 2:23:14 PM $
+ * 
+ */
+public interface DataDictionaryStore
+    extends GenericIdentifiableObjectStore<DataDictionary>
+{
+    Collection<DataElement> getDataElements( String key, int dictionaryId );
+
+    Collection<Indicator> getIndicators( String key, int dictionaryId );
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java	2010-12-03 12:31:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/DefaultDataDictionaryService.java	2011-06-02 03:22:21 +0000
@@ -31,9 +31,9 @@
 
 import java.util.Collection;
 
-import org.hisp.dhis.common.GenericIdentifiableObjectStore;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.i18n.I18nService;
+import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.system.util.Filter;
 import org.hisp.dhis.system.util.FilterUtils;
 import org.springframework.transaction.annotation.Transactional;
@@ -50,9 +50,9 @@
     // Dependencies
     // -------------------------------------------------------------------------
 
-    private GenericIdentifiableObjectStore<DataDictionary> dataDictionaryStore;
+    private DataDictionaryStore dataDictionaryStore;
 
-    public void setDataDictionaryStore( GenericIdentifiableObjectStore<DataDictionary> dataDictionaryStore )
+    public void setDataDictionaryStore( DataDictionaryStore dataDictionaryStore )
     {
         this.dataDictionaryStore = dataDictionaryStore;
     }
@@ -111,6 +111,21 @@
         return i18n( i18nService, dataDictionaryStore.get( dictionaryId ).getDataElements() );
     }
 
+    public Collection<DataElement> getDataElementsByDictionaryId( String key, int dictionaryId )
+    {
+        return i18n( i18nService, dataDictionaryStore.getDataElements( key, dictionaryId ) );
+    }
+    
+    public Collection<Indicator> getIndicatorsByDictionaryId( int dictionaryId )
+    {
+        return i18n( i18nService, dataDictionaryStore.get( dictionaryId ).getIndicators() );
+    }
+    
+    public Collection<Indicator> getIndicatorsByDictionaryId( String key, int dictionaryId )
+    {
+        return i18n( i18nService, dataDictionaryStore.getIndicators( key, dictionaryId ) );
+    }
+
     public int getDataDictionaryCount()
     {
         return dataDictionaryStore.getCount();

=== added directory 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/hibernate'
=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/hibernate/HibernateDataDictionaryStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/hibernate/HibernateDataDictionaryStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/datadictionary/hibernate/HibernateDataDictionaryStore.java	2011-06-02 03:22:21 +0000
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2004-2009, 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.
+ */
+
+package org.hisp.dhis.datadictionary.hibernate;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.hibernate.criterion.Order;
+import org.hibernate.criterion.Restrictions;
+import org.hibernate.transform.Transformers;
+import org.hisp.dhis.datadictionary.DataDictionary;
+import org.hisp.dhis.datadictionary.DataDictionaryStore;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.hibernate.HibernateGenericStore;
+import org.hisp.dhis.indicator.Indicator;
+
+/**
+ * @author Chau Thu Tran
+ * @version $ HibernateDataDictionaryStore.java Jun 1, 2011 2:24:46 PM $
+ * 
+ */
+public class HibernateDataDictionaryStore
+    extends HibernateGenericStore<DataDictionary>
+    implements DataDictionaryStore
+{
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<DataElement> getDataElements( String key, int dictionaryId )
+    {
+        List<Map> results = getCriteria().createAlias( "dataElements", "dataElement" ).add(
+            Restrictions.ilike( "dataElement.name", "%" + key + "%" ) ).add( Restrictions.eq( "id", dictionaryId ) )
+            .addOrder( Order.asc( "dataElement.name" ) ).setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP )
+            .list();
+        
+        Set<DataElement> dataElements = new HashSet<DataElement>();
+        for ( Map<String, Object> map : results )
+        {
+            dataElements.add( (DataElement) map.get( "dataElement" ) );
+        }
+
+        return dataElements;
+    }
+
+    @SuppressWarnings( "unchecked" )
+    public Collection<Indicator> getIndicators( String key, int dictionaryId )
+    {
+        List<Map> results = getCriteria().createAlias( "indicators", "indicator" ).add(
+            Restrictions.ilike( "indicator.name", "%" + key + "%" ) ).add( Restrictions.eq( "id", dictionaryId ) )
+            .addOrder( Order.asc( "indicator.name" ) ).setResultTransformer( Transformers.ALIAS_TO_ENTITY_MAP ).list();
+        
+        Set<Indicator> indicators = new HashSet<Indicator>();
+        for ( Map<String, Object> map : results )
+        {
+            indicators.add( (Indicator) map.get( "indicator" ) );
+        }
+
+        return indicators;
+    }
+
+}

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-06-01 15:28:59 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/META-INF/dhis/beans.xml	2011-06-02 03:22:21 +0000
@@ -42,7 +42,7 @@
 		<property name="cacheable" value="true"/>
 	</bean>
 
-	<bean id="org.hisp.dhis.datadictionary.DataDictionaryStore" class="org.hisp.dhis.hibernate.HibernateGenericStore">
+	<bean id="org.hisp.dhis.datadictionary.DataDictionaryStore" class="org.hisp.dhis.datadictionary.hibernate.HibernateDataDictionaryStore">
 		<property name="clazz" value="org.hisp.dhis.datadictionary.DataDictionary" />
 		<property name="sessionFactory" ref="sessionFactory" />
 		<property name="cacheable" value="true"/>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java	2011-05-06 11:10:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/dataelement/GetDataElementListAction.java	2011-06-02 03:22:21 +0000
@@ -138,7 +138,7 @@
     }
 
     private String key;
-    
+
     public String getKey()
     {
         return key;
@@ -165,7 +165,8 @@
 
             dataDictionaryId = null;
         }
-        else  // Specified, set current data dictionary
+        else
+        // Specified, set current data dictionary
         {
             dataDictionaryModeManager.setCurrentDataDictionary( dataDictionaryId );
         }
@@ -180,23 +181,41 @@
 
         if ( isNotBlank( key ) ) // Filter on key only if set
         {
-            this.paging = createPaging( dataElementService.getDataElementCountByName( key ) );
-            
-            dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+            if ( dataDictionaryId == null )
+            {
+                this.paging = createPaging( dataElementService.getDataElementCountByName( key ) );
+
+                dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsBetweenByName( key, paging
+                    .getStartPos(), paging.getPageSize() ) );
+            }
+            else
+            {
+                dataElements = new ArrayList<DataElement>( dataDictionaryService.getDataElementsByDictionaryId( key,
+                    dataDictionaryId ) );
+       
+                this.paging = createPaging( dataElements.size() );
+
+                if ( dataElements.size() > 0 )
+                {
+                    dataElements = getBlockElement( dataElements, paging.getStartPos(), paging.getEndPos() );
+                }
+            }
         }
         else if ( dataDictionaryId != null )
         {
-            dataElements = new ArrayList<DataElement>( dataDictionaryService.getDataElementsByDictionaryId( dataDictionaryId ) );
-            
+            dataElements = new ArrayList<DataElement>( dataDictionaryService
+                .getDataElementsByDictionaryId( dataDictionaryId ) );           
+
             this.paging = createPaging( dataElements.size() );
-            
-            dataElements = getBlockElement( dataElements, paging.getStartPos(), paging.getPageSize() );
+
+            dataElements = getBlockElement( dataElements, paging.getStartPos(), paging.getEndPos() );
         }
         else
         {
             this.paging = createPaging( dataElementService.getDataElementCount() );
-            
-            dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsBetween( paging.getStartPos(), paging.getPageSize() ) );
+
+            dataElements = new ArrayList<DataElement>( dataElementService.getDataElementsBetween( paging.getStartPos(),
+                paging.getPageSize() ) );
         }
 
         Collections.sort( dataElements, dataElementComparator );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.java	2011-05-06 11:10:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/java/org/hisp/dhis/dd/action/indicator/GetIndicatorListAction.java	2011-06-02 03:22:21 +0000
@@ -138,7 +138,7 @@
     }
 
     private String key;
-    
+
     public String getKey()
     {
         return key;
@@ -162,14 +162,15 @@
         else if ( dataDictionaryId == -1 ) // All, reset current data dictionary
         {
             dataDictionaryModeManager.setCurrentDataDictionary( null );
-            
+
             dataDictionaryId = null;
         }
-        else // Specified, set current data dictionary
+        else
+        // Specified, set current data dictionary
         {
             dataDictionaryModeManager.setCurrentDataDictionary( dataDictionaryId );
         }
-        
+
         dataDictionaries = new ArrayList<DataDictionary>( dataDictionaryService.getAllDataDictionaries() );
 
         Collections.sort( dataDictionaries, new DataDictionaryNameComparator() );
@@ -180,25 +181,45 @@
 
         if ( isNotBlank( key ) ) // Filter on key only if set
         {
-            this.paging = createPaging( indicatorService.getIndicatorCountByName( key ) );
-            
-            indicators = new ArrayList<Indicator>( indicatorService.getIndicatorsBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+            if ( dataDictionaryId == null )
+            {
+                this.paging = createPaging( indicatorService.getIndicatorCountByName( key ) );
+
+                indicators = new ArrayList<Indicator>( indicatorService.getIndicatorsBetweenByName( key, paging
+                    .getStartPos(), paging.getPageSize() ) );
+            }
+            else
+            {
+                indicators = new ArrayList<Indicator>( dataDictionaryService.getIndicatorsByDictionaryId( key,
+                    dataDictionaryId ) );
+
+                this.paging = createPaging( indicators.size() );
+
+                if( indicators.size() > 0 )
+                {
+                    indicators = getBlockElement( indicators, paging.getStartPos() , paging.getEndPos() );
+                }
+            }
         }
         else if ( dataDictionaryId != null )
         {
-            indicators = new ArrayList<Indicator>( dataDictionaryService.getDataDictionary( dataDictionaryId ).getIndicators() );
-            
+            indicators = new ArrayList<Indicator>( dataDictionaryService.getIndicatorsByDictionaryId( dataDictionaryId ) );
+          
             this.paging = createPaging( indicators.size() );
-            
-            indicators = getBlockElement( indicators, paging.getStartPage(), paging.getEndPos() );
+
+            if ( indicators.size() > 0 )
+            {
+                indicators = getBlockElement( indicators, paging.getStartPos() , paging.getEndPos() );
+            }
         }
         else
         {
             this.paging = createPaging( indicatorService.getIndicatorCount() );
-            
-            indicators = new ArrayList<Indicator>( indicatorService.getIndicatorsBetween( paging.getStartPos(), paging.getPageSize() ) );
+
+            indicators = new ArrayList<Indicator>( indicatorService.getIndicatorsBetween( paging.getStartPos(), paging
+                .getPageSize() ) );
         }
-        
+
         Collections.sort( indicators, indicatorComparator );
 
         displayPropertyHandler.handle( indicators );