← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20148: remove unused code in PDFUtils

 

------------------------------------------------------------
revno: 20148
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-09-15 11:59:19 +0700
message:
  remove unused code in PDFUtils
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.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-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	2015-09-07 08:51:58 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java	2015-09-15 04:59:19 +0000
@@ -28,28 +28,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static com.lowagie.text.Element.ALIGN_CENTER;
-import static com.lowagie.text.Element.ALIGN_LEFT;
-
-import java.io.OutputStream;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.commons.lang3.StringUtils;
-import org.hisp.dhis.attribute.AttributeValue;
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.expression.ExpressionService;
-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.UserAuthorityGroup;
-import org.hisp.dhis.user.UserCredentials;
-import org.hisp.dhis.validation.ValidationRule;
-
 import com.lowagie.text.Document;
 import com.lowagie.text.DocumentException;
 import com.lowagie.text.Font;
@@ -61,6 +39,11 @@
 import com.lowagie.text.pdf.PdfPTable;
 import com.lowagie.text.pdf.PdfWriter;
 
+import java.io.OutputStream;
+
+import static com.lowagie.text.Element.ALIGN_CENTER;
+import static com.lowagie.text.Element.ALIGN_LEFT;
+
 /**
  * @author Lars Helge Overland
  * @author Dang Duy Hieu
@@ -84,7 +67,7 @@
      * Creates a document.
      *
      * @param outputStream The output stream to write the document content.
-     * @param pageSize the page size.
+     * @param pageSize     the page size.
      * @return A Document.
      */
     public static Document openDocument( OutputStream outputStream, Rectangle pageSize )
@@ -120,18 +103,18 @@
      * Creates a table. Specify the columns and widths by providing one<br>
      * float per column with a percentage value. For instance
      * </p>
-     *
+     * <p>
      * <p>
      * getPdfPTable( 0.35f, 0.65f )
      * </p>
-     *
+     * <p>
      * <p>
      * will give you a table with two columns where the first covers 35 %<br>
      * of the page while the second covers 65 %.
      * </p>
      *
      * @param keepTogether Indicates whether the table could be broken across
-     *        multiple pages or should be kept at one page.
+     *                     multiple pages or should be kept at one page.
      * @param columnWidths The column widths.
      * @return
      */
@@ -149,7 +132,7 @@
      * Adds a table to a document.
      *
      * @param document The document to add the table to.
-     * @param table The table to add to the document.
+     * @param table    The table to add to the document.
      */
     public static void addTableToDocument( Document document, PdfPTable table )
     {
@@ -189,9 +172,9 @@
     /**
      * Creates a cell.
      *
-     * @param text The text to include in the cell.
-     * @param colspan The column span of the cell.
-     * @param font The font of the cell text.
+     * @param text            The text to include in the cell.
+     * @param colspan         The column span of the cell.
+     * @param font            The font of the cell text.
      * @param horizontalAlign The vertical alignment of the text in the cell.
      * @return A PdfCell.
      */
@@ -255,7 +238,7 @@
      * Creates an empty cell.
      *
      * @param colspan The column span of the cell.
-     * @param height The height of the column.
+     * @param height  The height of the column.
      * @return A PdfCell.
      */
     public static PdfPCell getEmptyCell( int colSpan, int height )
@@ -300,403 +283,4 @@
             throw new RuntimeException( "Error while creating base font", ex );
         }
     }
-
-    // -------------------------------------------------------------------------
-    // Domain object methods
-    // -------------------------------------------------------------------------
-
-    /**
-     * Writes a "Data Elements" title in front of page
-     *
-     * @param dataElementIds the identifier list of Data
-     * @param i18n The i18n object
-     * @param format The i18nFormat object
-     *
-     */
-    public static void printObjectFrontPage( Document document, Collection<?> objects, I18n i18n, I18nFormat format,
-        String frontPageLabel )
-    {
-        if ( objects == null || objects.size() > 0 )
-        {
-            String title = i18n.getString( frontPageLabel );
-
-            printFrontPage( document, title, i18n, format );
-        }
-    }
-
-    /**
-     * Writes a "Data dictionary" title in front of page
-     *
-     * @param document The document
-     * @param i18n The i18n object
-     * @param format The i18nFormat object
-     *
-     */
-    public static void printDocumentFrontPage( Document document, I18n i18n, I18nFormat format )
-    {
-        String title = i18n.getString( "data_dictionary" );
-
-        printFrontPage( document, title, i18n, format );
-    }
-
-    /**
-     * Writes a DHIS 2 title in front of page
-     *
-     * @param document The document
-     * @param exportParams the exporting params
-     *
-     */
-    private static void printFrontPage( Document document, String title, I18n i18n, I18nFormat format )
-    {
-        PdfPTable table = getPdfPTable( true, 1.00f );
-
-        table.addCell( getTitleCell( i18n.getString( "district_health_information_software" ), 1 ) );
-
-        table.addCell( getEmptyCell( 1, 40 ) );
-
-        table.addCell( getSubtitleCell( title, 1 ) );
-
-        table.addCell( getEmptyCell( 1, 40 ) );
-
-        String date = format.formatDate( Calendar.getInstance().getTime() );
-
-        table.addCell( getSubtitleCell( date, 1 ) );
-
-        addTableToDocument( document, table );
-
-        moveToNewPage( document );
-    }
-
-    /**
-     * Creates a table with the given data element
-     *
-     * @param element The data element
-     * @param i18n i18n object
-     * @param HEADER3 The header3 font
-     * @param ITALIC The italic font
-     * @param TEXT The text font
-     * @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 printDataElement( DataElement element, I18n i18n, boolean keepTogether,
-        float... columnWidths )
-    {
-        PdfPTable table = getPdfPTable( keepTogether, columnWidths );
-
-        table.addCell( getHeaderCell( element.getName(), 2 ) );
-
-        table.addCell( getEmptyCell( 2, 15 ) );
-
-        table.addCell( getItalicCell( i18n.getString( "short_name" ) ) );
-        table.addCell( getTextCell( element.getShortName() ) );
-
-        if ( StringUtils.trimToNull( element.getCode() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "code" ) ) );
-            table.addCell( getTextCell( element.getCode() ) );
-        }
-        if ( StringUtils.trimToNull( element.getDescription() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "description" ) ) );
-            table.addCell( getTextCell( element.getDescription() ) );
-        }
-
-        /* TODO fixme
-        if ( StringUtils.trimToNull( element.getType() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "value_type" ) ) );
-            table.addCell( getTextCell( i18n.getString( getType().get( element.getType() ) ) ) );
-        }
-        */
-        if ( StringUtils.trimToNull( element.getAggregationOperator() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "aggregation_operator" ) ) );
-            table.addCell( getTextCell( i18n.getString( getAggregationOperator().get( element.getAggregationOperator() ) ) ) );
-        }
-
-        for ( AttributeValue value : element.getAttributeValues() )
-        {
-            table.addCell( getItalicCell( value.getAttribute().getName() ) );
-            table.addCell( getTextCell( value.getValue() ) );
-        }
-
-        table.addCell( getEmptyCell( 2, 30 ) );
-
-        return table;
-    }
-
-    /**
-     * Creates a table with the given indicator
-     *
-     * @param indicator The indicator
-     * @param i18n i18n object
-     * @param expressionService The expression service
-     * @param HEADER3 The header3 font
-     * @param ITALIC The italic font
-     * @param TEXT The text font
-     * @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 printIndicator( Indicator indicator, I18n i18n, ExpressionService expressionService,
-        boolean keepTogether, float... columnWidths )
-    {
-        PdfPTable table = getPdfPTable( keepTogether, columnWidths );
-
-        table.addCell( getHeaderCell( indicator.getName(), 2 ) );
-
-        table.addCell( getEmptyCell( 2, 15 ) );
-
-        table.addCell( getItalicCell( i18n.getString( "short_name" ) ) );
-        table.addCell( getTextCell( indicator.getShortName() ) );
-
-        if ( StringUtils.trimToNull( indicator.getCode() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "code" ) ) );
-            table.addCell( getTextCell( indicator.getCode() ) );
-        }
-        if ( StringUtils.trimToNull( indicator.getDescription() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "description" ) ) );
-            table.addCell( getTextCell( indicator.getDescription() ) );
-        }
-
-        table.addCell( getItalicCell( i18n.getString( "annualized" ) ) );
-        table.addCell( getTextCell( i18n.getString( getBoolean().get( indicator.isAnnualized() ) ) ) );
-
-        table.addCell( getItalicCell( i18n.getString( "indicator_type" ) ) );
-        table.addCell( getTextCell( indicator.getIndicatorType().getName() ) );
-
-        table.addCell( getItalicCell( i18n.getString( "numerator_description" ) ) );
-        table.addCell( getTextCell( indicator.getNumeratorDescription() ) );
-
-        table.addCell( getItalicCell( i18n.getString( "numerator_formula" ) ) );
-        table.addCell( getTextCell( expressionService.getExpressionDescription( indicator.getNumerator() ) ) );
-
-        table.addCell( getItalicCell( i18n.getString( "denominator_description" ) ) );
-        table.addCell( getTextCell( indicator.getDenominatorDescription() ) );
-
-        table.addCell( getItalicCell( i18n.getString( "denominator_formula" ) ) );
-        table.addCell( getTextCell( expressionService.getExpressionDescription( indicator.getDenominator() ) ) );
-
-        for ( AttributeValue value : indicator.getAttributeValues() )
-        {
-            table.addCell( getItalicCell( value.getAttribute().getName() ) );
-            table.addCell( getTextCell( value.getValue() ) );
-        }
-
-        table.addCell( getEmptyCell( 2, 30 ) );
-
-        return table;
-    }
-
-    /**
-     * Creates a table with the given unit
-     *
-     * @param unit The organization unit
-     * @param i18n i18n object
-     * @param format
-     * @param HEADER3 The header3 font
-     * @param ITALIC The italic font
-     * @param TEXT The text font
-     * @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 printOrganisationUnit( OrganisationUnit unit, I18n i18n, I18nFormat format,
-        boolean keepTogether, float... columnWidths )
-    {
-        PdfPTable table = getPdfPTable( keepTogether, columnWidths );
-
-        table.addCell( getHeaderCell( unit.getName(), 2 ) );
-
-        table.addCell( getEmptyCell( 2, 15 ) );
-
-        table.addCell( getItalicCell( i18n.getString( "short_name" ) ) );
-        table.addCell( getTextCell( unit.getShortName() ) );
-
-        if ( StringUtils.trimToNull( unit.getCode() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "code" ) ) );
-            table.addCell( getTextCell( unit.getCode() ) );
-        }
-
-        table.addCell( getItalicCell( i18n.getString( "opening_date" ) ) );
-        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( format.formatDate( unit.getClosedDate() ) ) );
-        }
-
-        table.addCell( getItalicCell( i18n.getString( "active" ) ) );
-
-        if ( StringUtils.trimToNull( unit.getComment() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "comment" ) ) );
-            table.addCell( getTextCell( unit.getComment() ) );
-        }
-
-        for ( AttributeValue value : unit.getAttributeValues() )
-        {
-            table.addCell( getItalicCell( value.getAttribute().getName() ) );
-            table.addCell( getTextCell( value.getValue() ) );
-        }
-
-        table.addCell( getEmptyCell( 2, 30 ) );
-
-        return table;
-    }
-
-    /**
-     * 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 ( StringUtils.trimToNull( user.getEmail() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "email" ) ) );
-            table.addCell( getTextCell( user.getEmail() ) );
-        }
-
-        if ( StringUtils.trimToNull( 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 = temp.substring( 0, temp.isEmpty() ? 0 : temp.length() - 1 );
-
-        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 = temp.substring( 0, temp.isEmpty() ? 0 : temp.length() - 1 );
-
-        table.addCell( getItalicCell( i18n.getString( "roles" ) ) );
-        table.addCell( getTextCell( temp ) );
-
-        for ( AttributeValue value : user.getAttributeValues() )
-        {
-            table.addCell( getItalicCell( value.getAttribute().getName() ) );
-            table.addCell( getTextCell( value.getValue() ) );
-        }
-
-        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
-     * @param HEADER3 The header3 font
-     * @param ITALIC The italic font
-     * @param TEXT The text font
-     * @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 printValidationRule( ValidationRule validationRule, I18n i18n,
-        ExpressionService expressionService, boolean keepTogether, float... columnWidths )
-    {
-        PdfPTable table = getPdfPTable( keepTogether, columnWidths );
-
-        table.addCell( getHeaderCell( validationRule.getName(), 2 ) );
-
-        table.addCell( getEmptyCell( 2, 15 ) );
-
-        if ( StringUtils.trimToNull( validationRule.getDescription() ) != null )
-        {
-            table.addCell( getItalicCell( i18n.getString( "description" ) ) );
-            table.addCell( getTextCell( validationRule.getDescription() ) );
-        }
-
-        table.addCell( getItalicCell( i18n.getString( "operator" ) ) );
-        table.addCell( getTextCell( i18n.getString( validationRule.getOperator().toString() ) ) );
-
-        table.addCell( getItalicCell( i18n.getString( "left_side_of_expression" ) ) );
-        table.addCell( getTextCell( expressionService.getExpressionDescription( validationRule.getLeftSide()
-            .getExpression() ) ) );
-
-        table.addCell( getItalicCell( i18n.getString( "left_side_description" ) ) );
-        table.addCell( getTextCell( validationRule.getLeftSide().getDescription() ) );
-
-        table.addCell( getItalicCell( i18n.getString( "right_side_of_expression" ) ) );
-        table.addCell( getTextCell( expressionService.getExpressionDescription( validationRule.getRightSide()
-            .getExpression() ) ) );
-
-        table.addCell( getItalicCell( i18n.getString( "right_side_description" ) ) );
-        table.addCell( getTextCell( validationRule.getRightSide().getDescription() ) );
-
-        table.addCell( getItalicCell( i18n.getString( "period_type" ) ) );
-        table.addCell( getTextCell( i18n.getString( validationRule.getPeriodType().getName() ) ) );
-
-        table.addCell( getEmptyCell( 2, 30 ) );
-
-        return table;
-    }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    private static Map<Boolean, String> getBoolean()
-    {
-        Map<Boolean, String> map = new HashMap<>();
-        map.put( true, "yes" );
-        map.put( false, "no" );
-        return map;
-    }
-
-    private static Map<String, String> getAggregationOperator()
-    {
-        Map<String, String> map = new HashMap<>();
-        map.put( DataElement.AGGREGATION_OPERATOR_SUM, "sum" );
-        map.put( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM, "average" );
-        map.put( DataElement.AGGREGATION_OPERATOR_COUNT, "count" );
-        return map;
-    }
 }