=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DeleteNotAllowedException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DeleteNotAllowedException.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/DeleteNotAllowedException.java 2010-09-13 11:06:01 +0000
@@ -29,7 +29,6 @@
/**
* @author Lars Helge Overland
- * @version $Id$
*/
public class DeleteNotAllowedException
extends RuntimeException
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryForm.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryForm.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryForm.java 2010-09-13 11:06:01 +0000
@@ -28,10 +28,19 @@
*/
import java.io.Serializable;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+/**
+ * @author Bharath Kumar
+ */
public class DataEntryForm
implements Serializable
{
+ public static final Pattern INPUT_PATTERN = Pattern.compile( "value\\[\\d+\\]\\.value:value\\[\\d+\\]\\.value" );
+ public static final Pattern OPERAND_PATTERN = Pattern.compile( "\\d+" );
+
/**
* The unique identifier for this DataEntryForm
*/
@@ -67,6 +76,59 @@
}
// -------------------------------------------------------------------------
+ // Logic
+ // -------------------------------------------------------------------------
+
+ /**
+ * Map the identifiers inside the HTML code according to the provided data
+ * element identifier and category option combo identifier mappings.
+ *
+ * @param htmlCode the HTML code.
+ * @param dataElementMap the mapping between data element identifiers to be
+ * converted.
+ * @param categoryOptionComboMap the mapping between category option combo
+ * identifiers to be converted.
+ * @return the converted HTML code.
+ */
+ public void convertDataEntryForm( Map
";
+
+ private String htmlCodeB =
+ "
" +
+ "
" +
+ "
" +
+ "
";
+
+ @Test
+ public void testConvertDataEntryForm()
+ {
+ Map dataElementMap = new HashMap();
+ Map categoryOptionComboMap = new HashMap();
+
+ dataElementMap.put( 1000, 1100 );
+ dataElementMap.put( 2000, 2100 );
+ categoryOptionComboMap.put( 3, 13 );
+ categoryOptionComboMap.put( 4, 14 );
+
+ DataEntryForm form = new DataEntryForm( "DataEntryFormA", htmlCodeA );
+
+ form.convertDataEntryForm( dataElementMap, categoryOptionComboMap );
+
+ assertEquals( htmlCodeB, form.getHtmlCode() );
+ }
+
+ @Test(expected=RuntimeException.class)
+ public void testConvertDataEntryFormInvalid()
+ {
+ Map dataElementMap = new HashMap();
+ Map categoryOptionComboMap = new HashMap();
+
+ DataEntryForm form = new DataEntryForm( "DataEntryFormA", htmlCodeA );
+
+ form.convertDataEntryForm( dataElementMap, categoryOptionComboMap );
+
+ fail();
+ }
+}
=== 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-09-13 10:22:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java 2010-09-13 11:06:01 +0000
@@ -27,11 +27,8 @@
* 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;
@@ -45,9 +42,6 @@
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
// ------------------------------------------------------------------------
@@ -168,36 +162,6 @@
return sb.toString();
}
- public String convertDataEntryForm( String htmlCode, Map dataElementMap, Map categoryOptionComboMap )
- {
- Matcher inputMatcher = INPUT_PATTERN.matcher( htmlCode );
- 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 );
-
- return buffer.toString();
- }
-
public Collection listDisctinctDataEntryFormByProgramStageIds( List programStageIds )
{
if ( programStageIds == null || programStageIds.size() == 0 )
=== modified file '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/DataEntryFormServiceTest.java 2010-09-13 10:22:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormServiceTest.java 2010-09-13 11:06:01 +0000
@@ -31,16 +31,11 @@
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;
@@ -54,18 +49,6 @@
public class DataEntryFormServiceTest
extends DhisSpringTest
{
- private String htmlCodeA =
- "
" +
- "
" +
- "
" +
- "
";
-
- private String htmlCodeB =
- "
" +
- "
" +
- "
" +
- "
";
-
private PeriodStore periodStore;
private DataSetService dataSetService;
@@ -96,33 +79,6 @@
// -------------------------------------------------------------------------
@Test
- public void testConvertDataEntryForm()
- {
- Map dataElementMap = new HashMap();
- Map categoryOptionComboMap = new HashMap();
-
- dataElementMap.put( 1000, 1100 );
- dataElementMap.put( 2000, 2100 );
- categoryOptionComboMap.put( 3, 13 );
- categoryOptionComboMap.put( 4, 14 );
-
- String code = dataEntryFormService.convertDataEntryForm( htmlCodeA, dataElementMap, categoryOptionComboMap );
-
- assertEquals( htmlCodeB, code );
- }
-
- @Test(expected=RuntimeException.class)
- public void testConvertDataEntryFormInvalid()
- {
- Map dataElementMap = new HashMap();
- Map categoryOptionComboMap = new HashMap();
-
- dataEntryFormService.convertDataEntryForm( htmlCodeA, dataElementMap, categoryOptionComboMap );
-
- fail();
- }
-
- @Test
public void testAddDataEntryForm()
{
DataSet dataSetA = new DataSet( "DataSet-A", periodType );
=== modified 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 2010-09-10 09:54:49 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ExceptionUtils.java 2010-09-13 11:06:01 +0000
@@ -1,8 +1,38 @@
package org.hisp.dhis.system.util;
+/*
+ * Copyright (c) 2004-2010, 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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+/**
+ * @author Lars Helge Overland
+ */
public class ExceptionUtils
{
private static final Log log = LogFactory.getLog( ExceptionUtils.class );