dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39296
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19914: minor fixes, remove more usage of type/numbertype/texttype
------------------------------------------------------------
revno: 19914
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-09-01 12:02:13 +0700
message:
minor fixes, remove more usage of type/numbertype/texttype
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java
dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtilsImpl.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-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java 2015-07-08 05:02:25 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java 2015-09-01 05:02:13 +0000
@@ -313,7 +313,6 @@
private ZipOutputStream getCSVDataExportField( ZipOutputStream out, DeflatedDataValue value )
{
-
String dataElementType = dataElementService.getDataElement( value.getDataElementId() ).getType();
try
@@ -327,7 +326,6 @@
out.write( SEPARATOR_B );
out.write( SEPARATOR_B );
}
-
else if ( dataElementType.equals( DataElement.VALUE_TYPE_BOOL ) )
{
out.write( SEPARATOR_B );
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java 2015-02-19 09:18:17 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/dataentry/action/SaveSectionFormAction.java 2015-09-01 05:02:13 +0000
@@ -28,18 +28,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionContext;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.struts2.StrutsStatics;
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -64,8 +58,13 @@
import org.hisp.dhis.user.CurrentUserService;
import org.hisp.dhis.util.ContextUtils;
-import com.opensymphony.xwork2.Action;
-import com.opensymphony.xwork2.ActionContext;
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
/**
* @author mortenoh
@@ -301,7 +300,7 @@
for ( String key : parameterMap.keySet() )
{
- if ( key.startsWith( "DE" ) && key.indexOf( "OC" ) != -1 )
+ if ( key.startsWith( "DE" ) && key.contains( "OC" ) )
{
String[] splitKey = key.split( "OC" );
Integer dataElementId = Integer.parseInt( splitKey[0].substring( 2 ) );
@@ -309,34 +308,30 @@
String value = parameterMap.get( key );
DataElement dataElement = dataElementService.getDataElement( dataElementId );
- DataElementCategoryOptionCombo categoryOptionCombo = categoryService
- .getDataElementCategoryOptionCombo( optionComboId );
-
- DataValue dataValue = dataValueService
- .getDataValue( dataElement, period, organisationUnit, categoryOptionCombo );
+ DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDataElementCategoryOptionCombo( optionComboId );
+ DataValue dataValue = dataValueService.getDataValue( dataElement, period, organisationUnit, categoryOptionCombo );
value = value.trim();
- Boolean valueIsEmpty = (value == null || value.length() == 0);
+ Boolean valueIsEmpty = value.length() == 0;
// validate types
Boolean correctType = true;
- String type = dataElement.getType();
- String numberType = dataElement.getNumberType();
+ ValueType valueType = dataElement.getValueType();
if ( !valueIsEmpty )
{
- if ( type.equals( DataElement.VALUE_TYPE_STRING ) )
+ if ( valueType.isText() )
{
}
- else if ( type.equals( DataElement.VALUE_TYPE_BOOL ) )
+ else if ( ValueType.BOOLEAN == valueType )
{
- if ( !valueIsEmpty && !ValueUtils.isBoolean( value ) )
+ if ( !ValueUtils.isBoolean( value ) )
{
correctType = false;
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_boolean" ) );
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_DATE ) )
+ else if ( ValueType.DATE == valueType )
{
if ( !ValueUtils.isDate( value ) )
{
@@ -344,8 +339,7 @@
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_date" ) );
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT )
- && numberType.equals( DataElement.VALUE_TYPE_NUMBER ) )
+ else if ( ValueType.NUMBER == valueType )
{
if ( !MathUtils.isNumeric( value ) )
{
@@ -353,8 +347,7 @@
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_number" ) );
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT )
- && numberType.equals( DataElement.VALUE_TYPE_INT ) )
+ else if ( ValueType.INTEGER == valueType )
{
if ( !MathUtils.isInteger( value ) )
{
@@ -362,8 +355,7 @@
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_integer" ) );
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT )
- && numberType.equals( DataElement.VALUE_TYPE_POSITIVE_INT ) )
+ else if ( ValueType.INTEGER_POSITIVE == valueType )
{
if ( !MathUtils.isPositiveInteger( value ) )
{
@@ -371,8 +363,7 @@
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_positive_integer" ) );
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT )
- && numberType.equals( DataElement.VALUE_TYPE_NEGATIVE_INT ) )
+ else if ( ValueType.INTEGER_NEGATIVE == valueType )
{
if ( !MathUtils.isNegativeInteger( value ) )
{
@@ -380,8 +371,7 @@
typeViolations.put( key, "\"" + value + "\"" + " " + i18n.getString( "is_invalid_negative_integer" ) );
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT)
- && numberType.equals( DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT ) )
+ else if ( ValueType.INTEGER_ZERO_OR_POSITIVE == valueType )
{
if ( !MathUtils.isZeroOrPositiveInteger( value ) )
{
@@ -427,7 +417,7 @@
}
DataElementCategoryOptionCombo optionCombo = categoryService.getDefaultDataElementCategoryOptionCombo(); //TODO
-
+
CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet, period,
organisationUnit, optionCombo );
=== modified file 'dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtilsImpl.java'
--- dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtilsImpl.java 2015-01-17 07:41:26 +0000
+++ dhis-2/dhis-web/dhis-web-light/src/main/java/org/hisp/dhis/light/utils/NamebasedUtilsImpl.java 2015-09-01 05:02:13 +0000
@@ -28,11 +28,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
+import org.hisp.dhis.common.ValueType;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.mobile.service.ModelMapping;
import org.hisp.dhis.program.Program;
@@ -43,27 +39,32 @@
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.system.util.MathUtils;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
public class NamebasedUtilsImpl
implements NamebasedUtils
{
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
-
+
private ProgramService programService;
public void setProgramService( ProgramService programService )
{
this.programService = programService;
}
-
+
private ProgramStageService programStageService;
-
+
public void setProgramStageService( ProgramStageService programStageService )
{
this.programStageService = programStageService;
}
-
+
@Override
public ProgramStage getProgramStage( int programId, int programStageId )
{
@@ -80,59 +81,58 @@
}
return null;
}
-
+
@Override
public String getTypeViolation( DataElement dataElement, String value )
{
- String type = dataElement.getType();
- String numberType = dataElement.getNumberType();
+ ValueType valueType = dataElement.getValueType();
- if ( type.equals( DataElement.VALUE_TYPE_STRING ) )
+ if ( valueType.isText() )
{
}
- else if ( type.equals( DataElement.VALUE_TYPE_BOOL ) )
+ else if ( ValueType.BOOLEAN == valueType )
{
if ( !ValueUtils.isBoolean( value ) )
{
return "is_invalid_boolean";
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_DATE ) )
+ else if ( ValueType.DATE == valueType )
{
if ( !ValueUtils.isDate( value ) )
{
return "is_invalid_date";
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_NUMBER ) )
+ else if ( ValueType.NUMBER == valueType )
{
if ( !MathUtils.isNumeric( value ) )
{
return "is_invalid_number";
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_INT ) )
+ else if ( ValueType.INTEGER == valueType )
{
if ( !MathUtils.isInteger( value ) )
{
return "is_invalid_integer";
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_POSITIVE_INT ) )
+ else if ( ValueType.INTEGER_POSITIVE == valueType )
{
if ( !MathUtils.isPositiveInteger( value ) )
{
return "is_invalid_positive_integer";
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_NEGATIVE_INT ) )
+ else if ( ValueType.INTEGER_NEGATIVE == valueType )
{
if ( !MathUtils.isNegativeInteger( value ) )
{
return "is_invalid_negative_integer";
}
}
- else if ( type.equals( DataElement.VALUE_TYPE_INT ) && numberType.equals( DataElement.VALUE_TYPE_ZERO_OR_POSITIVE_INT ) )
+ else if ( ValueType.INTEGER_ZERO_OR_POSITIVE == valueType )
{
if ( !MathUtils.isZeroOrPositiveInteger( value ) )
{
@@ -155,21 +155,21 @@
return null;
}
-
+
@Override
public List<org.hisp.dhis.api.mobile.model.DataElement> transformDataElementsToMobileModel( Integer programStageId )
{
ProgramStage programStage = programStageService.getProgramStage( programStageId );
-
+
List<org.hisp.dhis.api.mobile.model.DataElement> des = new ArrayList<>();
- List<ProgramStageDataElement> programStageDataElements = new ArrayList<>(programStage.getProgramStageDataElements());
+ List<ProgramStageDataElement> programStageDataElements = new ArrayList<>( programStage.getProgramStageDataElements() );
des = transformDataElementsToMobileModel( programStageDataElements );
-
+
return des;
}
-
+
@Override
public List<org.hisp.dhis.api.mobile.model.DataElement> transformDataElementsToMobileModel( List<ProgramStageDataElement> programStageDataElements )
{