dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35677
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18256: Data import, validation of stored by field
------------------------------------------------------------
revno: 18256
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-02-13 14:17:36 +0100
message:
Data import, validation of stored by field
modified:
dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.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-services/dhis-service-core/src/main/resources/i18n_global.properties'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties 2014-12-17 14:17:16 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/i18n_global.properties 2015-02-13 13:17:36 +0000
@@ -908,6 +908,8 @@
value_not_bool=Data value is not a boolean
value_not_true_only=Data value is not true
value_not_valid_date=Data value is not a valid date
+stored_by_length_greater_than_max_length=Stored by is greater than max length
+comment_length_greater_than_max_length=Comment is greater than max length
#-- calendars -----------------------------------------------------------------#
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java 2015-02-13 13:17:36 +0000
@@ -805,14 +805,21 @@
internalValue.setAttributeOptionCombo( attrOptionCombo );
internalValue.setValue( trimToNull( dataValue.getValue() ) );
+ String storedByValid = ValidationUtils.storedByIsValid( dataValue.getStoredBy() );
+
if ( dataValue.getStoredBy() == null || dataValue.getStoredBy().trim().isEmpty() )
{
internalValue.setStoredBy( currentUser );
}
- else
+ else if ( storedByValid == null )
{
internalValue.setStoredBy( dataValue.getStoredBy() );
}
+ else
+ {
+ summary.getConflicts().add( new ImportConflict( dataValue.getStoredBy(), i18n.getString( storedByValid ) ) );
+ continue;
+ }
internalValue.setCreated( dataValue.hasCreated() ? parseDate( dataValue.getCreated() ) : now );
internalValue.setLastUpdated( dataValue.hasLastUpdated() ? parseDate( dataValue.getLastUpdated() ) : now );
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ValidationUtils.java 2015-02-13 13:17:36 +0000
@@ -374,6 +374,32 @@
}
/**
+ * Checks if the given stored by value is valid. Returns null if valid and a string
+ * if invalid, possible values are:
+ * </p>
+ * <ul>
+ * <li>stored_by_length_greater_than_max_length</li>
+ * </ul>
+ *
+ * @param storedBy the stored by value.
+ * @return null if the stored by value is valid, a string if not.
+ */
+ public static String storedByIsValid( String storedBy )
+ {
+ if ( storedBy == null || storedBy.trim().isEmpty() )
+ {
+ return null;
+ }
+
+ if ( storedBy.length() > 31 )
+ {
+ return "stored_by_length_greater_than_max_length";
+ }
+
+ return null;
+ }
+
+ /**
* Checks to see if given parameter is a valid hex color string (#xxx and #xxxxxx, xxx, xxxxxx).
*
* @param value Value to check against