← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2672: Bug Fixed in Survey/DeTarget Module

 

------------------------------------------------------------
revno: 2672
committer: Mithilesh Kumar Thakur<mithilesh.hisp@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2011-01-20 18:49:33 +0530
message:
  Bug Fixed in Survey/DeTarget Module
modified:
  local/in/dhis-web-survey/src/main/java/org/hisp/dhis/detarget/action/UpdateDeTargetAction.java
  local/in/dhis-web-survey/src/main/resources/META-INF/dhis/beans.xml
  local/in/dhis-web-survey/src/main/webapp/dhis-web-survey/javascript/general.js


--
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 'local/in/dhis-web-survey/src/main/java/org/hisp/dhis/detarget/action/UpdateDeTargetAction.java'
--- local/in/dhis-web-survey/src/main/java/org/hisp/dhis/detarget/action/UpdateDeTargetAction.java	2011-01-17 07:45:29 +0000
+++ local/in/dhis-web-survey/src/main/java/org/hisp/dhis/detarget/action/UpdateDeTargetAction.java	2011-01-20 13:19:33 +0000
@@ -38,8 +38,8 @@
 import org.hisp.dhis.detarget.DeTarget;
 import org.hisp.dhis.detarget.DeTargetMember;
 import org.hisp.dhis.detarget.DeTargetService;
-
-
+import org.hisp.dhis.detargetdatavalue.DeTargetDataValue;
+import org.hisp.dhis.detargetdatavalue.DeTargetDataValueService;
 
 import com.opensymphony.xwork2.Action;
 
@@ -75,6 +75,13 @@
     {
         this.dataElementCategoryService = dataElementCategoryService;
     }
+    
+    private DeTargetDataValueService deTargetdataValueService;
+    
+    public void setDeTargetdataValueService( DeTargetDataValueService deTargetdataValueService )
+    {
+        this.deTargetdataValueService = deTargetdataValueService;
+    }
     // -------------------------------------------------------------------------
     // Getters & Setters
     // -------------------------------------------------------------------------
@@ -135,6 +142,12 @@
         return deTargetMemberList;
     }
     
+   private List<String> selectedDeTargetMember;
+    
+    public List<String> getSelectedDeTargetMember()
+    {
+        return selectedDeTargetMember;
+    }
     // -------------------------------------------------------------------------
     // Action
     // -------------------------------------------------------------------------
@@ -145,7 +158,9 @@
         // ---------------------------------------------------------------------
         // Prepare values
         // ---------------------------------------------------------------------
-    
+        
+        selectedDeTargetMember = new ArrayList<String>();
+        
         if ( shortName != null && shortName.trim().length() == 0 )
         {
                 shortName = null;
@@ -160,12 +175,98 @@
         deTarget.setUrl( url );
         deTarget.setDescription( description );
         
-        deTargetMemberList = new ArrayList<DeTargetMember>(deTargetService.getDeTargetMembers( deTarget ));
-        
-        
+        
+        if ( deTargetId != 0 )
+        {
+             deTarget = deTargetService.getDeTarget( deTargetId );
+        
+             List<DeTargetMember>  deTargetMemberList = new ArrayList<DeTargetMember>(deTargetService.getDeTargetMembers( deTarget ));
+             for( DeTargetMember dataElementTarget : deTargetMemberList )
+             {
+                 selectedDeTargetMember.add( dataElementTarget.getDataelements().getId()+":" + dataElementTarget.getDecategoryOptionCombo().getId() );
+             }
+                //indicators.removeAll( survey.getIndicators() );
+        }
+        
+        //deTargetMemberList = new ArrayList<DeTargetMember>(deTargetService.getDeTargetMembers( deTarget ));
+        
+        
+        
+      
+        
+        List<DeTargetDataValue> dataValueList = new ArrayList<DeTargetDataValue>( deTargetdataValueService.getDeTargetDataValues( deTarget));
+        
+        System.out.println( " \n+++++++++ size of datavalueList is " +  dataValueList.size() );
+       
+        if( dataValueList.size() == 0 || dataValueList == null  )
+        {
+            deTargetService.deleteDeTargetMembers( deTarget );
+            
+            for ( String selectedId : selectedList )
+            {
+                String[] parts = selectedId.split( ":" );
+                DataElement dataElement = dataElementService.getDataElement(  Integer.parseInt( parts[0] ) );
+                DataElementCategoryOptionCombo decoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( parts[1] ));
+                
+               // List<DeTargetDataValue> dataValueList = new ArrayList<DeTargetDataValue>(deTargetdataValueService.getDeTargetDataValues( deTarget, dataElement, decoc ));
+                
+                DeTargetMember deTargetMember = new DeTargetMember( deTarget, dataElement, decoc);
+                
+                deTargetService.addDeTargetMember( deTargetMember );
+                
+                //deTargetService.updateDeTargetMember( deTargetMember );
+                //System.out.println( dataElement + ":" +  decoc );
+                
+               
+            }
+            
+        }
+        else
+        {
+            for ( String selectedId : selectedList )
+            {
+                String[] parts = selectedId.split( ":" );
+                DataElement dataElement = dataElementService.getDataElement(  Integer.parseInt( parts[0] ) );
+                DataElementCategoryOptionCombo decoc = dataElementCategoryService.getDataElementCategoryOptionCombo( Integer.parseInt( parts[1] ));
+                
+               // List<DeTargetDataValue> dataValueList = new ArrayList<DeTargetDataValue>(deTargetdataValueService.getDeTargetDataValues( deTarget, dataElement, decoc ));
+                
+                String deOptComboId = dataElement.getId() + ":" + decoc.getId();
+                
+                if( !selectedDeTargetMember.contains( deOptComboId ) )
+                {
+                    DeTargetMember deTargetMember = new DeTargetMember( deTarget, dataElement, decoc);
+                    
+                    deTargetService.addDeTargetMember( deTargetMember );
+                }
+                   
+                
+                
+               // DeTargetMember deTargetMember = new DeTargetMember( deTarget, dataElement, decoc);
+                
+               // deTargetService.addDeTargetMember( deTargetMember );
+                
+                //deTargetService.updateDeTargetMember( deTargetMember );
+                //System.out.println( dataElement + ":" +  decoc );
+                
+               
+            }
+        }
+        
+        //deTargetdataValueService.getDeTargetDataValues( deTarget, dataelement, decategoryOptionCombo )
+        
+       // int flag = deTargetService.deleteDeTarget( deTarget );
+        
+       // deTargetService.deleteDeTargetMembers( deTarget );
+      
+ 
+        
+        
+     
+     
         //Collection<Indicator> updatedIndicatorList = new HashSet<Indicator>();
         
-        deTargetService.deleteDeTargetMembers( deTarget );
+       // deTargetService.deleteDeTargetMembers( deTarget );
        
         /*
         for( DeTargetMember dataElementTarget : deTargetMemberList )
@@ -178,6 +279,7 @@
         */
         
         
+        /*
         for ( String selectedId : selectedList )
         {
             String[] parts = selectedId.split( ":" );
@@ -187,10 +289,15 @@
             DeTargetMember deTargetMember = new DeTargetMember( deTarget, dataElement, decoc);
             
             deTargetService.addDeTargetMember( deTargetMember );
+            
+            //deTargetService.updateDeTargetMember( deTargetMember );
             //System.out.println( dataElement + ":" +  decoc );
             
            
         }
+        */
+        
+        //deTargetService.updateDeTarget( deTarget );
         return SUCCESS;
     }
 }

=== modified file 'local/in/dhis-web-survey/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-survey/src/main/resources/META-INF/dhis/beans.xml	2011-01-18 11:50:14 +0000
+++ local/in/dhis-web-survey/src/main/resources/META-INF/dhis/beans.xml	2011-01-20 13:19:33 +0000
@@ -434,6 +434,8 @@
 	</property>	
     <property name="deTargetService" ref="org.hisp.dhis.detarget.DeTargetService">
     </property>
+	<property name="deTargetdataValueService" ref="org.hisp.dhis.detargetdatavalue.DeTargetDataValueService">
+	</property>	
     </bean>
 	
 	<!-- Delete DeTarget Form  -->

=== modified file 'local/in/dhis-web-survey/src/main/webapp/dhis-web-survey/javascript/general.js'
--- local/in/dhis-web-survey/src/main/webapp/dhis-web-survey/javascript/general.js	2011-01-19 13:29:17 +0000
+++ local/in/dhis-web-survey/src/main/webapp/dhis-web-survey/javascript/general.js	2011-01-20 13:19:33 +0000
@@ -169,7 +169,7 @@
 
 function targetValueSaver( dataElementId_, optionComboid_, value_, resultColor_, selectedOption_ )
 {
-    var SUCCESS = '#ccffcc';
+	var SUCCESS = '#ccffcc';
     var ERROR = '#ccccff';
 
     var dataElementId = dataElementId_;
@@ -200,25 +200,26 @@
         var code = parseInt( codeElement.firstChild.nodeValue );
         if ( code == 0 )
         {
-            markValue( resultColor );
+            markTargetValue( resultColor );
         }
         else
         {
-        	markValue( ERROR );
+        	markTargetValue( ERROR );
             window.alert( i18n_saving_value_failed_status_code + '\n\n' + code );
         }
     }
     
     function handleHttpError( errorCode )
     {
-        markValue( ERROR );
+    	markTargetValue( ERROR );
         window.alert( i18n_saving_value_failed_error_code + '\n\n' + errorCode );
     }   
     
-    function markValue( color )
+    function markTargetValue( color )
     {        
-        //var element = document.getElementById( 'value[' + deOptionComboId + '].value' );
-        var element = document.getElementById( 'value[' + optionComboId + '].value' );
+       //var element = document.getElementById( 'value[' + deOptionComboId + '].value' );
+       // var element = document.getElementById( 'value[' + optionComboId + '].value' );
+        var element = document.getElementById( 'value[' + dataElementId + '].value' );
         element.style.backgroundColor = color;
     }
 }