← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4576: Export to PDF - Organisation unit list page. And put "search" method into commons.

 

------------------------------------------------------------
revno: 4576
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2011-09-14 10:44:56 +0700
message:
  Export to PDF - Organisation unit list page. And put "search" method into commons.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/OrganisationUnitConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/ITextPDFExportService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java
  dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/pom.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitListAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnit.js
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm


--
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/organisationunit/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2011-09-07 14:22:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java	2011-09-14 03:44:56 +0000
@@ -115,7 +115,16 @@
      *         there are no OrganisationUnits.
      */
     Collection<OrganisationUnit> getAllOrganisationUnits();
-
+    
+    /**
+     * Returns all OrganisationUnits with corresponding name key based on the given list.
+     * 
+     * @param orgUnits the collection of organization unit objects.
+     * @param key the name key.
+     * @return a collection of OrganisationUnits.
+     */
+    void searchOrganisationUnitByName( List<OrganisationUnit> orgUnits, String key );
+    
     /**
      * Returns all OrganisationUnits with corresponding identifiers.
      * 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-09-07 14:22:23 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java	2011-09-14 03:44:56 +0000
@@ -33,6 +33,7 @@
 import java.util.Date;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -165,6 +166,19 @@
         return organisationUnitStore.getAll();
     }
 
+    public void searchOrganisationUnitByName( List<OrganisationUnit> orgUnits, String key )
+    {
+        Iterator<OrganisationUnit> iterator = orgUnits.iterator();
+        
+        while ( iterator.hasNext() )
+        {
+            if ( !iterator.next().getName().toLowerCase().contains( key.toLowerCase() ) )
+            {
+                iterator.remove();
+            }
+        }
+    }
+    
     public Collection<OrganisationUnit> getOrganisationUnits( final Collection<Integer> identifiers )
     {
         Collection<OrganisationUnit> objects = getAllOrganisationUnits();

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java	2011-09-10 08:40:27 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java	2011-09-14 03:44:56 +0000
@@ -36,6 +36,7 @@
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.indicator.Indicator;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.user.User;
 import org.hisp.dhis.user.UserCredentials;
 import org.hisp.dhis.validation.ValidationRule;
@@ -110,6 +111,8 @@
 
     private Collection<Indicator> indicatorObjects = new ArrayList<Indicator>();
 
+    private Collection<OrganisationUnit> organisationUnitObjects = new ArrayList<OrganisationUnit>();
+
     private Collection<UserCredentials> userObjects = new ArrayList<UserCredentials>();
 
     private Collection<ValidationRule> validationRuleObjects = new ArrayList<ValidationRule>();
@@ -478,6 +481,16 @@
         this.indicatorObjects = indicatorObjects;
     }
 
+    public Collection<OrganisationUnit> getOrganisationUnitObjects()
+    {
+        return organisationUnitObjects;
+    }
+
+    public void setOrganisationUnitObjects( Collection<OrganisationUnit> organisationUnitObjects )
+    {
+        this.organisationUnitObjects = organisationUnitObjects;
+    }
+
     public Collection<UserCredentials> getUserObjects()
     {
         return userObjects;

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/OrganisationUnitConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/OrganisationUnitConverter.java	2010-12-26 21:40:52 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/OrganisationUnitConverter.java	2011-09-14 03:44:56 +0000
@@ -27,17 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.importexport.ExportParams;
 import org.hisp.dhis.importexport.PDFConverter;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.system.util.PDFUtils;
 
 import com.lowagie.text.Document;
@@ -53,11 +47,8 @@
     extends PDFUtils
     implements PDFConverter
 {
-    private OrganisationUnitService organisationUnitService;
-
-    public OrganisationUnitConverter( OrganisationUnitService organisationUnitService )
+    public OrganisationUnitConverter( )
     {
-        this.organisationUnitService = organisationUnitService;
     }
 
     // -------------------------------------------------------------------------
@@ -69,12 +60,9 @@
         I18n i18n = params.getI18n();
         I18nFormat format = params.getFormat();
 
-        PDFUtils.printObjectFrontPage( document, params.getOrganisationUnits(), i18n, format, "organisation_units" );
-
-        List<OrganisationUnit> units = new ArrayList<OrganisationUnit>( organisationUnitService.getOrganisationUnits( params.getOrganisationUnits() ) );
-        Collections.sort( units, new OrganisationUnitNameComparator() );
-
-        for ( OrganisationUnit unit : units )
+        PDFUtils.printObjectFrontPage( document, params.getOrganisationUnitObjects(), i18n, format, "organisation_units" );
+
+        for ( OrganisationUnit unit : params.getOrganisationUnitObjects() )
         {
             addTableToDocument( document, printOrganisationUnit( unit, i18n, format, true, 0.40f, 0.60f ) );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/ITextPDFExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/ITextPDFExportService.java	2011-09-10 08:40:27 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/ITextPDFExportService.java	2011-09-14 03:44:56 +0000
@@ -109,7 +109,7 @@
             thread.setDataElementConverter( new DataElementConverter() );
             thread.setIndicatorConverter( new IndicatorConverter( expressionService ) );
             thread.setOrganisationUnitHierarchyConverter( new OrganisationUnitHierarchyConverter( organisationUnitService ) );
-            thread.setOrganisationUnitConverter( new OrganisationUnitConverter( organisationUnitService ) );
+            thread.setOrganisationUnitConverter( new OrganisationUnitConverter() );
             thread.setUserConverter( new UserConverter() );
             thread.setValidationRuleConverter( new ValidationRuleConverter( expressionService ) );
 

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java	2011-09-12 09:15:08 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java	2011-09-14 03:44:56 +0000
@@ -531,8 +531,7 @@
         }
 
         table.addCell( getItalicCell( i18n.getString( "opening_date" ) ) );
-        table
-            .addCell( getTextCell( unit.getOpeningDate() != null ? format.formatDate( unit.getOpeningDate() ) : EMPTY ) );
+        table.addCell( getTextCell( unit.getOpeningDate() != null ? format.formatDate( unit.getOpeningDate() ) : EMPTY ) );
 
         if ( unit.getClosedDate() != null )
         {

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties	2011-09-09 06:18:32 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties	2011-09-14 03:44:56 +0000
@@ -58,7 +58,7 @@
 dhis-web-reporting 						= B\u00e1o c\u00e1o
 dhis-web-openhealth-integration 		= Ph\u00e2n t\u00edch d\u1eef li\u1ec7u
 dhis-web-datastatus						= Tr\u1ea1ng th\u00e1i d\u1eef li\u1ec7u
-dhis-web-excel-reporting				= B\u00e1o c\u00e1o excel
+dhis-web-spreadsheet-reporting 			= B\u00e1o c\u00e1o d\u1ea1ng B\u1ea3ng t\u00ednh
 
 #-- Common ---------------------------------------------------------------------#
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/pom.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/pom.xml	2011-08-28 17:52:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/pom.xml	2011-09-14 03:44:56 +0000
@@ -31,6 +31,10 @@
     </dependency>
     <dependency>
       <groupId>org.hisp.dhis</groupId>
+      <artifactId>dhis-service-importexport</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.hisp.dhis</groupId>
       <artifactId>dhis-web-commons</artifactId>
     </dependency>
     <dependency>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitListAction.java	2011-05-06 11:10:34 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/java/org/hisp/dhis/oum/action/organisationunit/GetOrganisationUnitListAction.java	2011-09-14 03:44:56 +0000
@@ -37,12 +37,14 @@
 
 import org.hisp.dhis.options.displayproperty.DisplayPropertyHandler;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
 import org.hisp.dhis.paging.ActionPagingSupport;
 
 /**
  * @author Torgeir Lorange Ostby
- * @version $Id: GetOrganisationUnitListAction.java 1898 2006-09-22 12:06:56Z torgeilo $
+ * @version $Id: GetOrganisationUnitListAction.java 1898 2006-09-22 12:06:56Z
+ *          torgeilo $
  */
 public class GetOrganisationUnitListAction
     extends ActionPagingSupport<OrganisationUnit>
@@ -55,6 +57,13 @@
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
+    
+    private OrganisationUnitService organisationUnitService;
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
 
     private OrganisationUnitSelectionManager selectionManager;
 
@@ -73,7 +82,7 @@
     {
         this.organisationUnitComparator = organisationUnitComparator;
     }
-    
+
     // -------------------------------------------------------------------------
     // DisplayPropertyHandler
     // -------------------------------------------------------------------------
@@ -83,8 +92,8 @@
     public void setDisplayPropertyHandler( DisplayPropertyHandler displayPropertyHandler )
     {
         this.displayPropertyHandler = displayPropertyHandler;
-    }    
-    
+    }
+
     // -------------------------------------------------------------------------
     // Input & Output
     // -------------------------------------------------------------------------
@@ -97,7 +106,7 @@
     }
 
     private String key;
-    
+
     public String getKey()
     {
         return key;
@@ -128,33 +137,19 @@
                 organisationUnits.addAll( selectedUnit.getChildren() );
             }
         }
-        
+
         Collections.sort( organisationUnits, organisationUnitComparator );
-        
+
         displayPropertyHandler.handle( organisationUnits );
-        
+
         if ( isNotBlank( key ) )
         {
-            organisationUnits = searchByName( organisationUnits, key );
+            organisationUnitService.searchOrganisationUnitByName( organisationUnits, key );
         }
-        
+
         this.paging = createPaging( organisationUnits.size() );
         organisationUnits = getBlockElement( organisationUnits, paging.getStartPos(), paging.getPageSize() );
 
         return SUCCESS;
     }
-    
-    private List<OrganisationUnit> searchByName( List<OrganisationUnit> orgUnits, String key )
-    {
-        List<OrganisationUnit> result = new ArrayList<OrganisationUnit>();
-
-        for ( OrganisationUnit each : orgUnits )
-        {
-            if ( each.getName().toLowerCase().contains( key.toLowerCase() ) )
-            {
-                result.add( each );
-            }
-        }
-        return result;
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml	2011-06-23 14:44:17 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/META-INF/dhis/beans.xml	2011-09-14 03:44:56 +0000
@@ -100,6 +100,21 @@
     </property>
   </bean>
 
+    <!-- PDF -->
+
+  <bean id="org.hisp.dhis.oum.action.pdf.ExportToPdfAction" class="org.hisp.dhis.oum.action.pdf.ExportToPdfAction"
+    scope="prototype">
+    <property name="serviceProvider">
+      <ref bean="exportServiceProvider" />
+    </property>
+    <property name="selectionManager">
+	  <ref bean="org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager" />
+	</property>
+    <property name="organisationUnitService">
+	  <ref bean="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+	</property>
+  </bean>
+  
 	<!-- OrganisationUnitGroup -->
 
   <bean id="org.hisp.dhis.oum.action.organisationunitgroup.GetOrganisationUnitGroupListAction" class="org.hisp.dhis.oum.action.organisationunitgroup.GetOrganisationUnitGroupListAction"

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2011-08-21 10:26:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/resources/struts.xml	2011-09-14 03:44:56 +0000
@@ -84,6 +84,17 @@
       <param name="onExceptionReturn">plainTextError</param>
       <param name="requiredAuthorities">F_ORGANISATIONUNIT_DELETE</param>
     </action>
+	
+	<!-- PDF -->
+
+    <action name="exportToPdf" class="org.hisp.dhis.oum.action.pdf.ExportToPdfAction">
+      <result name="success" type="stream">
+        <param name="contentType">application/zip</param>
+        <param name="inputName">inputStream</param>
+        <param name="contentDisposition">filename="${fileName}"</param>
+        <param name="bufferSize">10240</param>
+      </result>
+    </action>
 
     <!-- OrganisationUnitGroup -->
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnit.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnit.js	2011-08-19 21:33:57 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/javascript/organisationUnit.js	2011-09-14 03:44:56 +0000
@@ -13,6 +13,20 @@
 }
 
 // -----------------------------------------------------------------------------
+// Export to PDF
+// -----------------------------------------------------------------------------
+
+function exportPDF( type )
+{
+	var params = {
+		type: type,
+		key: jQuery( 'input[type=text][name=key]' ).val()
+	};
+	
+	exportPdfByType( params );
+}
+
+// -----------------------------------------------------------------------------
 // View details
 // -----------------------------------------------------------------------------
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm	2011-03-19 19:30:05 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-organisationunit/src/main/webapp/dhis-web-maintenance-organisationunit/organisationUnit.vm	2011-09-14 03:44:56 +0000
@@ -17,7 +17,10 @@
 			<table width="100%">
 				<tr>
 					<td>#filterDiv( "organisationUnit" )</td>
-					<td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddOrganisationUnitForm.action'"/></td>
+					<td colspan="3" style="text-align:right">
+						<input type="button" value="$i18n.getString( 'get_pdf' )" onclick="exportPDF( 'organisationunit' );" style="width:80px"/>
+						<input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddOrganisationUnitForm.action'"/>
+					</td>
 				</tr>
 			</table>
 			<table class="listTable" id="listTable">