← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1885: Minor fix.

 

------------------------------------------------------------
revno: 1885
committer: Tran Chau <tran.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Thu 2010-07-29 12:49:13 +0700
message:
  Minor fix.
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-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.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-07-25 12:54:27 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataentryform/DataEntryFormService.java	2010-07-29 05:49:13 +0000
@@ -102,4 +102,12 @@
      * @return A collection containing all DataEntryForms.
      */
     Collection<DataEntryForm> getAllDataEntryForms();    
+    
+    /**
+     * Prepare DataEntryForm code
+     * 
+     * @return htmlCode.
+     */
+    String prepareDataEntryFormCode( String preparedCode );
+    
 }

=== 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-07-25 12:54:27 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataentryform/DefaultDataEntryFormService.java	2010-07-29 05:49:13 +0000
@@ -28,6 +28,8 @@
  */
 
 import java.util.Collection;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.program.ProgramStage;
@@ -141,4 +143,79 @@
     {
         return dataEntryFormStore.getAllDataEntryForms();
     }
+    
+    public String prepareDataEntryFormCode( String preparedCode )
+    {
+        // ---------------------------------------------------------------------
+        // Buffer to contain the final result.
+        // ---------------------------------------------------------------------
+        
+        StringBuffer sb = new StringBuffer();
+        
+        // ---------------------------------------------------------------------
+        // Pattern to match data elements in the HTML code.
+        // ---------------------------------------------------------------------
+ 
+        Pattern patDataElement = Pattern.compile( "(<input.*?)[/]?>" );
+        Matcher matDataElement = patDataElement.matcher( preparedCode );
+
+        // ---------------------------------------------------------------------
+        // Iterate through all matching data element fields.
+        // ---------------------------------------------------------------------
+        
+        boolean result = matDataElement.find();
+        
+        while ( result )
+        {
+            // -----------------------------------------------------------------
+            // Get input HTML code (HTML input field code).
+            // -----------------------------------------------------------------
+            
+            String dataElementCode = matDataElement.group( 1 );
+            
+            // -----------------------------------------------------------------
+            // Pattern to extract data element name from data element field
+            // -----------------------------------------------------------------
+            
+            Pattern patDataElementName = Pattern.compile( "value=\"\\[ (.*) \\]\"" );
+            Matcher matDataElementName = patDataElementName.matcher( dataElementCode );
+
+            Pattern patTitle = Pattern.compile( "title=\"-- (.*) --\"" );
+            Matcher matTitle = patTitle.matcher( dataElementCode );
+       
+            if ( matDataElementName.find() && matDataElementName.groupCount() > 0 )
+            {
+                String temp = "[ " + matDataElementName.group( 1 ) + " ]";
+                dataElementCode = dataElementCode.replace( temp, "" );
+
+                if ( matTitle.find() && matTitle.groupCount() > 0 )
+                {
+                    temp = "-- " + matTitle.group( 1 ) + " --";
+                    dataElementCode = dataElementCode.replace( temp, "" );
+                }
+
+                // -------------------------------------------------------------
+                // Appends dataElementCode
+                // -------------------------------------------------------------
+       
+                String appendCode = dataElementCode;
+                appendCode += "/>";
+                matDataElement.appendReplacement( sb, appendCode );
+            }
+
+            // -----------------------------------------------------------------
+            // Go to next data entry field
+            // -----------------------------------------------------------------
+   
+            result = matDataElement.find();
+        }
+
+        // -----------------------------------------------------------------
+        // Add remaining code (after the last match), and return formatted code.
+        // -----------------------------------------------------------------
+
+        matDataElement.appendTail( sb );
+
+        return sb.toString();
+    }    
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java	2010-07-27 03:51:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/AutoSaveDataEntryFormAction.java	2010-07-29 05:49:13 +0000
@@ -108,86 +108,11 @@
         else
         {
             dataEntryForm.setName( nameField );
-            dataEntryForm.setHtmlCode( prepareDataEntryFormInputs(designTextarea ));
+            dataEntryForm.setHtmlCode( dataEntryFormService.prepareDataEntryFormCode(designTextarea ));
             dataEntryFormService.updateDataEntryForm( dataEntryForm );
         }
 
         return SUCCESS;
     }
     
-    private String prepareDataEntryFormInputs( String preparedCode )
-    {
-        // ---------------------------------------------------------------------
-        // Buffer to contain the final result.
-        // ---------------------------------------------------------------------
-        
-        StringBuffer sb = new StringBuffer();
-        
-        // ---------------------------------------------------------------------
-        // Pattern to match data elements in the HTML code.
-        // ---------------------------------------------------------------------
- 
-        Pattern patDataElement = Pattern.compile( "(<input.*?)[/]?>" );
-        Matcher matDataElement = patDataElement.matcher( preparedCode );
-
-        // ---------------------------------------------------------------------
-        // Iterate through all matching data element fields.
-        // ---------------------------------------------------------------------
-        
-        boolean result = matDataElement.find();
-        
-        while ( result )
-        {
-            // -----------------------------------------------------------------
-            // Get input HTML code (HTML input field code).
-            // -----------------------------------------------------------------
-            
-            String dataElementCode = matDataElement.group( 1 );
-            
-            // -----------------------------------------------------------------
-            // Pattern to extract data element name from data element field
-            // -----------------------------------------------------------------
-            
-            Pattern patDataElementName = Pattern.compile( "value=\"\\[ (.*) \\]\"" );
-            Matcher matDataElementName = patDataElementName.matcher( dataElementCode );
-
-            Pattern patTitle = Pattern.compile( "title=\"-- (.*) --\"" );
-            Matcher matTitle = patTitle.matcher( dataElementCode );
-       
-            if ( matDataElementName.find() && matDataElementName.groupCount() > 0 )
-            {
-                String temp = "[ " + matDataElementName.group( 1 ) + " ]";
-                dataElementCode = dataElementCode.replace( temp, "" );
-
-                if ( matTitle.find() && matTitle.groupCount() > 0 )
-                {
-                    temp = "-- " + matTitle.group( 1 ) + " --";
-                    dataElementCode = dataElementCode.replace( temp, "" );
-                }
-
-                // -------------------------------------------------------------
-                // Appends dataElementCode
-                // -------------------------------------------------------------
-       
-                String appendCode = dataElementCode;
-                appendCode += "/>";
-                matDataElement.appendReplacement( sb, appendCode );
-            }
-
-            // -----------------------------------------------------------------
-            // Go to next data entry field
-            // -----------------------------------------------------------------
-   
-            result = matDataElement.find();
-        }
-
-        // -----------------------------------------------------------------
-        // Add remaining code (after the last match), and return formatted code.
-        // -----------------------------------------------------------------
-
-        matDataElement.appendTail( sb );
-
-        return sb.toString();
-    }    
-
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java	2010-07-27 03:51:10 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataset/src/main/java/org/hisp/dhis/dataset/action/dataentryform/SaveDataEntryFormAction.java	2010-07-29 05:49:13 +0000
@@ -101,100 +101,17 @@
 
         if ( dataEntryForm == null )
         {
-            dataEntryForm = new DataEntryForm( nameField, prepareDataEntryFormCode( designTextarea ) );
+            dataEntryForm = new DataEntryForm( nameField, dataEntryFormService.prepareDataEntryFormCode( designTextarea ) );
             dataEntryFormService.addDataEntryForm( dataEntryForm, DataEntryFormAssociation.DATAENTRY_ASSOCIATE_DATASET, dataset.getId() );
         }
         else
         {
             dataEntryForm.setName( nameField );
-            dataEntryForm.setHtmlCode( prepareDataEntryFormCode( designTextarea ) );
+            dataEntryForm.setHtmlCode( dataEntryFormService.prepareDataEntryFormCode( designTextarea ) );
             dataEntryFormService.updateDataEntryForm( dataEntryForm );
         }
 
         return SUCCESS;
     }
-
-    private String prepareDataEntryFormCode( String dataEntryFormCode )
-    {
-        String preparedCode = dataEntryFormCode;
-
-        preparedCode = prepareDataEntryFormInputs( preparedCode );
-        
-        return preparedCode;
-    }
-
-    private String prepareDataEntryFormInputs( String preparedCode )
-    {
-        // ---------------------------------------------------------------------
-        // Buffer to contain the final result.
-        // ---------------------------------------------------------------------
-        
-        StringBuffer sb = new StringBuffer();
-        
-        // ---------------------------------------------------------------------
-        // Pattern to match data elements in the HTML code.
-        // ---------------------------------------------------------------------
- 
-        Pattern patDataElement = Pattern.compile( "(<input.*?)[/]?>" );
-        Matcher matDataElement = patDataElement.matcher( preparedCode );
-
-        // ---------------------------------------------------------------------
-        // Iterate through all matching data element fields.
-        // ---------------------------------------------------------------------
-        
-        boolean result = matDataElement.find();
-        
-        while ( result )
-        {
-            // -----------------------------------------------------------------
-            // Get input HTML code (HTML input field code).
-            // -----------------------------------------------------------------
-            
-            String dataElementCode = matDataElement.group( 1 );
-            
-            // -----------------------------------------------------------------
-            // Pattern to extract data element name from data element field
-            // -----------------------------------------------------------------
-            
-            Pattern patDataElementName = Pattern.compile( "value=\"\\[ (.*) \\]\"" );
-            Matcher matDataElementName = patDataElementName.matcher( dataElementCode );
-
-            Pattern patTitle = Pattern.compile( "title=\"-- (.*) --\"" );
-            Matcher matTitle = patTitle.matcher( dataElementCode );
-       
-            if ( matDataElementName.find() && matDataElementName.groupCount() > 0 )
-            {
-                String temp = "[ " + matDataElementName.group( 1 ) + " ]";
-                dataElementCode = dataElementCode.replace( temp, "" );
-
-                if ( matTitle.find() && matTitle.groupCount() > 0 )
-                {
-                    temp = "-- " + matTitle.group( 1 ) + " --";
-                    dataElementCode = dataElementCode.replace( temp, "" );
-                }
-
-                // -------------------------------------------------------------
-                // Appends dataElementCode
-                // -------------------------------------------------------------
-       
-                String appendCode = dataElementCode;
-                appendCode += "/>";
-                matDataElement.appendReplacement( sb, appendCode );
-            }
-
-            // -----------------------------------------------------------------
-            // Go to next data entry field
-            // -----------------------------------------------------------------
    
-            result = matDataElement.find();
-        }
-
-        // -----------------------------------------------------------------
-        // Add remaining code (after the last match), and return formatted code.
-        // -----------------------------------------------------------------
-
-        matDataElement.appendTail( sb );
-        
-        return sb.toString();
-    }    
 }