dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #19960
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8933: Added timestamp to report downloads
------------------------------------------------------------
revno: 8933
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-11-07 15:31:41 +0300
message:
Added timestamp to report downloads
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java
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/grid/GridUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2012-10-18 21:27:32 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/GridUtils.java 2012-11-07 12:31:41 +0000
@@ -69,6 +69,7 @@
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
import org.hisp.dhis.system.util.CodecUtils;
+import org.hisp.dhis.system.util.DateUtils;
import org.hisp.dhis.system.util.Encoder;
import org.hisp.dhis.system.util.ExcelUtils;
import org.hisp.dhis.system.util.MathUtils;
@@ -103,7 +104,7 @@
private static final WritableCellFormat XLS_FORMAT_TTTLE = new WritableCellFormat( new WritableFont(
WritableFont.TAHOMA, 13, WritableFont.NO_BOLD, false ) );
- private static final WritableCellFormat XLS_FORMAT_SUBTTTLE = new WritableCellFormat( new WritableFont(
+ private static final WritableCellFormat XLS_FORMAT_SUBTITLE = new WritableCellFormat( new WritableFont(
WritableFont.TAHOMA, 12, WritableFont.NO_BOLD, false ) );
private static final WritableCellFormat XLS_FORMAT_LABEL = new WritableCellFormat( new WritableFont(
@@ -146,7 +147,9 @@
Document document = openDocument( out );
toPdfInternal( grid, document, 0F );
-
+
+ addPdfTimestamp( document, true );
+
closeDocument( document );
}
}
@@ -165,6 +168,8 @@
toPdfInternal( grid, document, 40F );
}
+ addPdfTimestamp( document, false );
+
closeDocument( document );
}
}
@@ -208,6 +213,14 @@
addTableToDocument( document, table );
}
+
+ private static void addPdfTimestamp( Document document, boolean paddingTop )
+ {
+ PdfPTable table = new PdfPTable(1);
+ table.addCell( getEmptyCell( 1, ( paddingTop ? 30 : 0 ) ) );
+ table.addCell( getTextCell( getGeneratedString() ) );
+ addTableToDocument( document, table );
+ }
/**
* Writes a XLS (Excel workbook) representation of the given list of Grids to the given OutputStream.
@@ -264,12 +277,11 @@
rowNumber++;
- if ( StringUtils.isNotEmpty( grid.getSubtitle() ) )
- {
- sheet.addCell( new Label( 0, rowNumber++, grid.getSubtitle(), XLS_FORMAT_SUBTTTLE ) );
-
- rowNumber++;
- }
+ String subTitle = StringUtils.isNotEmpty( grid.getSubtitle() ) ?
+ ( grid.getSubtitle() + " (" + getGeneratedString() + ")" ) : grid.getSubtitle();
+
+ sheet.addCell( new Label( 0, rowNumber++, subTitle, XLS_FORMAT_SUBTITLE ) );
+ rowNumber++;
for ( GridHeader header : grid.getVisibleHeaders() )
{
@@ -299,7 +311,7 @@
rowNumber++;
}
}
-
+
/**
* Writes a CSV representation of the given Grid to the given OutputStream.
*/
@@ -566,7 +578,15 @@
// -------------------------------------------------------------------------
// Supportive methods
// -------------------------------------------------------------------------
-
+
+ /**
+ * Returns a string explaning when the grid was generated.
+ */
+ private static String getGeneratedString()
+ {
+ return "Generated: " + DateUtils.getMediumDateString();
+ }
+
/**
* Render using Velocity.
*/
=== 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 2012-10-18 13:04:28 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/PDFUtils.java 2012-11-07 12:31:41 +0000
@@ -191,10 +191,10 @@
* @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 verticalAlign The vertical alignment of the text in the cell.
+ * @param horizontalAlign The vertical alignment of the text in the cell.
* @return A PdfCell.
*/
- public static PdfPCell getCell( String text, int colspan, Font font, int verticalAlign )
+ public static PdfPCell getCell( String text, int colspan, Font font, int horizontalAlign )
{
Paragraph paragraph = new Paragraph( text, font );
@@ -203,7 +203,7 @@
cell.setColspan( colspan );
cell.setBorder( 0 );
cell.setMinimumHeight( 15 );
- cell.setHorizontalAlignment( verticalAlign );
+ cell.setHorizontalAlignment( horizontalAlign );
return cell;
}