ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject ambari git commit: AMBARI-11149. Widgets: attempted to move/add/delete a widget causes exception.
Date Thu, 14 May 2015 23:07:29 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 3d9072733 -> 501afc0f5


AMBARI-11149. Widgets: attempted to move/add/delete a widget causes exception.


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/501afc0f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/501afc0f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/501afc0f

Branch: refs/heads/trunk
Commit: 501afc0f58c65eaeccf6c388ae6100c2c3d31048
Parents: 3d90727
Author: Siddharth Wagle <swagle@hortonworks.com>
Authored: Thu May 14 16:07:19 2015 -0700
Committer: Siddharth Wagle <swagle@hortonworks.com>
Committed: Thu May 14 16:07:19 2015 -0700

----------------------------------------------------------------------
 .../internal/WidgetLayoutResourceProvider.java  |  9 ++++++++
 .../entities/WidgetLayoutUserWidgetEntity.java  |  8 +++----
 .../WidgetLayoutResourceProviderTest.java       | 23 ++++++++++++++++----
 3 files changed, 31 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/501afc0f/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProvider.java
index 8f068d5..174a106 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProvider.java
@@ -286,6 +286,15 @@ public class WidgetLayoutResourceProvider extends AbstractControllerResourceProv
 
           Set widgetsSet = (LinkedHashSet) propertyMap.get(WIDGETLAYOUT_WIDGETS_PROPERTY_ID);
 
+          //Remove old relations from widget entities
+          for (WidgetLayoutUserWidgetEntity widgetLayoutUserWidgetEntity : entity.getListWidgetLayoutUserWidgetEntity())
{
+            widgetLayoutUserWidgetEntity.getWidget().getListWidgetLayoutUserWidgetEntity()
+                    .remove(widgetLayoutUserWidgetEntity);
+            widgetDAO.merge(widgetLayoutUserWidgetEntity.getWidget());
+          }
+          entity.setListWidgetLayoutUserWidgetEntity(new LinkedList<WidgetLayoutUserWidgetEntity>());
+          widgetLayoutDAO.merge(entity);
+
           List<WidgetLayoutUserWidgetEntity> widgetLayoutUserWidgetEntityList = new
LinkedList<WidgetLayoutUserWidgetEntity>();
           int order=0;
           for (Object widgetObject : widgetsSet) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/501afc0f/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/WidgetLayoutUserWidgetEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/WidgetLayoutUserWidgetEntity.java
b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/WidgetLayoutUserWidgetEntity.java
index 1d6e1b5..dbae31b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/WidgetLayoutUserWidgetEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/WidgetLayoutUserWidgetEntity.java
@@ -17,6 +17,7 @@
  */
 package org.apache.ambari.server.orm.entities;
 
+import javax.persistence.CascadeType;
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.Id;
@@ -43,7 +44,7 @@ public class WidgetLayoutUserWidgetEntity {
   @JoinColumn(name = "widget_layout_id", referencedColumnName = "id")
   private WidgetLayoutEntity widgetLayout;
 
-  @ManyToOne
+  @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
   @JoinColumn(name = "widget_id", referencedColumnName = "id")
   private WidgetEntity widget;
 
@@ -97,10 +98,7 @@ public class WidgetLayoutUserWidgetEntity {
 
     WidgetLayoutUserWidgetEntity that = (WidgetLayoutUserWidgetEntity) o;
 
-    if (widgetLayout.getId() != that.widgetLayout.getId()) return false;
-    if (widget.getId() != that.widget.getId()) return false;
-
-    return true;
+    return (widgetLayout.equals(that.widgetLayout) && widget.equals(that.widget));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/ambari/blob/501afc0f/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProviderTest.java
index 1a9e230..8184d34 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/WidgetLayoutResourceProviderTest.java
@@ -221,7 +221,15 @@ public class WidgetLayoutResourceProviderTest {
     dao.create(capture(entityCapture));
     expectLastCall();
 
-    replay(amc, clusters, cluster, dao);
+    WidgetEntity widgetEntity = new WidgetEntity();
+    widgetEntity.setId(1L);
+    widgetEntity.setListWidgetLayoutUserWidgetEntity(new ArrayList<WidgetLayoutUserWidgetEntity>());
+    WidgetEntity widgetEntity2 = new WidgetEntity();
+    widgetEntity2.setId(2L);
+    widgetEntity2.setListWidgetLayoutUserWidgetEntity(new ArrayList<WidgetLayoutUserWidgetEntity>());
+    expect(widgetDAO.findById(1L)).andReturn(widgetEntity).atLeastOnce();
+
+    replay(amc, clusters, cluster, dao, widgetDAO);
 
     Map<String, Object> requestProps = new HashMap<String, Object>();
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_CLUSTER_NAME_PROPERTY_ID,
"c1");
@@ -231,6 +239,9 @@ public class WidgetLayoutResourceProviderTest {
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_USERNAME_PROPERTY_ID, "admin");
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_SCOPE_PROPERTY_ID, "CLUSTER");
     Set widgetsInfo = new LinkedHashSet();
+    Map<String, String> widget = new HashMap<String, String>();
+    widget.put("id","1");
+    widgetsInfo.add(widget);
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgetsInfo);
 
     Request request = PropertyHelper.getCreateRequest(
@@ -255,15 +266,19 @@ public class WidgetLayoutResourceProviderTest {
     String oldLayoutName = entity.getLayoutName();
     String oldScope = entity.getScope();
 
-    resetToStrict(dao);
+    resetToStrict(dao, widgetDAO);
     expect(dao.findById(1L)).andReturn(entity).anyTimes();
     expect(dao.merge((WidgetLayoutEntity) anyObject())).andReturn(entity).anyTimes();
-    replay(dao);
+    expect(widgetDAO.merge(widgetEntity)).andReturn(widgetEntity).anyTimes();
+    expect(widgetDAO.findById(2L)).andReturn(widgetEntity2).anyTimes();
+    replay(dao, widgetDAO);
 
     requestProps = new HashMap<String, Object>();
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_LAYOUT_NAME_PROPERTY_ID, "layout_name_new");
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_SCOPE_PROPERTY_ID, "USER");
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_ID_PROPERTY_ID, "1");
+    widget.put("id","2");
+    widgetsInfo.add(widget);
     requestProps.put(WidgetLayoutResourceProvider.WIDGETLAYOUT_WIDGETS_PROPERTY_ID, widgetsInfo);
 
     request = PropertyHelper.getUpdateRequest(requestProps, null);
@@ -273,7 +288,7 @@ public class WidgetLayoutResourceProviderTest {
     Assert.assertFalse(oldLayoutName.equals(entity.getLayoutName()));
     Assert.assertFalse(oldScope.equals(entity.getScope()));
 
-    verify(amc, clusters, cluster, dao);
+    verify(amc, clusters, cluster, dao, widgetDAO);
   }
 
   /**


Mime
View raw message