dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #28199
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14071: CSV import, taking max char length into account
------------------------------------------------------------
revno: 14071
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-02-18 14:11:50 +0100
message:
CSV import, taking max char length into account
modified:
dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.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/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2014-02-18 11:58:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/organisationunit/hibernate/OrganisationUnit.hbm.xml 2014-02-18 13:11:50 +0000
@@ -40,7 +40,7 @@
<property name="comment" type="text" />
- <property name="featureType" />
+ <property name="featureType" length="50" />
<property name="coordinates" type="text" />
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java 2014-02-18 11:58:08 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/CsvObjectUtils.java 2014-02-18 13:11:50 +0000
@@ -133,17 +133,17 @@
{
DataElement object = new DataElement();
setIdentifiableObject( object, values );
- object.setShortName( getSafe( values, 3, StringUtils.substring( object.getName(), 0, 50 ) ) );
- object.setDescription( getSafe( values, 4, null ) );
- object.setFormName( getSafe( values, 5, null ) );
+ object.setShortName( getSafe( values, 3, object.getName(), 50 ) );
+ object.setDescription( getSafe( values, 4, null, null ) );
+ object.setFormName( getSafe( values, 5, null, 230 ) );
object.setActive( true );
- object.setDomainType( getSafe( values, 6, DataElement.DOMAIN_TYPE_AGGREGATE ) );
- object.setType( getSafe( values, 7, DataElement.VALUE_TYPE_INT ) );
- object.setNumberType( getSafe( values, 8, DataElement.VALUE_TYPE_NUMBER ) );
- object.setTextType( getSafe( values, 9, null ) );
- object.setAggregationOperator( getSafe( values, 10, DataElement.AGGREGATION_OPERATOR_SUM ) );
- object.setUrl( getSafe( values, 11, null ) );
- object.setZeroIsSignificant( Boolean.valueOf( getSafe( values, 12, "false" ) ) );
+ object.setDomainType( getSafe( values, 6, DataElement.DOMAIN_TYPE_AGGREGATE, 16 ) );
+ object.setType( getSafe( values, 7, DataElement.VALUE_TYPE_INT, 16 ) );
+ object.setNumberType( getSafe( values, 8, DataElement.VALUE_TYPE_NUMBER, 16 ) );
+ object.setTextType( getSafe( values, 9, null, 16 ) );
+ object.setAggregationOperator( getSafe( values, 10, DataElement.AGGREGATION_OPERATOR_SUM, 16 ) );
+ object.setUrl( getSafe( values, 11, null, 255 ) );
+ object.setZeroIsSignificant( Boolean.valueOf( getSafe( values, 12, "false", null ) ) );
list.add( object );
}
@@ -165,20 +165,20 @@
{
OrganisationUnit object = new OrganisationUnit();
setIdentifiableObject( object, values );
- object.setShortName( getSafe( values, 3, StringUtils.substring( object.getName(), 0, 50 ) ) );
- object.setDescription( getSafe( values, 4, null ) );
- object.setUuid( getSafe( values, 5, null ) );
- object.setOpeningDate( getMediumDate( getSafe( values, 6, "1970-01-01" ) ) );
- object.setClosedDate( getMediumDate( getSafe( values, 7, "1970-01-01" ) ) );
- object.setActive( true);
- object.setComment( getSafe( values, 8, null ) );
- object.setFeatureType( getSafe( values, 9, null ) );
- object.setCoordinates( getSafe( values, 10, null ) );
- object.setUrl( getSafe( values, 11, null ) );
- object.setContactPerson( getSafe( values, 12, null ) );
- object.setAddress( getSafe( values, 13, null ) );
- object.setEmail( getSafe( values, 14, null ) );
- object.setPhoneNumber( getSafe( values, 15, null ) );
+ object.setShortName( getSafe( values, 3, object.getName(), 50 ) );
+ object.setDescription( getSafe( values, 4, null, null ) );
+ object.setUuid( getSafe( values, 5, null, 36 ) );
+ object.setOpeningDate( getMediumDate( getSafe( values, 6, "1970-01-01", null ) ) );
+ object.setClosedDate( getMediumDate( getSafe( values, 7, "1970-01-01", null ) ) );
+ object.setActive( true );
+ object.setComment( getSafe( values, 8, null, null ) );
+ object.setFeatureType( getSafe( values, 9, null, 50 ) );
+ object.setCoordinates( getSafe( values, 10, null, null ) );
+ object.setUrl( getSafe( values, 11, null, 255 ) );
+ object.setContactPerson( getSafe( values, 12, null, 255 ) );
+ object.setAddress( getSafe( values, 13, null, 255 ) );
+ object.setEmail( getSafe( values, 14, null, 150 ) );
+ object.setPhoneNumber( getSafe( values, 15, null, 150 ) );
list.add( object );
}
@@ -189,20 +189,37 @@
private static void setIdentifiableObject( BaseIdentifiableObject object, String[] values )
{
- object.setName( getSafe( values, 0, null ) );
- object.setUid( getSafe( values, 1, CodeGenerator.generateCode() ) );
- object.setCode( getSafe( values, 2, null ) );
+ object.setName( getSafe( values, 0, null, 230 ) );
+ object.setUid( getSafe( values, 1, CodeGenerator.generateCode(), 11 ) );
+ object.setCode( getSafe( values, 2, null, 50 ) );
}
- private static final String getSafe( String[] values, int index, String defaultValue )
+ /**
+ * Returns a string from the given array avoiding exceptions.
+ *
+ * @param values the string array.
+ * @param index the array index of the string to get.
+ * @param defaultValue the default value in case index is out of bounds.
+ * @param max the max number of characters to return for the string.
+ */
+ private static String getSafe( String[] values, int index, String defaultValue, Integer max )
{
+ String string = null;
+
if ( values == null || index < 0 || index >= values.length )
{
- return defaultValue;
- }
-
- String value = values[index];
-
- return value != null ? value : defaultValue;
+ string = defaultValue;
+ }
+ else
+ {
+ string = values[index];
+ }
+
+ if ( string != null )
+ {
+ return max != null ? StringUtils.substring( string, 0, max ) : string;
+ }
+
+ return null;
}
}