dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #13800
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4525: Users module - Allowed to export the list of users in PDF file.
------------------------------------------------------------
revno: 4525
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-09-06 12:37:32 +0700
message:
Users module - Allowed to export the list of users in PDF file.
added:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/UserConverter.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/pdf/
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/pdf/ExportToPdfAction.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.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/exporter/ITextPDFExportService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/PDFPipeThread.java
dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml
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.properties
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-user/pom.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.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/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-09-04 10:21:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2011-09-06 05:37:32 +0000
@@ -175,6 +175,14 @@
*/
void deleteUserCredentials( UserCredentials userCredentials );
+ /**
+ * Get the UserCredentials with the corresponding identifiers.
+ *
+ * @param identifiers the collection of identifiers.
+ * @return a collection of users.
+ */
+ Collection<UserCredentials> getUsers( Collection<Integer> identifiers, User user );
+
Collection<UserCredentials> searchUsersByName( String key );
Collection<UserCredentials> getUsersBetween( int first, int max );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-09-04 10:21:24 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2011-09-06 05:37:32 +0000
@@ -9,7 +9,10 @@
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.filter.UserCredentialsCanUpdateFilter;
import org.hisp.dhis.system.util.AuditLogUtil;
+import org.hisp.dhis.system.util.Filter;
+import org.hisp.dhis.system.util.FilterUtils;
import org.springframework.transaction.annotation.Transactional;
/*
@@ -48,18 +51,18 @@
implements UserService
{
private static final Log log = LogFactory.getLog( DefaultUserService.class );
-
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
private CurrentUserService currentUserService;
-
+
public void setCurrentUserService( CurrentUserService currentUserService )
{
this.currentUserService = currentUserService;
}
-
+
private UserStore userStore;
public void setUserStore( UserStore userStore )
@@ -135,32 +138,26 @@
public int addUser( User user )
{
- log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(),
- AuditLogUtil.ACTION_ADD ,
- User.class.getSimpleName(),
- user.getName()) );
-
+ log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_ADD, User.class
+ .getSimpleName(), user.getName() ) );
+
return userStore.addUser( user );
}
public void deleteUser( User user )
{
userStore.deleteUser( user );
-
- log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(),
- AuditLogUtil.ACTION_DELETE ,
- User.class.getSimpleName(),
- user.getName()) );
+
+ log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_DELETE,
+ User.class.getSimpleName(), user.getName() ) );
}
public void updateUser( User user )
{
userStore.updateUser( user );
- log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(),
- AuditLogUtil.ACTION_EDIT ,
- User.class.getSimpleName(),
- user.getName()) );
+ log.info( AuditLogUtil.logMessage( currentUserService.getCurrentUsername(), AuditLogUtil.ACTION_EDIT,
+ User.class.getSimpleName(), user.getName() ) );
}
public Collection<User> getAllUsers()
@@ -183,6 +180,22 @@
return userStore.getUserCountByName( userName );
}
+ public Collection<UserCredentials> getUsers( final Collection<Integer> identifiers, User user )
+ {
+ Collection<UserCredentials> userCredentialsS = getAllUserCredentials();
+
+ FilterUtils.filter( userCredentialsS, new UserCredentialsCanUpdateFilter( user ) );
+
+ return identifiers == null ? userCredentialsS : FilterUtils.filter( userCredentialsS,
+ new Filter<UserCredentials>()
+ {
+ public boolean retain( UserCredentials object )
+ {
+ return identifiers.contains( object.getId() );
+ }
+ } );
+ }
+
public Collection<UserCredentials> getUsersByOrganisationUnitBetween( OrganisationUnit unit, int first, int max )
{
return userStore.getUsersByOrganisationUnitBetween( unit, first, max );
@@ -223,7 +236,7 @@
{
return userStore.getUsersWithoutOrganisationUnitCountByName( userName );
}
-
+
// -------------------------------------------------------------------------
// UserAuthorityGroup
// -------------------------------------------------------------------------
@@ -294,7 +307,7 @@
}
}
}
-
+
// -------------------------------------------------------------------------
// UserCredentials
// -------------------------------------------------------------------------
@@ -353,35 +366,35 @@
{
return userStore.searchUsersByName( username );
}
-
+
public void setLastLogin( String username )
{
UserCredentials credentials = getUserCredentialsByUsername( username );
credentials.setLastLogin( new Date() );
- updateUserCredentials( credentials );
+ updateUserCredentials( credentials );
}
-
+
public Collection<UserCredentials> getInactiveUsers( int months, int first, int max )
{
Calendar cal = PeriodType.createCalendarInstance();
- cal.add( Calendar.MONTH, ( months * -1 ) );
-
+ cal.add( Calendar.MONTH, (months * -1) );
+
return userStore.getInactiveUsers( cal.getTime(), first, max );
}
-
+
public int getInactiveUsersCount( int months )
{
Calendar cal = PeriodType.createCalendarInstance();
- cal.add( Calendar.MONTH, ( months * -1 ) );
-
+ cal.add( Calendar.MONTH, (months * -1) );
+
return userStore.getInactiveUsersCount( cal.getTime() );
}
-
+
public int getActiveUsersCount( int days )
{
Calendar cal = PeriodType.createCalendarInstance();
- cal.add( Calendar.DAY_OF_YEAR, ( days * -1 ) );
-
+ cal.add( Calendar.DAY_OF_YEAR, (days * -1) );
+
return userStore.getActiveUsersCount( cal.getTime() );
}
@@ -413,4 +426,5 @@
{
return userStore.getUserSetting( user, name );
}
+
}
=== 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-04-24 15:50:02 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportParams.java 2011-09-06 05:37:32 +0000
@@ -34,6 +34,7 @@
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.user.User;
/**
* @author Lars Helge Overland
@@ -42,71 +43,75 @@
public class ExportParams
{
private boolean includeDataValues;
-
+
private boolean includeCompleteDataSetRegistrations;
-
+
private boolean aggregatedData;
-
+
private Date startDate;
-
+
private Date endDate;
-
+
+ private User currentUser;
+
private Collection<Integer> categories = new ArrayList<Integer>();
-
+
private Collection<Integer> categoryOptions = new ArrayList<Integer>();
-
+
private Collection<Integer> categoryCombos = new ArrayList<Integer>();
private Collection<Integer> categoryOptionCombos = new ArrayList<Integer>();
private Collection<Integer> dataElements = new ArrayList<Integer>();
-
+
private Collection<Integer> dataElementGroups = new ArrayList<Integer>();
-
+
private Collection<Integer> dataElementGroupSets = new ArrayList<Integer>();
-
+
private Collection<Integer> indicators = new ArrayList<Integer>();
-
+
private Collection<Integer> indicatorGroups = new ArrayList<Integer>();
-
+
private Collection<Integer> indicatorGroupSets = new ArrayList<Integer>();
-
+
private Collection<Integer> indicatorTypes = new ArrayList<Integer>();
-
+
private Collection<Integer> dataDictionaries = new ArrayList<Integer>();
-
+
private Collection<Integer> dataSets = new ArrayList<Integer>();
-
+
private Collection<Integer> periods = new ArrayList<Integer>();
-
+
private Collection<Integer> organisationUnits = new ArrayList<Integer>();
-
+
private Collection<Integer> organisationUnitGroups = new ArrayList<Integer>();
-
+
private Collection<Integer> organisationUnitGroupSets = new ArrayList<Integer>();
-
+
private Collection<Integer> organisationUnitLevels = new HashSet<Integer>();
-
+
+ private Collection<Integer> users = new HashSet<Integer>();
+
private Collection<Integer> validationRules = new ArrayList<Integer>();
-
+
private Collection<Integer> reports = new ArrayList<Integer>();
-
+
private Collection<Integer> reportTables = new ArrayList<Integer>();
-
+
private Collection<Integer> charts = new ArrayList<Integer>();
-
+
private Collection<Integer> olapUrls = new ArrayList<Integer>();
-
+
private I18n i18n;
-
+
private I18nFormat format;
-
+
// -------------------------------------------------------------------------
// Constructur
// -------------------------------------------------------------------------
-
+
public ExportParams()
- {
+ {
}
// -------------------------------------------------------------------------
@@ -132,7 +137,7 @@
{
this.includeCompleteDataSetRegistrations = includeCompleteDataSetRegistrations;
}
-
+
public boolean isAggregatedData()
{
return aggregatedData;
@@ -162,7 +167,7 @@
{
this.endDate = endDate;
}
-
+
public I18n getI18n()
{
return i18n;
@@ -172,7 +177,7 @@
{
this.i18n = i18n;
}
-
+
public I18nFormat getFormat()
{
return format;
@@ -223,6 +228,19 @@
this.categoryOptionCombos = categoryOptionCombos;
}
+ /**
+ * @return
+ */
+ public User getCurrentUser()
+ {
+ return currentUser;
+ }
+
+ public void setCurrentUser( User currentUser )
+ {
+ this.currentUser = currentUser;
+ }
+
public Collection<Integer> getDataElements()
{
return dataElements;
@@ -373,6 +391,16 @@
this.validationRules = validationRules;
}
+ public Collection<Integer> getUsers()
+ {
+ return users;
+ }
+
+ public void setUsers( Collection<Integer> users )
+ {
+ this.users = users;
+ }
+
public Collection<Integer> getReports()
{
return reports;
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/UserConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/UserConverter.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/converter/UserConverter.java 2011-09-06 05:37:32 +0000
@@ -0,0 +1,84 @@
+package org.hisp.dhis.importexport.pdf.converter;
+
+/*
+ * Copyright (c) 2004-2011, 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.
+ */
+
+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.system.util.PDFUtils;
+import org.hisp.dhis.user.UserCredentials;
+import org.hisp.dhis.user.UserService;
+import org.hisp.dhis.user.comparator.UsernameComparator;
+
+import com.lowagie.text.Document;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class UserConverter
+ extends PDFUtils
+ implements PDFConverter
+{
+ private UserService userService;
+
+ /**
+ * Constructor for write operations.
+ */
+ public UserConverter( UserService userService )
+ {
+ this.userService = userService;
+ }
+
+ // -------------------------------------------------------------------------
+ // PDFConverter implementation
+ // -------------------------------------------------------------------------
+
+ public void write( Document document, ExportParams params )
+ {
+ I18n i18n = params.getI18n();
+ I18nFormat format = params.getFormat();
+
+ PDFUtils.printObjectFrontPage( document, params.getUsers(), i18n, format, "users" );
+
+ List<UserCredentials> userCredentialss = new ArrayList<UserCredentials>( userService.getUsers( params
+ .getUsers(), params.getCurrentUser() ) );
+
+ Collections.sort( userCredentialss, new UsernameComparator() );
+
+ for ( UserCredentials userCredentials : userCredentialss )
+ {
+ addTableToDocument( document, printUser( userCredentials, 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 2010-12-26 21:40:52 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/ITextPDFExportService.java 2011-09-06 05:37:32 +0000
@@ -44,9 +44,11 @@
import org.hisp.dhis.importexport.pdf.converter.IndicatorConverter;
import org.hisp.dhis.importexport.pdf.converter.OrganisationUnitConverter;
import org.hisp.dhis.importexport.pdf.converter.OrganisationUnitHierarchyConverter;
+import org.hisp.dhis.importexport.pdf.converter.UserConverter;
import org.hisp.dhis.importexport.pdf.converter.ValidationRuleConverter;
import org.hisp.dhis.indicator.IndicatorService;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.user.UserService;
import org.hisp.dhis.validation.ValidationRuleService;
/**
@@ -74,6 +76,13 @@
this.dataElementService = dataElementService;
}
+ private ExpressionService expressionService;
+
+ public void setExpressionService( ExpressionService expressionService )
+ {
+ this.expressionService = expressionService;
+ }
+
private IndicatorService indicatorService;
public void setIndicatorService( IndicatorService indicatorService )
@@ -88,11 +97,11 @@
this.organisationUnitService = organisationUnitService;
}
- private ExpressionService expressionService;
+ private UserService userService;
- public void setExpressionService( ExpressionService expressionService )
+ public void setUserService( UserService userService )
{
- this.expressionService = expressionService;
+ this.userService = userService;
}
private ValidationRuleService validationRuleService;
@@ -134,6 +143,7 @@
thread.setOrganisationUnitHierarchyConverter( new OrganisationUnitHierarchyConverter(
organisationUnitService ) );
thread.setOrganisationUnitConverter( new OrganisationUnitConverter( organisationUnitService ) );
+ thread.setUserConverter( new UserConverter( userService ) );
thread.setValidationRuleConverter( new ValidationRuleConverter( validationRuleService, expressionService ) );
thread.start();
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/PDFPipeThread.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/PDFPipeThread.java 2011-01-17 17:03:05 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/pdf/exporter/PDFPipeThread.java 2011-09-06 05:37:32 +0000
@@ -32,6 +32,7 @@
import org.hibernate.SessionFactory;
import org.hisp.dhis.importexport.ExportParams;
import org.hisp.dhis.importexport.PDFConverter;
+import org.hisp.dhis.importexport.pdf.converter.UserConverter;
import org.hisp.dhis.system.process.OpenSessionThread;
import org.hisp.dhis.system.util.PDFUtils;
import org.hisp.dhis.system.util.StreamUtils;
@@ -87,6 +88,14 @@
this.organisationUnitConverter = organisationUnitConverter;
}
+ private PDFConverter userConverter;
+
+ public void setUserConverter( UserConverter userConverter )
+ {
+ this.userConverter = userConverter;
+
+ }
+
private PDFConverter validationRuleConverter;
public void setValidationRuleConverter( PDFConverter validationRuleConverter )
@@ -116,15 +125,17 @@
document = PDFUtils.openDocument( outputStream );
PDFUtils.printDocumentFrontPage( document, exportParams.getI18n(), exportParams.getFormat() );
-
+
dataElementConverter.write( document, exportParams );
-
+
indicatorConverter.write( document, exportParams );
organisationUnitHierarchyConverter.write( document, exportParams );
organisationUnitConverter.write( document, exportParams );
+ userConverter.write( document, exportParams );
+
validationRuleConverter.write( document, exportParams );
PDFUtils.closeDocument( document );
@@ -134,4 +145,5 @@
StreamUtils.closeOutputStream( outputStream );
}
}
+
}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2011-07-13 11:32:13 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml 2011-09-06 05:37:32 +0000
@@ -269,9 +269,10 @@
<bean id="org.hisp.dhis.importexport.PDFExportService" class="org.hisp.dhis.importexport.pdf.exporter.ITextPDFExportService">
<property name="sessionFactory" ref="sessionFactory" />
<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+ <property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
- <property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
+ <property name="userService" ref="org.hisp.dhis.user.UserService" />
<property name="validationRuleService" ref="org.hisp.dhis.validation.ValidationRuleService" />
</bean>
=== 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-03-30 07:47:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java 2011-09-06 05:37:32 +0000
@@ -42,6 +42,9 @@
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.UserAuthorityGroup;
+import org.hisp.dhis.user.UserCredentials;
import org.hisp.dhis.validation.ValidationRule;
import com.lowagie.text.Document;
@@ -62,7 +65,7 @@
public class PDFUtils
{
private static final String EMPTY = "";
-
+
/**
* Creates a document.
*
@@ -202,34 +205,34 @@
return cell;
}
-
+
public static PdfPCell getTitleCell( String text, int colspan )
{
return getCell( text, colspan, getBoldFont( 16 ), ALIGN_CENTER );
}
-
+
public static PdfPCell getSubtitleCell( String text, int colspan )
{
return getCell( text, colspan, getItalicFont( 12 ), ALIGN_CENTER );
}
-
+
public static PdfPCell getHeaderCell( String text, int colspan )
{
return getCell( text, colspan, getFont( 12 ), ALIGN_LEFT );
}
-
+
public static PdfPCell getTextCell( String text )
{
return getCell( text, 1, getFont( 9 ), ALIGN_LEFT );
}
-
+
public static PdfPCell getTextCell( Object object )
{
String text = object != null ? String.valueOf( object ) : EMPTY;
-
+
return getCell( text, 1, getFont( 9 ), ALIGN_LEFT );
}
-
+
public static PdfPCell getItalicCell( String text )
{
return getCell( text, 1, getItalicFont( 9 ), ALIGN_LEFT );
@@ -241,10 +244,10 @@
cell.setPaddingBottom( bottom );
cell.setPaddingLeft( left );
cell.setPaddingRight( right );
-
+
return cell;
}
-
+
/**
* Creates an empty cell.
*
@@ -292,7 +295,7 @@
catch ( Exception ex )
{
throw new RuntimeException( "Error while creating base font", ex );
- }
+ }
}
// -------------------------------------------------------------------------
@@ -307,8 +310,8 @@
* @param format The i18nFormat object
*
*/
- public static void printObjectFrontPage( Document document, Collection<?> objectIds, I18n i18n,
- I18nFormat format, String frontPageLabel )
+ public static void printObjectFrontPage( Document document, Collection<?> objectIds, I18n i18n, I18nFormat format,
+ String frontPageLabel )
{
if ( objectIds == null || objectIds.size() > 0 )
{
@@ -373,7 +376,8 @@
* multiple pages or should be kept at one page.
* @param columnWidths The column widths.
*/
- public static PdfPTable printDataElement( DataElement element, I18n i18n, boolean keepTogether, float... columnWidths )
+ public static PdfPTable printDataElement( DataElement element, I18n i18n, boolean keepTogether,
+ float... columnWidths )
{
PdfPTable table = getPdfPTable( keepTogether, columnWidths );
@@ -427,8 +431,8 @@
* multiple pages or should be kept at one page.
* @param columnWidths The column widths.
*/
- public static PdfPTable printIndicator( Indicator indicator, I18n i18n,
- ExpressionService expressionService, boolean keepTogether, float... columnWidths )
+ public static PdfPTable printIndicator( Indicator indicator, I18n i18n, ExpressionService expressionService,
+ boolean keepTogether, float... columnWidths )
{
PdfPTable table = getPdfPTable( keepTogether, columnWidths );
@@ -465,7 +469,8 @@
table.addCell( getTextCell( indicator.getNumeratorDescription() ) );
table.addCell( getItalicCell( i18n.getString( "numerator_aggregation_operator" ) ) );
- table.addCell( getTextCell( i18n.getString( getAggregationOperator().get( indicator.getNumeratorAggregationOperator() ) ) ) );
+ table.addCell( getTextCell( i18n.getString( getAggregationOperator().get(
+ indicator.getNumeratorAggregationOperator() ) ) ) );
table.addCell( getItalicCell( i18n.getString( "numerator_formula" ) ) );
table.addCell( getTextCell( expressionService.getExpressionDescription( indicator.getNumerator() ) ) );
@@ -474,7 +479,8 @@
table.addCell( getTextCell( indicator.getDenominatorDescription() ) );
table.addCell( getItalicCell( i18n.getString( "denominator_aggregation_operator" ) ) );
- table.addCell( getTextCell( i18n.getString( getAggregationOperator().get( indicator.getDenominatorAggregationOperator() ) ) ) );
+ table.addCell( getTextCell( i18n.getString( getAggregationOperator().get(
+ indicator.getDenominatorAggregationOperator() ) ) ) );
table.addCell( getItalicCell( i18n.getString( "denominator_formula" ) ) );
table.addCell( getTextCell( expressionService.getExpressionDescription( indicator.getDenominator() ) ) );
@@ -497,7 +503,8 @@
* multiple pages or should be kept at one page.
* @param columnWidths The column widths.
*/
- public static PdfPTable printOrganisationUnit( OrganisationUnit unit, I18n i18n, I18nFormat format, boolean keepTogether, float... columnWidths )
+ public static PdfPTable printOrganisationUnit( OrganisationUnit unit, I18n i18n, I18nFormat format,
+ boolean keepTogether, float... columnWidths )
{
PdfPTable table = getPdfPTable( keepTogether, columnWidths );
@@ -515,12 +522,12 @@
}
table.addCell( getItalicCell( i18n.getString( "opening_date" ) ) );
- table.addCell( getTextCell( unit.getOpeningDate() != null ? format.formatDate( unit.getOpeningDate() ) : "" ) );
+ table.addCell( getTextCell( unit.getOpeningDate() != null ? format.formatDate( unit.getOpeningDate() ) : EMPTY ) );
if ( unit.getClosedDate() != null )
{
table.addCell( getItalicCell( i18n.getString( "closed_date" ) ) );
- table.addCell( getTextCell( unit.getClosedDate() != null ? format.formatDate( unit.getClosedDate() ) : "" ) );
+ table.addCell( getTextCell( format.formatDate( unit.getClosedDate() ) ) );
}
table.addCell( getItalicCell( i18n.getString( "active" ) ) );
@@ -540,6 +547,77 @@
/**
* Creates a table with the given validation rule
*
+ * @param user The User
+ * @param i18n i18n object
+ * @param format I18nFormat object
+ * @param keepTogether Indicates whether the table could be broken across
+ * multiple pages or should be kept at one page.
+ * @param columnWidths The column widths.
+ */
+ public static PdfPTable printUser( UserCredentials userCredentials, I18n i18n, I18nFormat format,
+ boolean keepTogether, float... columnWidths )
+ {
+ User user = userCredentials.getUser();
+
+ PdfPTable table = getPdfPTable( keepTogether, columnWidths );
+
+ table.addCell( getHeaderCell( user.getFirstName() + ", " + user.getSurname(), 2 ) );
+
+ table.addCell( getEmptyCell( 2, 15 ) );
+
+ table.addCell( getItalicCell( i18n.getString( "username" ) ) );
+ table.addCell( getTextCell( userCredentials.getUsername() ) );
+
+ if ( nullIfEmpty( user.getEmail() ) != null )
+ {
+ table.addCell( getItalicCell( i18n.getString( "email" ) ) );
+ table.addCell( getTextCell( user.getEmail() ) );
+ }
+
+ if ( nullIfEmpty( user.getPhoneNumber() ) != null )
+ {
+ table.addCell( getItalicCell( i18n.getString( "phone_number" ) ) );
+ table.addCell( getTextCell( user.getPhoneNumber() ) );
+ }
+
+ table.addCell( getItalicCell( i18n.getString( "last_login" ) ) );
+ table.addCell( getTextCell( userCredentials.getLastLogin() != null ? format.formatDate( userCredentials
+ .getLastLogin() ) : EMPTY ) );
+
+ String temp = "";
+
+ for ( OrganisationUnit unit : user.getOrganisationUnits() )
+ {
+ temp += unit.getName().concat( ", " );
+ }
+
+ temp = temp.trim();
+ temp.substring( 0, temp.isEmpty() ? 0 : temp.length() - 2 );
+
+ table.addCell( getItalicCell( i18n.getString( "organisation_units" ) ) );
+ table.addCell( getTextCell( temp ) );
+
+ temp = "";
+
+ for ( UserAuthorityGroup role : userCredentials.getUserAuthorityGroups() )
+ {
+ temp += role.getName().concat( ", " );
+ }
+
+ temp = temp.trim();
+ temp.substring( 0, temp.isEmpty() ? 0 : temp.length() - 2 );
+
+ table.addCell( getItalicCell( i18n.getString( "roles" ) ) );
+ table.addCell( getTextCell( temp ) );
+
+ table.addCell( getEmptyCell( 2, 30 ) );
+
+ return table;
+ }
+
+ /**
+ * Creates a table with the given validation rule
+ *
* @param validationRule The validation rule
* @param i18n i18n object
* @param expressionService The expression service
@@ -550,7 +628,7 @@
* multiple pages or should be kept at one page.
* @param columnWidths The column widths.
*/
- public static PdfPTable printValidationRule( ValidationRule validationRule, I18n i18n,
+ public static PdfPTable printValidationRule( ValidationRule validationRule, I18n i18n,
ExpressionService expressionService, boolean keepTogether, float... columnWidths )
{
PdfPTable table = getPdfPTable( keepTogether, columnWidths );
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2011-08-12 11:35:39 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global.properties 2011-09-06 05:37:32 +0000
@@ -452,6 +452,7 @@
organisation_unit_hierarchy = Organisation unit hierarchy
validation_rules = Validation rules
period_type = Period Type
+users = Users
#-- Indicator -----------------------------------------------------------------#
=== 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-07-13 11:32:13 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/i18n_global_vi_VN.properties 2011-09-06 05:37:32 +0000
@@ -392,6 +392,7 @@
organisation_unit_hierarchy = C\u00e2y ph\u00e2n c\u1ea5p \u0111\u01a1n v\u1ecb
validation_rules = C\u00e1c \u0111i\u1ec1u ki\u1ec7n ki\u1ec3m tra
period_type = Ki\u1ec3u th\u1eddi gian
+users = Ng\u01b0\u1eddi d\u00f9ng
#-- Indicator -----------------------------------------------------------------#
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml 2011-08-28 17:52:59 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/pom.xml 2011-09-06 05:37:32 +0000
@@ -9,7 +9,7 @@
</parent>
<artifactId>dhis-web-maintenance-user</artifactId>
- <packaging>war</packaging>
+ <packaging>jar</packaging>
<name>DHIS User Maintenance</name>
<build>
@@ -25,6 +25,10 @@
<artifactId>dhis-service-core</artifactId>
</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>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java 2011-09-04 10:21:24 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/GetUserListAction.java 2011-09-06 05:37:32 +0000
@@ -101,7 +101,7 @@
{
return key;
}
-
+
private Integer months;
public Integer getMonths()
@@ -120,34 +120,38 @@
public String execute()
throws Exception
- {
+ {
if ( isNotBlank( key ) ) // Filter on key only if set
{
this.paging = createPaging( userService.getUserCountByName( key ) );
-
- userCredentialsList = new ArrayList<UserCredentials>( userService.getUsersBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
+
+ userCredentialsList = new ArrayList<UserCredentials>( userService.getUsersBetweenByName( key, paging
+ .getStartPos(), paging.getPageSize() ) );
Collections.sort( userCredentialsList, new UsernameComparator() );
}
else if ( months != null && months != 0 )
{
this.paging = createPaging( userService.getInactiveUsersCount( months ) );
-
- userCredentialsList = new ArrayList<UserCredentials>( userService.getInactiveUsers( months, paging.getStartPos(), paging.getPageSize() ) );
+
+ userCredentialsList = new ArrayList<UserCredentials>( userService.getInactiveUsers( months, paging
+ .getStartPos(), paging.getPageSize() ) );
}
else
{
this.paging = createPaging( userService.getUserCount() );
-
- userCredentialsList = new ArrayList<UserCredentials>( userService.getUsersBetween( paging.getStartPos(), paging.getPageSize() ) );
+
+ userCredentialsList = new ArrayList<UserCredentials>( userService.getUsersBetween( paging.getStartPos(),
+ paging.getPageSize() ) );
Collections.sort( userCredentialsList, new UsernameComparator() );
}
- FilterUtils.filter( userCredentialsList, new UserCredentialsCanUpdateFilter( currentUserService.getCurrentUser() ) );
-
+ FilterUtils.filter( userCredentialsList, new UserCredentialsCanUpdateFilter( currentUserService
+ .getCurrentUser() ) );
+
currentUserName = currentUserService.getCurrentUsername();
-
+
return SUCCESS;
}
}
=== added directory 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/pdf'
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/pdf/ExportToPdfAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/pdf/ExportToPdfAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/java/org/hisp/dhis/user/action/pdf/ExportToPdfAction.java 2011-09-06 05:37:32 +0000
@@ -0,0 +1,168 @@
+package org.hisp.dhis.user.action.pdf;
+
+/*
+ * Copyright (c) 2004-2011, 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.
+ */
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.common.ServiceProvider;
+import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.ExportService;
+import org.hisp.dhis.user.CurrentUserService;
+
+import com.opensymphony.xwork2.Action;
+
+/**
+ * @author Dang Duy Hieu
+ * @version $Id$
+ */
+public class ExportToPdfAction
+ implements Action
+{
+ private static final Log log = LogFactory.getLog( ExportToPdfAction.class );
+
+ private static final String EXPORT_FORMAT_PDF = "PDF";
+
+ private static final String TYPE_USER = "user";
+
+ private static final String FILENAME_USER = "Users.zip";
+
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ private CurrentUserService currentUserService;
+
+ public void setCurrentUserService( CurrentUserService currentUserService )
+ {
+ this.currentUserService = currentUserService;
+ }
+
+ private ServiceProvider<ExportService> serviceProvider;
+
+ public void setServiceProvider( ServiceProvider<ExportService> serviceProvider )
+ {
+ this.serviceProvider = serviceProvider;
+ }
+
+ private I18n i18n;
+
+ public void setI18n( I18n i18n )
+ {
+ this.i18n = i18n;
+ }
+
+ private I18nFormat format;
+
+ public void setFormat( I18nFormat format )
+ {
+ this.format = format;
+ }
+
+ // -------------------------------------------------------------------------
+ // Output
+ // -------------------------------------------------------------------------
+
+ private InputStream inputStream;
+
+ public InputStream getInputStream()
+ {
+ return inputStream;
+ }
+
+ private String fileName;
+
+ public String getFileName()
+ {
+ return fileName;
+ }
+
+ // -------------------------------------------------------------------------
+ // Input
+ // -------------------------------------------------------------------------
+
+ private String type;
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+
+ private List<Integer> activeIds = new ArrayList<Integer>();
+
+ public void setActiveIds( List<Integer> activeIds )
+ {
+ this.activeIds = activeIds;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ public String execute()
+ throws Exception
+ {
+ if ( type != null )
+ {
+ ExportParams params = new ExportParams();
+
+ if ( type.equals( TYPE_USER ) )
+ {
+ if ( (activeIds != null) && !activeIds.isEmpty() )
+ {
+ params.setUsers( activeIds );
+ }
+ else
+ {
+ params.setUsers( null );
+ }
+
+ fileName = FILENAME_USER;
+
+ log.info( "Exporting to PDF for object type: " + TYPE_USER );
+ }
+
+ params.setCurrentUser( currentUserService.getCurrentUser() );
+ params.setIncludeDataValues( false );
+ params.setI18n( i18n );
+ params.setFormat( format );
+
+ ExportService exportService = serviceProvider.provide( EXPORT_FORMAT_PDF );
+
+ inputStream = exportService.exportData( params );
+ }
+
+ return SUCCESS;
+ }
+
+}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml 2011-06-19 10:57:18 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/META-INF/dhis/beans.xml 2011-09-06 05:37:32 +0000
@@ -135,6 +135,16 @@
</property>
</bean>
+ <!-- PDF -->
+
+ <bean id="org.hisp.dhis.user.action.pdf.ExportToPdfAction" class="org.hisp.dhis.user.action.pdf.ExportToPdfAction"
+ scope="prototype">
+ <property name="serviceProvider">
+ <ref bean="exportServiceProvider" />
+ </property>
+ <property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
+ </bean>
+
<!-- Role -->
<bean id="org.hisp.dhis.user.action.AddRoleAction" class="org.hisp.dhis.user.action.AddRoleAction" scope="prototype">
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml 2011-07-27 10:39:06 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/resources/struts.xml 2011-09-06 05:37:32 +0000
@@ -88,6 +88,17 @@
<param name="onExceptionReturn">plainTextError</param>
</action>
+ <!-- PDF -->
+
+ <action name="exportToPdf" class="org.hisp.dhis.user.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>
+
<!-- Role -->
<action name="allRole" class="org.hisp.dhis.user.action.GetRoleListAction">
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2011-09-05 04:00:20 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-user/src/main/webapp/dhis-web-maintenance-user/allUser.vm 2011-09-06 05:37:32 +0000
@@ -31,7 +31,10 @@
#end
</select>
</td>
- <td colspan="3" style="text-align:right"><input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddUserForm.action'"/></td>
+ <td colspan="3" style="text-align:right">
+ <input type="button" value="$i18n.getString( 'get_pdf' )" onclick="exportPdfByType( 'user' );" style="width:80px"/>
+ <input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='showAddUserForm.action'"/>
+ </td>
</tr>
</table>
<table class="listTable" id="userList" width='100%'>