dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #08969
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2279: Centralized method
------------------------------------------------------------
revno: 2279
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2010-12-04 00:12:42 +0100
message:
Centralized method
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.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/dataelement/DataElementCategoryService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2010-10-08 10:12:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementCategoryService.java 2010-12-03 23:12:42 +0000
@@ -316,6 +316,14 @@
void generateOptionCombos( DataElementCategoryCombo categoryCombo );
/**
+ * Populates all transient properties on each Operand in the given collection.
+ *
+ * @param operands the collection of Operands.
+ * @return a collection of Operands.
+ */
+ public Collection<DataElementOperand> populateOperands( Collection<DataElementOperand> operands );
+
+ /**
*
* @param dataElementIdentifiers
* @return
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2010-12-03 22:30:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2010-12-03 23:12:42 +0000
@@ -36,7 +36,7 @@
/**
* This object can act both as a hydrated persisted object and as a wrapper
- * object.
+ * object (but not both at the same time).
*
* @author Abyot Asalefew
* @version $Id$
@@ -63,7 +63,7 @@
private DataElementCategoryOptionCombo categoryOptionCombo;
// -------------------------------------------------------------------------
- // Populated properties
+ // Transient properties
// -------------------------------------------------------------------------
private int dataElementId;
@@ -217,7 +217,7 @@
return COLUMN_PREFIX + dataElementId + COLUMN_SEPARATOR + optionComboId;
}
- public String getPrettyName()
+ public String getPrettyName( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo )
{
if ( dataElement == null || categoryOptionCombo == null )
{
@@ -227,21 +227,16 @@
return categoryOptionCombo.isDefault() ? dataElement.getName() : dataElement.getName() + SPACE + categoryOptionCombo.getName();
}
- public void updateProperties()
- {
- if ( this.dataElement == null || this.categoryOptionCombo == null )
- {
- throw new NullPointerException( "Data Element or Category Option Combo is null" );
- }
-
- this.dataElementId = this.dataElement.getId();
- this.optionComboId = this.categoryOptionCombo.getId();
- this.operandId = this.dataElementId + SEPARATOR + this.optionComboId;
- this.operandName = getPrettyName();
- this.aggregationOperator = this.dataElement.getAggregationOperator();
- this.frequencyOrder = this.dataElement.getFrequencyOrder();
- this.aggregationLevels = new ArrayList<Integer>( this.dataElement.getAggregationLevels() );
- this.valueType = this.dataElement.getType();
+ public void updateProperties( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo )
+ {
+ this.dataElementId = dataElement.getId();
+ this.optionComboId = categoryOptionCombo.getId();
+ this.operandId = dataElement.getId() + SEPARATOR + categoryOptionCombo.getId();
+ this.operandName = getPrettyName( dataElement, categoryOptionCombo );
+ this.aggregationOperator = dataElement.getAggregationOperator();
+ this.frequencyOrder = dataElement.getFrequencyOrder();
+ this.aggregationLevels = new ArrayList<Integer>( dataElement.getAggregationLevels() );
+ this.valueType = dataElement.getType();
}
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2010-12-03 22:30:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2010-12-03 23:12:42 +0000
@@ -395,17 +395,29 @@
return getOperands( dataElements );
}
+ public Collection<DataElementOperand> populateOperands( Collection<DataElementOperand> operands )
+ {
+ for ( DataElementOperand operand : operands )
+ {
+ DataElement dataElement = dataElementService.getDataElement( operand.getId() );
+ DataElementCategoryOptionCombo categoryOptionCombo = getDataElementCategoryOptionCombo( operand.getOptionComboId() );
+
+ operand.updateProperties( dataElement, categoryOptionCombo );
+ }
+
+ return operands;
+ }
+
public Collection<DataElementOperand> getOperands( Collection<DataElement> dataElements )
{
Collection<DataElementOperand> operands = new ArrayList<DataElementOperand>();
for ( DataElement dataElement : dataElements )
{
- for ( DataElementCategoryOptionCombo optionCombo : dataElement.getCategoryCombo().getOptionCombos() )
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getOptionCombos() )
{
- DataElementOperand operand = new DataElementOperand( dataElement.getId(), optionCombo.getId(),
- dataElement.getName() + optionCombo.getName(), dataElement.getType(), dataElement.getAggregationOperator(),
- new ArrayList<Integer>( dataElement.getAggregationLevels() ), dataElement.getFrequencyOrder() );
+ DataElementOperand operand = new DataElementOperand();
+ operand.updateProperties( dataElement, categoryOptionCombo );
operands.add( operand );
}
@@ -420,10 +432,10 @@
for ( DataElement dataElement : dataElements )
{
- for ( DataElementCategoryOptionCombo optionCombo : dataElement.getCategoryCombo().getOptionCombos() )
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getOptionCombos() )
{
- DataElementOperand operand = new DataElementOperand( dataElement, optionCombo );
- operand.updateProperties();
+ DataElementOperand operand = new DataElementOperand( dataElement, categoryOptionCombo );
+ operand.updateProperties( dataElement, categoryOptionCombo );
operands.add( operand );
}