dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33853
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17342: Data set report, format fix
------------------------------------------------------------
revno: 17342
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-11-02 21:28:32 -0500
message:
Data set report, format fix
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.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-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java 2014-11-03 00:24:32 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java 2014-11-03 02:28:32 +0000
@@ -50,6 +50,7 @@
{
private static final DecimalFormat FORMAT_VALUE = new DecimalFormat( "#.#" ); // Fixed for now
private static final String EMPTY = "";
+ private static final String NAN = "NaN";
private static final String INVALID_DATE = "Invalid date format";
@@ -269,7 +270,8 @@
}
/**
* Formats value. Returns empty string if value is null. Returns NaN if value
- * is not a number.
+ * is not a number. Return a formatted string if value is an instance of Number,
+ * if not returns the value as a string.
*
* @param value the value to format.
*/
@@ -280,11 +282,18 @@
return EMPTY;
}
- try
+ if ( value instanceof Number )
{
- return FORMAT_VALUE.format( value );
+ try
+ {
+ return FORMAT_VALUE.format( value );
+ }
+ catch ( IllegalArgumentException ex )
+ {
+ return NAN;
+ }
}
- catch ( IllegalArgumentException ex )
+ else
{
return String.valueOf( value );
}
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2014-11-03 00:24:32 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/datasetreport/impl/DefaultDataSetReportService.java 2014-11-03 02:28:32 +0000
@@ -28,13 +28,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.apache.commons.lang.StringUtils.trimToEmpty;
import static org.hisp.dhis.dataentryform.DataEntryFormService.DATAELEMENT_TOTAL_PATTERN;
import static org.hisp.dhis.dataentryform.DataEntryFormService.IDENTIFIER_PATTERN;
import static org.hisp.dhis.dataentryform.DataEntryFormService.INDICATOR_PATTERN;
import static org.hisp.dhis.dataentryform.DataEntryFormService.INPUT_PATTERN;
import static org.hisp.dhis.datasetreport.DataSetReportStore.SEPARATOR;
-import static org.hisp.dhis.system.util.MathUtils.getRoundedObject;
import java.util.ArrayList;
import java.util.Collections;
@@ -323,7 +321,7 @@
Object dataValue = dataValues.get( dataElementId + SEPARATOR + optionComboId );
- String value = "<span class=\"val\" data-de=\"" + dataElementId + "\" data-co=\"" + optionComboId + "\">" + trimToEmpty( String.valueOf( getRoundedObject( dataValue ) ) ) + "</span>";
+ String value = "<span class=\"val\" data-de=\"" + dataElementId + "\" data-co=\"" + optionComboId + "\">" + format.formatValue( dataValue ) + "</span>";
inputMatcher.appendReplacement( buffer, value );
}
@@ -333,7 +331,7 @@
Object dataValue = dataValues.get( dataElementId );
- inputMatcher.appendReplacement( buffer, trimToEmpty( String.valueOf( getRoundedObject( dataValue ) ) ) );
+ inputMatcher.appendReplacement( buffer, format.formatValue( dataValue ) );
}
else if ( indicatorMatcher.find() && indicatorMatcher.groupCount() > 0 )
{
@@ -341,7 +339,7 @@
Object indicatorValue = indicatorValues.get( indicatorId );
- inputMatcher.appendReplacement( buffer, trimToEmpty( String.valueOf( getRoundedObject( indicatorValue ) ) ) );
+ inputMatcher.appendReplacement( buffer, format.formatValue( indicatorValue ) );
}
}