← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15586: add mergeWith to Dashboard

 

------------------------------------------------------------
revno: 15586
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-06-07 16:26:31 +0200
message:
  add mergeWith to Dashboard
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.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/dashboard/Dashboard.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java	2014-06-07 14:22:06 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java	2014-06-07 14:26:31 +0000
@@ -28,19 +28,19 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.hisp.dhis.common.BaseIdentifiableObject;
-import org.hisp.dhis.common.DxfNamespaces;
-import org.hisp.dhis.common.view.DetailedView;
-
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonView;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.view.DetailedView;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * @author Lars Helge Overland
@@ -50,7 +50,7 @@
     extends BaseIdentifiableObject
 {
     public static final int MAX_ITEMS = 40;
-    
+
     private List<DashboardItem> items = new ArrayList<>();
 
     // -------------------------------------------------------------------------
@@ -77,7 +77,7 @@
      * is equal to current item index or if attempting to move an item one
      * position to the right (pointless operation).
      *
-     * @param uid the uid of the item to move.
+     * @param uid      the uid of the item to move.
      * @param position the new index position of the item.
      * @return true if the operation lead to a modification of order, false otherwise.
      */
@@ -90,16 +90,16 @@
 
         int index = items.indexOf( new DashboardItem( uid ) );
 
-        if ( index == -1 || index == position || ( index + 1 ) == position )
+        if ( index == -1 || index == position || (index + 1) == position )
         {
             return false; // Not found, already at position or pointless move
         }
 
         DashboardItem item = items.get( index );
 
-        index = position < index ? ( index + 1 ) : index; // New index after move
+        index = position < index ? (index + 1) : index; // New index after move
 
-        items.add( position, item ); // Add item at position        
+        items.add( position, item ); // Add item at position
         items.remove( index ); // Remove item at previous index
 
         return true;
@@ -173,8 +173,8 @@
 
     @JsonProperty( value = "items" )
     @JsonView( { DetailedView.class } )
-    @JacksonXmlElementWrapper( localName = "dashboardItems", namespace = DxfNamespaces.DXF_2_0)
-    @JacksonXmlProperty( localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlElementWrapper( localName = "dashboardItems", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0 )
     public List<DashboardItem> getItems()
     {
         return items;
@@ -184,4 +184,18 @@
     {
         this.items = items;
     }
+
+    @Override
+    public void mergeWith( IdentifiableObject other )
+    {
+        super.mergeWith( other );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            Dashboard dashboard = (Dashboard) other;
+
+            items.clear();
+            items.addAll( dashboard.getItems() );
+        }
+    }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2014-06-07 14:26:31 +0000
@@ -28,10 +28,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
@@ -43,17 +45,14 @@
 import org.hisp.dhis.reporttable.ReportTable;
 import org.hisp.dhis.user.User;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 /**
  * Represents an item in the dashboard. An item can represent an embedded object
  * or represent links to other objects.
- * 
+ *
  * @author Lars Helge Overland
  */
 @JacksonXmlRootElement( localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0 )
@@ -86,7 +85,7 @@
     private List<Document> resources = new ArrayList<Document>();
 
     private Boolean messages;
-    
+
     // -------------------------------------------------------------------------
     // Constructors
     // -------------------------------------------------------------------------
@@ -141,12 +140,12 @@
         {
             return TYPE_MESSAGES;
         }
-        
+
         return null;
     }
-    
+
     /**
-     * Returns the actual item object if this dashboard item represents an 
+     * Returns the actual item object if this dashboard item represents an
      * embedded item and not links to items.
      */
     public IdentifiableObject getEmbeddedItem()
@@ -163,12 +162,12 @@
         {
             return reportTable;
         }
-        
+
         return null;
     }
-    
+
     /**
-     * Returns a list of the actual item objects if this dashboard item 
+     * Returns a list of the actual item objects if this dashboard item
      * represents a list of objects and not an embedded item.
      */
     public List<? extends IdentifiableObject> getLinkItems()
@@ -189,7 +188,7 @@
         {
             return resources;
         }
-        
+
         return null;
     }