dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #07364
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2091: Implemented method for converting data entry form datalement/categoryoptioncombo identifiers. Mov...
------------------------------------------------------------
revno: 2091
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Fri 2010-09-10 11:54:49 +0200
message:
Implemented method for converting data entry form datalement/categoryoptioncombo identifiers. Moved tests to proper package
added:
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExceptionUtils.java
renamed:
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataEntryFormServiceTest.java => dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataEntryFormStoreTest.java => dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java
dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.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/dataentryform/DataEntryFormService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2010-08-31 14:34:31 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java 2010-09-10 09:54:49 +0000
@@ -29,6 +29,7 @@
import java.util.Collection;
import java.util.List;
+import java.util.Map;
public interface DataEntryFormService
{
@@ -90,6 +91,8 @@
*/
String prepareDataEntryFormCode( String preparedCode );
+ void convertDataEntryForm( DataEntryForm form, Map<Object, Integer> dataElementMap, Map<Object, Integer> categoryOptionComboMap );
+
Collection<DataEntryForm> listDisctinctDataEntryFormByProgramStageIds( List<Integer> programStageIds );
Collection<DataEntryForm> listDisctinctDataEntryFormByDataSetIds( List<Integer> dataSetIds );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2010-08-31 14:34:31 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2010-09-10 09:54:49 +0000
@@ -27,8 +27,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.system.util.ExceptionUtils.throwException;
+
import java.util.Collection;
import java.util.List;
+import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -42,6 +45,9 @@
public class DefaultDataEntryFormService
implements DataEntryFormService
{
+ private static final Pattern INPUT_PATTERN = Pattern.compile( "value\\[\\d+\\]\\.value:value\\[\\d+\\]\\.value" );
+ private static final Pattern OPERAND_PATTERN = Pattern.compile( "\\d+" );
+
// ------------------------------------------------------------------------
// Dependencies
// ------------------------------------------------------------------------
@@ -161,6 +167,36 @@
return sb.toString();
}
+
+ public void convertDataEntryForm( DataEntryForm form, Map<Object, Integer> dataElementMap, Map<Object, Integer> categoryOptionComboMap )
+ {
+ Matcher inputMatcher = INPUT_PATTERN.matcher( form.getHtmlCode() );
+ StringBuffer buffer = new StringBuffer();
+
+ while ( inputMatcher.find() )
+ {
+ String input = inputMatcher.group();
+ Matcher operandMatcher = OPERAND_PATTERN.matcher( input );
+
+ operandMatcher.find();
+ String d = operandMatcher.group();
+ throwException( d == null, "Could not find data element identifier in form" );
+ Integer dataElement = dataElementMap.get( Integer.parseInt( d ) );
+ throwException( dataElement == null, "Data element identifier does not exist: " + d );
+
+ operandMatcher.find();
+ String c = operandMatcher.group();
+ throwException( c == null, "Could not find category option combo identifier in form" );
+ Integer categoryOptionCombo = categoryOptionComboMap.get( Integer.parseInt( c ) );
+ throwException( categoryOptionCombo == null, "Category option combo identifier does not exist: " + c );
+
+ inputMatcher.appendReplacement( buffer, "value[" + dataElement + "].value:value[" + categoryOptionCombo + "].value" );
+ }
+
+ inputMatcher.appendTail( buffer );
+
+ form.setHtmlCode( buffer.toString() );
+ }
public Collection<DataEntryForm> listDisctinctDataEntryFormByProgramStageIds( List<Integer> programStageIds )
{
@@ -181,5 +217,4 @@
return dataEntryFormStore.listDisctinctDataEntryFormByDataSetIds( dataSetIds );
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java 2010-08-24 01:48:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/indicator/IndicatorDeletionHandler.java 2010-09-10 09:54:49 +0000
@@ -99,13 +99,20 @@
for ( Indicator indicator : indicatorService.getAllIndicators() )
{
Set<DataElement> daels = expressionService.getDataElementsInExpression( indicator.getNumerator() );
- if ( daels != null && daels.contains( dataElement ) ) return false;
+
+ if ( daels != null && daels.contains( dataElement ) )
+ {
+ return false;
+ }
daels = expressionService.getDataElementsInExpression( indicator.getDenominator() );
- if ( daels != null && daels.contains( dataElement ) ) return false;
+
+ if ( daels != null && daels.contains( dataElement ) )
+ {
+ return false;
+ }
}
return true;
}
-
}
=== added directory 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform'
=== renamed file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataEntryFormServiceTest.java' => 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataEntryFormServiceTest.java 2010-09-04 08:21:14 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java 2010-09-10 09:54:49 +0000
@@ -1,4 +1,4 @@
-package org.hisp.dhis.dataset;
+package org.hisp.dhis.dataentryform;
/*
* Copyright (c) 2004-2010, University of Oslo
@@ -31,13 +31,18 @@
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.period.PeriodStore;
import org.hisp.dhis.period.PeriodType;
import org.junit.Test;
@@ -49,6 +54,18 @@
public class DataEntryFormServiceTest
extends DhisSpringTest
{
+ private String htmlCodeA =
+ "<p><table><tr valign=\"top\">" +
+ "<td align=\"center\" width=\"8%\"><p><input title=\"\" view=\"@@deshortname@@\" value=\"\" name=\"entryfield\" id=\"value[1000].value:value[3].value\" style=\"width: 4em; text-align: center;\" /></p></td>" +
+ "<td align=\"center\" width=\"4%\"><p><input title=\"\" view=\"@@deshortname@@\" value=\"\" name=\"entryfield\" id=\"value[2000].value:value[4].value\" style=\"width: 4em; text-align: center;\" /></p></td>" +
+ "</tr></table></p>";
+
+ private String htmlCodeB =
+ "<p><table><tr valign=\"top\">" +
+ "<td align=\"center\" width=\"8%\"><p><input title=\"\" view=\"@@deshortname@@\" value=\"\" name=\"entryfield\" id=\"value[1100].value:value[13].value\" style=\"width: 4em; text-align: center;\" /></p></td>" +
+ "<td align=\"center\" width=\"4%\"><p><input title=\"\" view=\"@@deshortname@@\" value=\"\" name=\"entryfield\" id=\"value[2100].value:value[14].value\" style=\"width: 4em; text-align: center;\" /></p></td>" +
+ "</tr></table></p>";
+
private PeriodStore periodStore;
private DataSetService dataSetService;
@@ -79,6 +96,37 @@
// -------------------------------------------------------------------------
@Test
+ public void testConvertDataEntryForm()
+ {
+ Map<Object, Integer> dataElementMap = new HashMap<Object, Integer>();
+ Map<Object, Integer> categoryOptionComboMap = new HashMap<Object, Integer>();
+
+ dataElementMap.put( 1000, 1100 );
+ dataElementMap.put( 2000, 2100 );
+ categoryOptionComboMap.put( 3, 13 );
+ categoryOptionComboMap.put( 4, 14 );
+
+ DataEntryForm form = new DataEntryForm( "FormA", htmlCodeA );
+
+ dataEntryFormService.convertDataEntryForm( form, dataElementMap, categoryOptionComboMap );
+
+ assertEquals( htmlCodeB, form.getHtmlCode() );
+ }
+
+ @Test(expected=RuntimeException.class)
+ public void testConvertDataEntryFormInvalid()
+ {
+ Map<Object, Integer> dataElementMap = new HashMap<Object, Integer>();
+ Map<Object, Integer> categoryOptionComboMap = new HashMap<Object, Integer>();
+
+ DataEntryForm form = new DataEntryForm( "FormA", htmlCodeA );
+
+ dataEntryFormService.convertDataEntryForm( form, dataElementMap, categoryOptionComboMap );
+
+ fail();
+ }
+
+ @Test
public void testAddDataEntryForm()
{
DataSet dataSetA = new DataSet( "DataSet-A", periodType );
=== renamed file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataEntryFormStoreTest.java' => 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataEntryFormStoreTest.java 2010-09-01 04:42:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormStoreTest.java 2010-09-10 09:54:49 +0000
@@ -1,4 +1,4 @@
-package org.hisp.dhis.dataset;
+package org.hisp.dhis.dataentryform;
/*
* Copyright (c) 2004-2010, University of Oslo
@@ -37,6 +37,8 @@
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormStore;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.period.PeriodStore;
import org.hisp.dhis.period.PeriodType;
import org.junit.Test;
@@ -50,7 +52,7 @@
{
private PeriodStore periodStore;
- private DataSetStore dataSetStore;
+ private DataSetService dataSetService;
private DataEntryFormStore dataEntryFormStore;
@@ -60,7 +62,7 @@
public void setUpTest()
throws Exception
{
- dataSetStore = (DataSetStore) getBean( DataSetStore.ID );
+ dataSetService = (DataSetService) getBean( DataSetService.ID );
periodStore = (PeriodStore) getBean( PeriodStore.ID );
@@ -78,7 +80,7 @@
{
DataSet dataSetA = new DataSet( "DataSet-A", periodType );
- dataSetStore.addDataSet( dataSetA );
+ dataSetService.addDataSet( dataSetA );
DataEntryForm dataEntryFormA = new DataEntryForm( "DataEntryForm-A" );
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExceptionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExceptionUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExceptionUtils.java 2010-09-10 09:54:49 +0000
@@ -0,0 +1,25 @@
+package org.hisp.dhis.system.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ExceptionUtils
+{
+ private static final Log log = LogFactory.getLog( ExceptionUtils.class );
+
+ public static void throwException( boolean condition, String message )
+ {
+ if ( condition )
+ {
+ throw new RuntimeException( message );
+ }
+ }
+
+ public static void logException( boolean condition, String message )
+ {
+ if ( condition )
+ {
+ log.error( message );
+ }
+ }
+}
=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2010-09-01 07:28:01 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java 2010-09-10 09:54:49 +0000
@@ -50,6 +50,7 @@
import org.hisp.dhis.dataelement.DataElementGroup;
import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
@@ -147,6 +148,8 @@
protected MappingService mappingService;
protected ProgramStageService programStageService;
+
+ protected DataEntryFormService dataEntryFormService;
static
{