← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2117: Centralized methods to objects

 

------------------------------------------------------------
revno: 2117
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2010-11-20 11:53:59 +0100
message:
  Centralized methods to objects
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDisplayModesAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SectionFormAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/SelectedStateManager.java
  dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.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-api/src/main/java/org/hisp/dhis/dataset/DataSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2010-10-22 07:41:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java	2010-11-20 10:53:59 +0000
@@ -130,6 +130,20 @@
     }
 
     // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    public boolean hasDataEntryForm()
+    {
+        return dataEntryForm != null;
+    }
+    
+    public boolean hasSections()
+    {
+        return sections != null && sections.size() > 0;
+    }
+    
+    // -------------------------------------------------------------------------
     // hashCode and equals
     // -------------------------------------------------------------------------
 
@@ -242,17 +256,11 @@
         this.sortOrder = sortOrder;
     }
 
-    /**
-     * @param sections the sections to set
-     */
     public void setSections( Set<Section> sections )
     {
         this.sections = sections;
     }
 
-    /**
-     * @return the sections
-     */
     public Set<Section> getSections()
     {
         return sections;

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java	2010-10-22 13:49:25 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java	2010-11-20 10:53:59 +0000
@@ -71,7 +71,20 @@
     {
         return dataElements != null && dataElements.size() > 0 ? dataElements.iterator().next().getCategoryCombo() : null;
     }
-    
+
+    public boolean hasMultiDimensionalDataElement()
+    {
+        for ( DataElement element : dataElements )
+        {
+            if ( element.isMultiDimensional() )
+            {
+                return true;
+            }
+        }
+
+        return false;
+    }
+
     // -------------------------------------------------------------------------
     // hashCode, equals and toString
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDisplayModesAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDisplayModesAction.java	2010-11-18 13:11:49 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/LoadDisplayModesAction.java	2010-11-20 10:53:59 +0000
@@ -53,9 +53,9 @@
     {
         DataSet dataSet = selectedStateManager.getSelectedDataSet();
         
-        customForm = dataSet.getDataEntryForm() != null;
+        customForm = dataSet.hasDataEntryForm();
 
-        sectionForm = dataSet.getSections() != null && dataSet.getSections().size() > 0;
+        sectionForm = dataSet.hasSections();
 
         displayMode = selectedStateManager.getSelectedDisplayMode();
         

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SectionFormAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SectionFormAction.java	2010-11-18 13:17:32 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SectionFormAction.java	2010-11-20 10:53:59 +0000
@@ -53,7 +53,6 @@
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.de.comments.StandardCommentsManager;
-import org.hisp.dhis.de.screen.DataEntryScreenManager;
 import org.hisp.dhis.de.state.SelectedStateManager;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.minmax.MinMaxDataElement;
@@ -129,13 +128,6 @@
         this.categoryService = categoryService;
     }
 
-    private DataEntryScreenManager dataEntryScreenManager;
-
-    public void setDataEntryScreenManager( DataEntryScreenManager dataEntryScreenManager )
-    {
-        this.dataEntryScreenManager = dataEntryScreenManager;
-    }
-
     private SystemSettingManager systemSettingManager;
 
     public void setSystemSettingManager( SystemSettingManager systemSettingManager )
@@ -394,7 +386,7 @@
                     .getId() );
             }
 
-            if ( dataEntryScreenManager.hasMultiDimensionalDataElement( section ) )
+            if ( section.hasMultiDimensionalDataElement() )
             {
                 sectionIsMultiDimensional.put( section.getId(), true );
             }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java	2010-11-20 10:12:54 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/action/SelectAction.java	2010-11-20 10:53:59 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.de.state.SelectedStateManager.ALLOWED_FORM_TYPES;
 import static org.hisp.dhis.de.state.SelectedStateManager.CUSTOM_FORM;
 import static org.hisp.dhis.de.state.SelectedStateManager.DEFAULT_FORM;
 import static org.hisp.dhis.de.state.SelectedStateManager.SECTION_FORM;
@@ -238,22 +237,18 @@
         // Get display mode
         // ---------------------------------------------------------------------
 
-        if ( displayMode == null || !ALLOWED_FORM_TYPES.contains( displayMode ) )
+        if ( !selectedStateManager.displayModeIsValid( displayMode ) )
         {
             displayMode = selectedStateManager.getSelectedDisplayMode();
         }
         
-        boolean customDataEntryFormExists = selectedDataSet.getDataEntryForm() != null;
-
-        boolean hasSection = selectedDataSet.getSections() != null && selectedDataSet.getSections().size() > 0;
-        
-        if ( displayMode == null || !ALLOWED_FORM_TYPES.contains( displayMode ) )
+        if ( !selectedStateManager.displayModeIsValid( displayMode ) )
         {
-            if ( customDataEntryFormExists )
+            if ( selectedDataSet.hasDataEntryForm() )
             {
                 displayMode = CUSTOM_FORM;
             }
-            else if ( hasSection )
+            else if ( selectedDataSet.hasSections() )
             {
                 displayMode = SECTION_FORM;
             }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java	2010-11-17 18:26:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DataEntryScreenManager.java	2010-11-20 10:53:59 +0000
@@ -33,7 +33,6 @@
 import org.hisp.dhis.dataelement.CalculatedDataElement;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.Section;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.minmax.MinMaxDataElement;
@@ -46,8 +45,6 @@
  */
 public interface DataEntryScreenManager 
 {
-    boolean hasMultiDimensionalDataElement( Section section );
-    
     Collection<Integer> getAllCalculatedDataElements( DataSet dataSet );
     
     Map<CalculatedDataElement, Map<DataElement, Integer>> getNonSavedCalculatedDataElements( DataSet dataSet );

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java	2010-11-17 18:26:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/screen/DefaultDataEntryScreenManager.java	2010-11-20 10:53:59 +0000
@@ -52,7 +52,6 @@
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataset.DataSet;
-import org.hisp.dhis.dataset.Section;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.i18n.I18n;
@@ -107,19 +106,6 @@
     // DataEntryScreenManager implementation
     // -------------------------------------------------------------------------
     
-    public boolean hasMultiDimensionalDataElement( Section section )
-    {
-        for ( DataElement element : section.getDataElements() )
-        {
-            if ( element.isMultiDimensional() )
-            {
-                return true;
-            }
-        }
-
-        return false;
-    }
-
     public Collection<Integer> getAllCalculatedDataElements( DataSet dataSet )
     {
         Collection<Integer> calculatedDataElementIds = new HashSet<Integer>();

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java	2010-11-17 18:26:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/DefaultSelectedStateManager.java	2010-11-20 10:53:59 +0000
@@ -29,6 +29,7 @@
 
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -291,6 +292,18 @@
         return (String) getSession().get( SESSION_KEY_SELECTED_DISPLAY_MODE );
     }
     
+    public boolean displayModeIsValid( String displayMode )
+    {
+        DataSet dataSet = getSelectedDataSet();
+        
+        final Map<String, Boolean> map = new HashMap<String, Boolean>();
+        map.put( CUSTOM_FORM, dataSet.hasDataEntryForm() );
+        map.put( SECTION_FORM, dataSet.hasSections() );
+        map.put( DEFAULT_FORM, true );
+        
+        return displayMode != null && map.containsKey( displayMode ) ? map.get( displayMode ) : false;
+    }
+    
     // -------------------------------------------------------------------------
     // Support methods
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/SelectedStateManager.java'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/SelectedStateManager.java	2010-11-17 18:26:47 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/java/org/hisp/dhis/de/state/SelectedStateManager.java	2010-11-20 10:53:59 +0000
@@ -91,4 +91,6 @@
     void setSelectedDisplayMode( String displayMode );
     
     String getSelectedDisplayMode();
+    
+    boolean displayModeIsValid( String displayMode );
 }

=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2010-11-18 13:11:49 +0000
+++ dhis-2/dhis-web/dhis-web-dataentry/src/main/resources/META-INF/dhis/beans.xml	2010-11-20 10:53:59 +0000
@@ -91,7 +91,6 @@
 		<property name="customValueService" ref="org.hisp.dhis.customvalue.CustomValueService"/>
 		<property name="systemSettingManager" ref="org.hisp.dhis.options.SystemSettingManager" />
 		<property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService"/>
-		<property name="dataEntryScreenManager" ref="org.hisp.dhis.de.screen.DataEntryScreenManager" />
 	</bean>
 
 	<bean id="org.hisp.dhis.de.action.SaveValueAction" class="org.hisp.dhis.de.action.SaveValueAction" scope="prototype">