← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15810: Data set, better check for whether custom form exists. Removed unused code.

 

------------------------------------------------------------
revno: 15810
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-06-23 14:01:13 +0200
message:
  Data set, better check for whether custom form exists. Removed unused code.
removed:
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormTest.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryForm.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.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/DataEntryForm.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryForm.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryForm.java	2014-06-23 12:01:13 +0000
@@ -28,19 +28,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.Serializable;
+import java.util.regex.Pattern;
+
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.ImportableObject;
+import org.hisp.dhis.common.view.DetailedView;
+import org.hisp.dhis.common.view.ExportView;
+
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonView;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
-import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.common.ImportableObject;
-import org.hisp.dhis.common.view.DetailedView;
-import org.hisp.dhis.common.view.ExportView;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 /**
  * @author Bharath Kumar
@@ -121,51 +120,11 @@
     // -------------------------------------------------------------------------
 
     /**
-     * Map the identifiers inside the HTML code according to the provided data
-     * element identifier and category option combo identifier mappings.
-     *
-     * @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.
+     * Indicates whether this data entry form has custom form HTML code.
      */
-    public void convertDataEntryForm( Map<Object, Integer> dataElementMap, Map<Object, Integer> 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 );
-
-        this.htmlCode = buffer.toString();
-    }
-
-    private static void throwException( boolean condition, String message )
-    {
-        if ( condition )
-        {
-            throw new IllegalArgumentException( message );
-        }
+    public boolean hasForm()
+    {
+        return htmlCode != null && !htmlCode.trim().isEmpty();
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2014-04-25 11:22:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2014-06-23 12:01:13 +0000
@@ -424,7 +424,7 @@
 
     public boolean hasDataEntryForm()
     {
-        return dataEntryForm != null;
+        return dataEntryForm != null && dataEntryForm.hasForm();
     }
 
     public boolean hasSections()

=== removed file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormTest.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataentryform/DataEntryFormTest.java	1970-01-01 00:00:00 +0000
@@ -1,86 +0,0 @@
-package org.hisp.dhis.dataentryform;
-
-/*
- * Copyright (c) 2004-2014, 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 static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-
-/**
- * @author Lars Helge Overland
- */
-public class DataEntryFormTest
-{
-    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>";
-
-    @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( "DataEntryFormA", htmlCodeA );
-        
-        form.convertDataEntryForm( 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( "DataEntryFormA", htmlCodeA );
-        
-        form.convertDataEntryForm( dataElementMap, categoryOptionComboMap );
-        
-        fail();
-    }
-}