dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #02318
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 781: Made the data entry screen manager a little more object oriented.
------------------------------------------------------------
revno: 781
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-09-28 00:30:31 +0200
message:
Made the data entry screen manager a little more object oriented.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValue.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java
dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.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/customvalue/CustomValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValue.java 2009-07-05 20:32:22 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/customvalue/CustomValue.java 2009-09-27 22:30:31 +0000
@@ -66,85 +66,63 @@
*/
private String customValue;
+ // -------------------------------------------------------------------------
+ // Constructors
+ // -------------------------------------------------------------------------
+
public CustomValue()
{
}
- /**
- * @return the id
- */
+ // -------------------------------------------------------------------------
+ // Getters and setters
+ // -------------------------------------------------------------------------
+
public int getId()
{
return id;
}
- /**
- * @param id the id to set
- */
public void setId( int id )
{
this.id = id;
}
- /**
- * @return the dataSet
- */
public DataSet getDataSet()
{
return dataSet;
}
- /**
- * @param dataSet the dataSet to set
- */
public void setDataSet( DataSet dataSet )
{
this.dataSet = dataSet;
}
- /**
- * @return the dataElement
- */
public DataElement getDataElement()
{
return dataElement;
}
- /**
- * @param dataElement the dataElement to set
- */
public void setDataElement( DataElement dataElement )
{
this.dataElement = dataElement;
}
- /**
- * @return the optionCombo
- */
public DataElementCategoryOptionCombo getOptionCombo()
{
return optionCombo;
}
- /**
- * @param optionCombo the optionCombo to set
- */
public void setOptionCombo( DataElementCategoryOptionCombo optionCombo )
{
this.optionCombo = optionCombo;
}
- /**
- * @return the customValue
- */
public String getCustomValue()
{
return customValue;
}
- /**
- * @param customValue the customValue to set
- */
public void setCustomValue( String customValue )
{
this.customValue = customValue;
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java 2009-04-22 15:28:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/datavalue/DataValue.java 2009-09-27 22:30:31 +0000
@@ -42,6 +42,9 @@
public class DataValue
implements Serializable
{
+ public static final String TRUE = "true";
+ public static final String FALSE = "false";
+
/**
* Part of the DataValue's composite ID
*/
=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java 2009-09-27 20:13:13 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java 2009-09-27 22:30:31 +0000
@@ -67,8 +67,8 @@
implements DataEntryScreenManager
{
private static final String DEFAULT_FORM = "defaultform";
-
private static final String MULTI_DIMENSIONAL_FORM = "multidimensionalform";
+ private static final String EMPTY = "";
// -------------------------------------------------------------------------
// Dependencies
@@ -193,7 +193,6 @@
cde = (CalculatedDataElement) dataElement;
calculatedDataElementIds.add( cde.getId() );
-
}
}
@@ -229,7 +228,6 @@
List<Section> sections = (List<Section>) sectionService.getSectionByDataSet( dataSet );
return sections.size() != 0;
-
}
public Map<CalculatedDataElement, Integer> populateValuesForCalculatedDataElements(
@@ -379,14 +377,7 @@
if ( cde.isSaved() )
{
- for ( DataValue dv : dataValues )
- {
- if ( dv.getDataElement().getId() == dataElementId )
- {
- dataElementValue = dv.getValue();
- break;
- }
- }
+ dataElementValue = getValue( dataValues, dataElementId );
}
else
{
@@ -395,31 +386,16 @@
}
else
{
- for ( DataValue dv : dataValues )
- {
- if ( dv.getDataElement().getId() == dataElementId )
- {
- dataElementValue = dv.getValue();
- break;
- }
- }
+ dataElementValue = getValue( dataValues, dataElementId );
}
// -------------------------------------------------------------
// Insert value of data element in output code
// -------------------------------------------------------------
- int count = 0;
+ boolean customValueExists = customValuesExists( customValues, dataElementId, optionComboId );
- for ( CustomValue customValue : customValues )
- {
- if ( dataElementId == customValue.getDataElement().getId() && optionComboId == customValue.getOptionCombo().getId() )
- {
- count += 1;
- }
- }
-
- if ( dataElement.getType().equals( TYPE_BOOL ) || (dataElement.getType().equals( TYPE_STRING ) && count > 0) )
+ if ( dataElement.getType().equals( TYPE_BOOL ) || (dataElement.getType().equals( TYPE_STRING ) && customValueExists ) )
{
dataElementCode = dataElementCode.replace( "input", "select" );
dataElementCode = dataElementCode.replaceAll( "value=\".*?\"", "" );
@@ -440,7 +416,7 @@
}
// -------------------------------------------------------------
- // MIN-MAX Values
+ // Min-max values
// -------------------------------------------------------------
MinMaxDataElement minMaxDataElement = minMaxMap.get( dataElement.getId() );
@@ -460,7 +436,7 @@
dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" );
// -------------------------------------------------------------
- // Insert Title Information - DataElement id,name,type,min,max
+ // Insert title information - Data element id, name, type, min, max
// -------------------------------------------------------------
if ( dataElementCode.contains( "title=\"\"" ) )
@@ -509,7 +485,7 @@
appendCode += "</select>";
}
- else if ( dataElement.getType().equals( TYPE_STRING ) && count > 0 )
+ else if ( dataElement.getType().equals( TYPE_STRING ) && customValueExists )
{
appendCode += jsCodeForCombos;
@@ -671,15 +647,7 @@
if ( cde.isSaved() )
{
- for ( DataValue dv : dataValues )
- {
- if ( dv.getDataElement().getId() == dataElementId
- && dv.getOptionCombo().getId() == optionComboId )
- {
- dataElementValue = dv.getValue();
- break;
- }
- }
+ dataElementValue = getValue( dataValues, dataElementId, optionComboId );
}
else
{
@@ -688,31 +656,16 @@
}
else
{
- for ( DataValue dv : dataValues )
- {
- if ( dv.getDataElement().getId() == dataElementId && dv.getOptionCombo().getId() == optionComboId )
- {
- dataElementValue = dv.getValue();
- break;
- }
- }
+ dataElementValue = getValue( dataValues, dataElementId, optionComboId );
}
// -------------------------------------------------------------
// Insert value of data element in output code
// -------------------------------------------------------------
- int count = 0;
+ boolean customValueExists = customValuesExists( customValues, dataElementId, optionComboId );
- for ( CustomValue customValue : customValues )
- {
- if ( dataElementId == customValue.getDataElement().getId() && optionComboId == customValue.getOptionCombo().getId() )
- {
- count += 1;
- }
- }
-
- if ( dataElement.getType().equals( DataElement.TYPE_BOOL ) || (dataElement.getType().equals( TYPE_STRING ) && count > 0) )
+ if ( dataElement.getType().equals( DataElement.TYPE_BOOL ) || (dataElement.getType().equals( TYPE_STRING ) && customValueExists ) )
{
dataElementCode = dataElementCode.replace( "input", "select" );
dataElementCode = dataElementCode.replaceAll( "value=\".*?\"", "" );
@@ -731,7 +684,7 @@
}
// -------------------------------------------------------------
- // MIN-MAX Values
+ // Min-max values
// -------------------------------------------------------------
MinMaxDataElement minMaxDataElement = minMaxMap.get( dataElement.getId() + ":" + optionComboId );
@@ -751,7 +704,7 @@
dataElementCode = dataElementCode.replaceAll( "view=\".*?\"", "" );
// -------------------------------------------------------------
- // Insert Title Information - DataElement id,name,type,min,max
+ // Insert title information - Data element id, name, type, min, max
// -------------------------------------------------------------
if ( dataElementCode.contains( "title=\"\"" ) )
@@ -800,7 +753,7 @@
appendCode += "</select>";
}
- else if ( dataElement.getType().equals( TYPE_STRING ) && count > 0 )
+ else if ( dataElement.getType().equals( TYPE_STRING ) && customValueExists )
{
appendCode += jsCodeForCombos;
@@ -875,4 +828,59 @@
return sb.toString();
}
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ /**
+ * Tests whether the given Collection of CustomValues contains a CustomValue
+ * with the given data element identifier and category option combo id.
+ */
+ private boolean customValuesExists( Collection<CustomValue> customValues, int dataElementId, int categoryOptionComboId )
+ {
+ for ( CustomValue customValue : customValues )
+ {
+ if ( dataElementId == customValue.getDataElement().getId() && categoryOptionComboId == customValue.getOptionCombo().getId() )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the value of the DataValue in the Collection of DataValues with
+ * the given data element identifier and category option combo id.
+ */
+ private String getValue( Collection<DataValue> dataValues, int dataElementId, int categoryOptionComboId )
+ {
+ for ( DataValue dataValue : dataValues )
+ {
+ if ( dataValue.getDataElement().getId() == dataElementId && dataValue.getOptionCombo().getId() == categoryOptionComboId )
+ {
+ return dataValue.getValue();
+ }
+ }
+
+ return EMPTY;
+ }
+
+ /**
+ * Returns the value of the DataValue in the Collection of DataValues with
+ * the given data element identifier.
+ */
+ private String getValue( Collection<DataValue> dataValues, int dataElementId )
+ {
+ for ( DataValue dataValue : dataValues )
+ {
+ if ( dataValue.getDataElement().getId() == dataElementId )
+ {
+ return dataValue.getValue();
+ }
+ }
+
+ return EMPTY;
+ }
}