← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13154: CCEI: csv import changes

 

------------------------------------------------------------
revno: 13154
committer: Bharath <chbharathk@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-12-05 11:55:45 +0000
message:
  CCEI: csv import changes
modified:
  local/in/dhis-in-services/pom.xml
  local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/equipment/action/ShowEquipmentStatusFormAction.java
  local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/equipmentList.vm
  local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/importexport/action/CSVImportAction.java
  local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml


--
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-in-services/pom.xml'
--- local/in/dhis-in-services/pom.xml	2013-10-18 05:57:53 +0000
+++ local/in/dhis-in-services/pom.xml	2013-12-05 11:55:45 +0000
@@ -20,6 +20,7 @@
 	<module>dhis-in-service-reports</module>
     <module>dhis-in-service-survey</module>
 	<module>dhis-in-service-dataentrystatus</module>-->
+	<!--<module>dhis-service-aggregationengine-default</module>-->
 	<module>dhis-in-service-configuration</module>
 	<module>dhis-in-service-coldchain</module>
   </modules>

=== modified file 'local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/equipment/action/ShowEquipmentStatusFormAction.java'
--- local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/equipment/action/ShowEquipmentStatusFormAction.java	2013-10-18 05:57:53 +0000
+++ local/in/dhis-web-coldchain/src/main/java/org/hisp/dhis/coldchain/equipment/action/ShowEquipmentStatusFormAction.java	2013-12-05 11:55:45 +0000
@@ -79,9 +79,15 @@
         
         Constant optionSetConstant = constantService.getConstantByName( WORKING_STATUS_OPTION_SET );
         
-        optionSet = new OptionSet();
-        optionSet = optionService.getOptionSet( (int) optionSetConstant.getValue() );
-        
+        if( optionSetConstant != null )
+        {
+            optionSet = new OptionSet();
+            optionSet = optionService.getOptionSet( (int) optionSetConstant.getValue() );
+        }
+        else
+        {
+            System.out.println( "constant for working status option set is not defined");
+        }
         
         //equipment.getOrganisationUnit().getName();
         //equipment.getModel().getName();

=== modified file 'local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/equipmentList.vm'
--- local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/equipmentList.vm	2013-10-18 05:57:53 +0000
+++ local/in/dhis-web-coldchain/src/main/webapp/dhis-web-coldchain/equipmentList.vm	2013-12-05 11:55:45 +0000
@@ -39,7 +39,7 @@
 	 			#end
 			 	#foreach( $equipmentTypeAttribute in $equipmentTypeAttributeList )
 			 		#set( $mapId = $equipment.id + ':' + $equipmentTypeAttribute.equipmentTypeAttribute.id )
-			 			#if( $equipmentType.tracking && $equipmentTypeAttribute.equipmentTypeAttribute.getDescription().equalsIgnoreCase("WORKING_STATUS"))
+			 			#if( $equipmentType.tracking && $equipmentTypeAttribute.equipmentTypeAttribute.getDescription().equalsIgnoreCase("WorkingStatus"))
 			 				<td><a href="javascript:showEquipmentStatusHistoryForm( '$equipment.id','$equipment.getOrganisationUnit().getName()','$!equipment.model.name' ); " title='$i18n.getString( "equipment_tracking_history" )'>$!equipmentDetailsMap.get( $mapId )</a></td>
 			 			#else
 			 			<td>$!equipmentDetailsMap.get( $mapId )</td>

=== modified file 'local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/importexport/action/CSVImportAction.java'
--- local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/importexport/action/CSVImportAction.java	2013-11-29 05:29:50 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/java/org/hisp/dhis/ccem/importexport/action/CSVImportAction.java	2013-12-05 11:55:45 +0000
@@ -15,7 +15,6 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipInputStream;
 
-import org.apache.commons.lang.math.NumberUtils;
 import org.hisp.dhis.coldchain.equipment.Equipment;
 import org.hisp.dhis.coldchain.equipment.EquipmentAttributeValue;
 import org.hisp.dhis.coldchain.equipment.EquipmentService;
@@ -30,6 +29,8 @@
 import org.hisp.dhis.coldchain.model.ModelTypeAttribute;
 import org.hisp.dhis.coldchain.model.ModelTypeAttributeService;
 import org.hisp.dhis.coldchain.model.ModelTypeService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
@@ -101,8 +102,8 @@
     
     public void setEquipmentTypeAttributeService( EquipmentTypeAttributeService equipmentTypeAttributeService) 
     {
-		this.equipmentTypeAttributeService = equipmentTypeAttributeService;
-	}
+        this.equipmentTypeAttributeService = equipmentTypeAttributeService;
+    }
 
     private OrganisationUnitGroupService organisationUnitGroupService;
 
@@ -110,8 +111,15 @@
     {
         this.organisationUnitGroupService = organisationUnitGroupService;
     }
+    
+    private DataSetService dataSetService;
+    
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
 
-	private JdbcTemplate jdbcTemplate;
+    private JdbcTemplate jdbcTemplate;
 
     public void setJdbcTemplate( JdbcTemplate jdbcTemplate )
     {
@@ -215,7 +223,14 @@
         OrganisationUnitGroup ouGroup = null;
         if( ouGroups != null )
         {
-        	ouGroup = ouGroups.get( 0 );
+            ouGroup = ouGroups.get( 0 );
+        }
+        
+        List<DataSet> dataSets = new ArrayList<DataSet>( dataSetService.getDataSetByShortName( "FMD" ) ); 
+        DataSet dataSet = null;
+        if( dataSets != null )
+        {
+            dataSet = dataSets.get( 0 );
         }
 
         try
@@ -245,9 +260,15 @@
                     orgUnitMap.put( nodeId, organisationUnit );
                     ouGroup.addOrganisationUnit( organisationUnit );
                     organisationUnitGroupService.updateOrganisationUnitGroup( ouGroup );
+                    if( dataSet != null )
+                    {
+                        dataSet.getSources().add( organisationUnit );                        
+                    }
                 }
             }
                 
+            dataSetService.updateDataSet( dataSet );
+            
             csvReader.close();                       
         }
         catch( Exception e )
@@ -270,41 +291,36 @@
     	
     	try
     	{
-    		CsvReader csvReader = new CsvReader( adminHierarchyCSVFilePath, ',', Charset.forName( "UTF-8" ) );
-    		csvReader.readHeaders();
-    		String headers[] = csvReader.getHeaders();
+		CsvReader csvReader = new CsvReader( adminHierarchyCSVFilePath, ',', Charset.forName( "UTF-8" ) );
+		csvReader.readHeaders();
+		String headers[] = csvReader.getHeaders();
 
-    		Integer colCount = headers.length;
-    		while( csvReader.readRecord() )
-    		{
-    			String nodeId = csvReader.get( "NodeID" );
-    			String ouName = csvReader.get( "Name" );
-    			Integer ouLevel = Integer.parseInt( csvReader.get( "Level" ) );    			
-    			String parentId = csvReader.get( "Parent" );
-    			String ouCode = csvReader.get( "Code" );
-    			
-    			if( ouCode != null && ouCode.trim().equals("") )
-    				ouCode = null;
-    			
-            	List<OrganisationUnit> tempList = levelwiseOrgunits.get( ouLevel );
-                if( tempList == null )
-                {
-                    tempList = new ArrayList<OrganisationUnit>();                        
-                }
-                
-                OrganisationUnit organisationUnit = new OrganisationUnit( ouName, ouName, ouCode, new Date(), null, true, parentId );
-                organisationUnit.setDescription( nodeId );
-                orgUnitMap.put( nodeId, organisationUnit );
-                
-                //tempList.add( nodeId + "#@#" + ouName + "#@#" + parentId + "#@#" + ouCode );
-                //tempList.add( ouName );
-                //tempList.add( parentId );
-                //tempList.add( ouCode );
-                
-                tempList.add( organisationUnit );
-                
-                levelwiseOrgunits.put( ouLevel, tempList );
-    		}
+		Integer colCount = headers.length;
+		while( csvReader.readRecord() )
+		{
+		    String nodeId = csvReader.get( "NodeID" );
+		    String ouName = csvReader.get( "Name" );
+		    Integer ouLevel = Integer.parseInt( csvReader.get( "Level" ) );    			
+		    String parentId = csvReader.get( "Parent" );
+		    String ouCode = csvReader.get( "Code" );
+			
+		    if( ouCode != null && ouCode.trim().equals("") )
+		        ouCode = null;
+			
+        	    List<OrganisationUnit> tempList = levelwiseOrgunits.get( ouLevel );
+        	    if( tempList == null )
+        	    {
+        	        tempList = new ArrayList<OrganisationUnit>();                        
+        	    }
+            
+        	    OrganisationUnit organisationUnit = new OrganisationUnit( ouName, ouName, ouCode, new Date(), null, true, parentId );
+        	    organisationUnit.setDescription( nodeId );
+        	    orgUnitMap.put( nodeId, organisationUnit );
+                          
+        	    tempList.add( organisationUnit );
+            
+        	    levelwiseOrgunits.put( ouLevel, tempList );
+		}
     		
             csvReader.close();
             
@@ -372,28 +388,36 @@
             	
             	if( tempList == null )
             	{
-            		System.out.println( "tempList is null for : " + uniqueId );
-            		continue;
+            	    System.out.println( "tempList is null for : " + uniqueId );
+            	    continue;
             	}
+            	
             	OrganisationUnit orgUnit = faclityMap.get( tempList.get(0) );
             	
-            	Equipment equipment = new Equipment();
-	            
-	            equipment.setEquipmentType( refrigeratorEquipment );
-	            equipment.setOrganisationUnit( orgUnit );
-	            
-	            Model model = refrigeratorModelMap.get( catalogID );
-	            if( model == null )
-	            {
-	            	System.out.println( "model is null for : " + catalogID );
-	            	continue;
-	            }
-
-	            List<EquipmentAttributeValue> equipmentAttributeValueDetailsList = new ArrayList<EquipmentAttributeValue>();
-
-	            for( int i = 2; i < headers.length; i++ )
+            	if( orgUnit == null )
+            	{
+            	    System.out.println(" ********************* " + tempList.get(0) + " IS NULL ********************* ");
+            	    continue;
+            	}
+            	
+            	Equipment equipment = new Equipment();	            
+            	equipment.setEquipmentType( refrigeratorEquipment );
+	        equipment.setOrganisationUnit( orgUnit );
+	            
+	        Model model = refrigeratorModelMap.get( catalogID );
+	        if( model == null )
+	        {
+	            System.out.println( "model is null for : " + catalogID );
+	            continue;
+	        }
+	        
+	        equipment.setModel( model );
+
+	        List<EquipmentAttributeValue> equipmentAttributeValueDetailsList = new ArrayList<EquipmentAttributeValue>();
+
+	        for( int i = 2; i < headers.length; i++ )
                 {
-	            	EquipmentTypeAttribute equipmentTypeAttribute = equipmentTypeAttributeMap.get( headers[i] );
+	            EquipmentTypeAttribute equipmentTypeAttribute = equipmentTypeAttributeMap.get( headers[i] );
                     
                     if ( equipmentTypeAttribute != null )
                     {
@@ -403,38 +427,44 @@
                         
                         if( equipmentTypeAttribute.getOptionSet() != null )
                         {
-                        	List<String> lookupOptions = lookupDataMap.get( headers[i] );
-                        	if( lookupOptions != null )
-                        	{
-                        		try
-                        		{
-                        			equipmentAttributeValueDetails.setValue( lookupOptions.get( Integer.parseInt( csvReader.get( headers[i] ) ) + 1  ) );
-                        			equipmentAttributeValueDetailsList.add( equipmentAttributeValueDetails );
-                        		}
-                        		catch( Exception e )
-                        		{
+                            List<String> lookupOptions = lookupDataMap.get( headers[i] );
+                            if( lookupOptions != null )
+                            {
+                        	try
+                        	{
+                        	    //System.out.println( orgUnit.getName() + " : " + equipmentTypeAttribute.getName() + " : " + csvReader.get( headers[i] ) + " : " + lookupOptions.get( Integer.parseInt( csvReader.get( headers[i] ) ) + 1  ) );
+                        	    equipmentAttributeValueDetails.setValue( lookupOptions.get( Integer.parseInt( csvReader.get( headers[i] ) ) - 1  ) );
+                        	    equipmentAttributeValueDetailsList.add( equipmentAttributeValueDetails );
+                        	}
+                        	catch( Exception e )
+                        	{
                         			
-                        		}
                         	}
-                        	else
-                        	{
+                            }
+                            else
+                            {
                         		
-                        	}
+                            }
                         }
                         else
                         {
-                            equipmentAttributeValueDetails.setValue( csvReader.get( headers[i] ) );
-                            equipmentAttributeValueDetailsList.add( equipmentAttributeValueDetails );
+                            if( csvReader.get( headers[i] ) != null && !csvReader.get( headers[i] ).trim().equals( "" ) )
+                            {
+                                //System.out.print( orgUnit.getName()  + " : " );
+                                System.out.print( equipmentTypeAttribute.getName() + " : " );
+                                System.out.println( csvReader.get( headers[i] ) );
+                                equipmentAttributeValueDetails.setValue( csvReader.get( headers[i] ) );
+                                equipmentAttributeValueDetailsList.add( equipmentAttributeValueDetails );
+                            }
                         }
                     }
 	            	
                 }
 	            
-	            // -----------------------------------------------------------------------------
-	            // Creating EquipmentAttributeValue Instance and saving equipmentAttributeValue data
-	            // -----------------------------------------------------------------------------
-	            Integer id = equipmentService.createEquipment( equipment, equipmentAttributeValueDetailsList );
-
+	        // -----------------------------------------------------------------------------
+	        // Creating EquipmentAttributeValue Instance and saving equipmentAttributeValue data
+	        // -----------------------------------------------------------------------------
+	        Integer id = equipmentService.createEquipment( equipment, equipmentAttributeValueDetailsList );
             }
             
             csvReader.close();
@@ -512,15 +542,15 @@
                         	List<String> lookupOptions = lookupDataMap.get( headers[i] );
                         	if( lookupOptions != null )
                         	{
-                        		try
-                        		{
-                        			modelAttributeValue.setValue( lookupOptions.get( Integer.parseInt( csvReader.get( headers[i] ) ) + 1  ) );
-                        			modelAttributeValues.add( modelAttributeValue );
-                        		}
-                        		catch( Exception e )
-                        		{
+                        	    try
+                        	    {                        	        
+                        		modelAttributeValue.setValue( lookupOptions.get( Integer.parseInt( csvReader.get( headers[i] ) ) - 1  ) );
+                        		modelAttributeValues.add( modelAttributeValue );
+                        	    }
+                        	    catch( Exception e )
+                        	    {
                         			
-                        		}
+                        	    }
                         	}
                         	else
                         	{
@@ -606,11 +636,11 @@
             
             Integer colCount = headers.length;
             
-            System.out.println( colCount );
+            //System.out.println( colCount );
             
             while( csvReader.readRecord() )
             {
-                System.out.println( csvReader.get(0) );
+                //System.out.println( csvReader.get(0) );
                 for( int i = 0; i < colCount; i++ )
                 {
                     List<String> tempList = lookupDataMap.get( headers[i] );

=== modified file 'local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml'
--- local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml	2013-11-29 05:29:50 +0000
+++ local/in/dhis-web-maintenance-ccem/src/main/resources/META-INF/dhis/beans.xml	2013-12-05 11:55:45 +0000
@@ -754,6 +754,7 @@
         <property name="equipmentTypeService" ref="org.hisp.dhis.coldchain.equipment.EquipmentTypeService" />
         <property name="equipmentService" ref="org.hisp.dhis.coldchain.equipment.EquipmentService" />
         <property name="equipmentTypeAttributeService" ref="org.hisp.dhis.coldchain.equipment.EquipmentTypeAttributeService" />
+        <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
     </bean>