dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #04187
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1393: Added action for retrieving operands to the json api.
------------------------------------------------------------
revno: 1393
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-02-04 12:04:36 +0100
message:
Added action for retrieving operands to the json api.
added:
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/OperandMapper.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionCombos.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElement.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementName.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElements.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSet.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSets.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicator.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicators.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnit.vm
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnits.vm
dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml
--
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/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-02-04 09:59:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/hibernate/HibernateDataElementStore.java 2010-02-04 11:04:36 +0000
@@ -423,7 +423,7 @@
final ObjectMapper<Operand> mapper = new ObjectMapper<Operand>();
final String sql =
- "SELECT de.dataelementid, cocn.categoryoptioncomboid, cocn.categoryoptioncomboname " +
+ "SELECT de.dataelementid, de.name, cocn.categoryoptioncomboid, cocn.categoryoptioncomboname " +
"FROM dataelement as de " +
"JOIN categorycombo as cc on de.categorycomboid=cc.categorycomboid " +
"JOIN categorycombos_optioncombos as ccoc on cc.categorycomboid=ccoc.categorycomboid " +
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/OperandMapper.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/OperandMapper.java 2010-02-04 09:59:45 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/OperandMapper.java 2010-02-04 11:04:36 +0000
@@ -1,22 +1,65 @@
package org.hisp.dhis.system.objectmapper;
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
import java.sql.ResultSet;
import java.sql.SQLException;
import org.amplecode.quick.mapper.RowMapper;
import org.hisp.dhis.dataelement.Operand;
+import static org.hisp.dhis.dataelement.DataElementCategoryOptionCombo.DEFAULT_TOSTRING;
+
+/**
+ * @author Lars Helge Overland
+ */
public class OperandMapper
implements RowMapper<Operand>
{
+ private static final String SEPARATOR = " ";
+
@Override
public Operand mapRow( ResultSet resultSet )
throws SQLException
{
- Operand operand = new Operand(
+ String operandName = resultSet.getString( 2 );
+
+ final String cocName = resultSet.getString( 4 );
+
+ if ( cocName != null && !cocName.equals( DEFAULT_TOSTRING ) )
+ {
+ operandName += SEPARATOR + cocName;
+ }
+
+ final Operand operand = new Operand(
resultSet.getInt( 1 ),
- resultSet.getInt( 2 ),
- resultSet.getString( 3 ) );
+ resultSet.getInt( 3 ),
+ operandName );
return operand;
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionCombos.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionCombos.vm 2010-01-25 11:54:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonCategoryOptionCombos.vm 2010-02-04 11:04:36 +0000
@@ -3,7 +3,7 @@
#foreach( $coc in $categoryOptionCombos )
{
"id": $!{coc.id},
- "name": "$!{coc.name}"
+ "name": "$!encoder.jsEncode( ${coc.name} )"
}#if( $velocityCount < $size ),#end
#end
] }
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElement.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElement.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElement.vm 2010-02-04 11:04:36 +0000
@@ -1,11 +1,11 @@
{ "dataElement":
{
"id": $!{dataElement.id},
- "name": "$!{dataElement.name}",
- "alternativeName": "$!{dataElement.alternativeNamee}",
- "shortName": "$!{dataElement.shortName}",
- "code": "$!{dataElement.code}",
- "description": "$!{dataElement.description}",
+ "name": "$!encoder.jsEncode( ${dataElement.name} )",
+ "alternativeName": "$!encoder.jsEncode( ${dataElement.alternativeNamee} )",
+ "shortName": "$!encoder.jsEncode( ${dataElement.shortName} )",
+ "code": "$!encoder.jsEncode( ${dataElement.code} )",
+ "description": "$!encoder.jsEncode( ${dataElement.description} )",
"active": "$!{dataElement.active}",
"type": "$!{dataElement.type}",
"aggregationOperator": "$!{dataElement.aggregationOperator}"
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementName.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementName.vm 2010-01-25 11:54:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElementName.vm 2010-02-04 11:04:36 +0000
@@ -1,1 +1,1 @@
-{ "name": "$!{name}" }
\ No newline at end of file
+{ "name": "$!encoder.jsEncode( ${name} )" }
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElements.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElements.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataElements.vm 2010-02-04 11:04:36 +0000
@@ -2,11 +2,11 @@
{ "dataElements": [
#foreach( $dataElement in $dataElements )
{
- "id": $!{dataElement.id},
- "name": "$!{dataElement.name}",
- "alternativeName": "$!{dataElement.alternativeNamee}",
- "shortName": "$!{dataElement.shortName}",
- "code": "$!{dataElement.code}",
+ "id": $!encoder.jsEncode( ${dataElement.id} ),
+ "name": "$!encoder.jsEncode( ${dataElement.name} )",
+ "alternativeName": "$!encoder.jsEncode( ${dataElement.alternativeNamee} )",
+ "shortName": "$!encoder.jsEncode( ${dataElement.shortName} )",
+ "code": "$!encoder.jsEncode( ${dataElement.code} )",
"type": "$!{dataElement.type}",
"aggregationOperator": "$!{dataElement.aggregationOperator}"
}#if( $velocityCount < $size ),#end
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSet.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSet.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSet.vm 2010-02-04 11:04:36 +0000
@@ -1,8 +1,8 @@
{ "dataSet":
{
"id": $!{dataSet.id},
- "name": "$!{dataSet.name}",
- "shortName": "$!{dataSet.shortName}",
+ "name": "$!encoder.jsEncode( ${dataSet.name} )",
+ "shortName": "$!encoder.jsEncode( ${dataSet.shortName} )",
"periodTypeId": "$!{dataSet.periodTypeId}"
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSets.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSets.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonDataSets.vm 2010-02-04 11:04:36 +0000
@@ -3,8 +3,8 @@
#foreach( $dataSet in $dataSets )
{
"id": $!{dataSet.id},
- "name": "$!{dataSet.name}",
- "shortName": "$!{dataSet.shortName}",
+ "name": "$!encoder.jsEncode( ${dataSet.name} )",
+ "shortName": "$!encoder.jsEncode( ${dataSet.shortName} )",
"periodTypeId": "$!{dataSet.periodTypeId}"
}#if( $velocityCount < $size ),#end
#end
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicator.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicator.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicator.vm 2010-02-04 11:04:36 +0000
@@ -1,17 +1,17 @@
{ "indicator":
{
"id": $!{indicator.id},
- "name": "$!{indicator.name}",
- "alternativeName": "$!{indicator.alternativeNamee}",
- "shortName": "$!{indicator.shortName}",
- "code": "$!{indicator.code}",
+ "name": "$!encoder.jsEncode( ${indicator.name} )",
+ "alternativeName": "$!encoder.jsEncode( ${indicator.alternativeNamee} )",
+ "shortName": "$!encoder.jsEncode( ${indicator.shortName} )",
+ "code": "$!encoder.jsEncode( ${indicator.code} )",
"annualized": "${indicator.annualized}",
"indicatorTypeId": "$!{indicator.indicatorType.id}",
"numerator": "$!{indicator.numerator}",
- "numeratorDescription": "$!{indicator.numeratorDescription}",
+ "numeratorDescription": "$!encoder.jsEncode( ${indicator.numeratorDescription} )",
"numeratorAggregationOperator": "$!{indicator.numeratorAggregationOperator}",
"denominator": "$!{indicator.denominator}",
- "denominatorDescription": "$!{indicator.denominatorDescription}",
+ "denominatorDescription": "$!encoder.jsEncode( ${indicator.denominatorDescription} )",
"denominatorAggregationOperator": "$!{indicator.denominatorAggregationOperator}"
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicators.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicators.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonIndicators.vm 2010-02-04 11:04:36 +0000
@@ -3,10 +3,10 @@
#foreach( $indicator in $indicators )
{
"id": $!{indicator.id},
- "name": "$!encoder.jsonEncode( ${indicator.name} )",
- "alternativeName": "$!encoder.jsonEncode( ${indicator.alternativeNamee} )",
- "shortName": "$!encoder.jsonEncode( ${indicator.shortName} )",
- "code": "$!encoder.jsonEncode( ${indicator.code} )",
+ "name": "$!encoder.jsEncode( ${indicator.name} )",
+ "alternativeName": "$!encoder.jsEncode( ${indicator.alternativeNamee} )",
+ "shortName": "$!encoder.jsEncode( ${indicator.shortName} )",
+ "code": "$!encoder.jsEncode( ${indicator.code} )",
"annualized": "${indicator.annualized}",
"indicatorTypeId": $!{indicator.indicatorType.id}
}#if( $velocityCount < $size ),#end
=== added file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOperands.vm 2010-02-04 11:04:36 +0000
@@ -0,0 +1,11 @@
+#set( $size = $operands.size() )
+{ "operands": [
+#foreach( $operand in $operands )
+ {
+ "id": "$!{operand.id}",
+ "dataElementId": "$!{operand.dataElementId}",
+ "optionComboId": "$!{operand.optionComboId}",
+ "operandName": "$!encoder.jsEncode( ${operand.operandName} )"
+ }#if( $velocityCount < $size ),#end
+#end
+] }
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnit.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnit.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnit.vm 2010-02-04 11:04:36 +0000
@@ -1,13 +1,13 @@
{ "organisationUnit":
{
"id": $!{organisationUnit.id},
- "name": "$!{organisationUnit.name}",
- "shortName": "$!{organisationUnit.shortName}",
- "code": "$!{organisationUnit.code}",
+ "name": "$!encoder.jsEncode( ${organisationUnit.name} )",
+ "shortName": "$!encoder.jsEncode( ${organisationUnit.shortName} )",
+ "code": "$!encoder.jsEncode( ${organisationUnit.code} )",
"openingDate": "$!{organisationUnit.openingDate}",
"closedDate": "$!{organisationUnit.closedDate}",
"active": "$!{organisationUnit.active}",
- "comment": "$!{organisationUnit.comment}",
+ "comment": "$!encoder.jsEncode( ${organisationUnit.comment} )",
"geoCode": "$!{organisationUnit.geoCode}",
"latitude": "$!{organisationUnit.latitude}",
"longitude": "$!{organisationUnit.longitude}"
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnits.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnits.vm 2010-01-25 09:23:35 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/ajax/jsonOrganisationUnits.vm 2010-02-04 11:04:36 +0000
@@ -3,9 +3,9 @@
#foreach ( $unit in $organisationUnits )
{
"id": $!{unit.id},
- "name": "$!{unit.name}",
- "shortName": "$!{unit.shortName}",
- "code": "$!{unit.code}"
+ "name": "$!encoder.jsEncode( ${unit.name} )",
+ "shortName": "$!encoder.jsEncode( ${unit.shortName} )",
+ "code": "$!encoder.jsEncode( ${unit.code} )"
}#if( $velocityCount < $size ),#end
#end
] }
=== added file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/commons/action/GetOperandsAction.java 2010-02-04 11:04:36 +0000
@@ -0,0 +1,33 @@
+package org.hisp.dhis.commons.action;
+
+import java.util.Collection;
+
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataelement.Operand;
+
+import com.opensymphony.xwork2.Action;
+
+public class GetOperandsAction
+ implements Action
+{
+ private DataElementService dataElementService;
+
+ public void setDataElementService( DataElementService dataElementService )
+ {
+ this.dataElementService = dataElementService;
+ }
+
+ public Collection<Operand> operands;
+
+ public Collection<Operand> getOperands()
+ {
+ return operands;
+ }
+
+ public String execute()
+ {
+ operands = dataElementService.getAllOperands();
+
+ return SUCCESS;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2010-01-28 15:23:28 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/META-INF/dhis/beans.xml 2010-02-04 11:04:36 +0000
@@ -617,6 +617,12 @@
<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
</bean>
+ <bean id="org.hisp.dhis.commons.action.GetOperandsAction"
+ class="org.hisp.dhis.commons.action.GetOperandsAction"
+ scope="prototype">
+ <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService"/>
+ </bean>
+
<bean id="org.hisp.dhis.commons.action.NoAction"
class="org.hisp.dhis.commons.action.NoAction" />
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml'
--- dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2010-01-25 11:54:22 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/resources/dhis-web-commons.xml 2010-02-04 11:04:36 +0000
@@ -351,7 +351,7 @@
/dhis-web-commons/ajax/xmlCategoryOptionCombos.vm</result>
<param name="onExceptionReturn">plainTextError</param>
</action>
-
+
</package>
<!-- Common actions JSON -->
@@ -431,16 +431,22 @@
</action>
<action name="getCategoryOptionCombos" class="org.hisp.dhis.commons.action.GetCategoryOptionCombosAction">
- <result name="success" type="velocity-xml">
+ <result name="success" type="velocity-json">
/dhis-web-commons/ajax/jsonCategoryOptionCombos.vm</result>
<param name="onExceptionReturn">plainTextError</param>
</action>
<action name="getDataElementName" class="org.hisp.dhis.commons.action.GetDataElementNameAction">
- <result name="success" type="velocity-xml">
+ <result name="success" type="velocity-json">
/dhis-web-commons/ajax/jsonDataElementName.vm</result>
<param name="onExceptionReturn">plainTextError</param>
</action>
+
+ <action name="getOperands" class="org.hisp.dhis.commons.action.GetOperandsAction">
+ <result name="success" type="velocity-json">
+ /dhis-web-commons/ajax/jsonOperands.vm</result>
+ <param name="onExceptionReturn">plainTextError</param>
+ </action>
</package>