Allon Mureinik has uploaded a new change for review.

Change subject: core: Move getEntityPermissions[ForUserAndGroup]
......................................................................

core: Move getEntityPermissions[ForUserAndGroup]

Moved getEntityPermissions and getEntityPermissionsForUserAndGroups from
DbFacade to PermissionsDAO, where they belong.
Tests were moved from DbFacadeDAOTest to PremissionsDAOTest.

Change-Id: I6085afd4eca6bbd0c5f5ab615d6f06cd242f620a
Signed-off-by: Allon Mureinik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HasAdElementReconnectPermissionQuery.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAODbFacadeImpl.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
7 files changed, 97 insertions(+), 83 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/16386/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
index ad3d0b0..2a6d41d 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java
@@ -862,7 +862,7 @@
             final VdcObjectType type) {
         // Grant if there is matching permission in the database:
         final Guid permId =
-                getDbFacade().getEntityPermissions(userId, actionGroup, 
object, type);
+                getDbFacade().getPermissionDao().getEntityPermissions(userId, 
actionGroup, object, type);
         if (permId != null) {
             if (log.isDebugEnabled()) {
                 log.debugFormat("Found permission {0} for user when running 
{1}, on {2} with id {3}",
@@ -910,7 +910,7 @@
             final boolean ignoreEveryone) {
         // Grant if there is matching permission in the database:
         final Guid permId =
-                getDbFacade().getEntityPermissionsForUserAndGroups(userId, 
groupIds, actionGroup, object, type, ignoreEveryone);
+                
getPermissionDAO().getEntityPermissionsForUserAndGroups(userId, groupIds, 
actionGroup, object, type, ignoreEveryone);
         if (permId != null) {
             if (log.isDebugEnabled()) {
                 log.debugFormat("Found permission {0} for user when running 
{1}, on {2} with id {3}",
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HasAdElementReconnectPermissionQuery.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HasAdElementReconnectPermissionQuery.java
index 2c19a8d..283e719 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HasAdElementReconnectPermissionQuery.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HasAdElementReconnectPermissionQuery.java
@@ -15,7 +15,7 @@
 
     @Override
     protected void executeQueryCommand() {
-        Guid perm = 
getDbFacade().getEntityPermissions(getParameters().getAdElementId(),
+        Guid perm = 
getDbFacade().getPermissionDao().getEntityPermissions(getParameters().getAdElementId(),
                 ActionGroup.RECONNECT_TO_VM,
                 getParameters().getObjectId(),
                 VdcObjectType.VM);
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
index 9890f6b..fe1bbaf 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/DbFacade.java
@@ -2,14 +2,12 @@
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import java.sql.Types;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.VdcObjectType;
-import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.BaseDisk;
 import org.ovirt.engine.core.common.businessentities.BusinessEntity;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
@@ -114,7 +112,6 @@
 import org.ovirt.engine.core.utils.log.LogFactory;
 import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.jdbc.core.RowMapper;
-import org.springframework.jdbc.core.SqlOutParameter;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
 import org.springframework.jdbc.core.simple.SimpleJdbcCall;
 
@@ -220,46 +217,6 @@
 
     private CustomMapSqlParameterSource getCustomMapSqlParameterSource() {
         return new CustomMapSqlParameterSource(dbEngineDialect);
-    }
-
-    // tags_vm_map
-    public Guid getEntityPermissions(Guid adElementId, ActionGroup 
actionGroup, Guid objectId,
-            VdcObjectType vdcObjectType) {
-        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource().addValue("user_id", adElementId)
-                .addValue("action_group_id", 
actionGroup.getId()).addValue("object_id", objectId).addValue(
-                        "object_type_id", vdcObjectType.getValue());
-
-        String resultKey = "permission_id";
-        Map<String, Object> dbResults =
-                new 
SimpleJdbcCall(jdbcTemplate).withProcedureName("get_entity_permissions")
-                        .declareParameters(new SqlOutParameter(resultKey, 
Types.VARCHAR))
-                        .execute(parameterSource);
-
-        return dbResults.get(resultKey) != null ? new 
Guid(dbResults.get(resultKey).toString()) : null;
-    }
-
-    public Guid getEntityPermissionsForUserAndGroups(Guid userId,
-            String groupIds,
-            ActionGroup actionGroup,
-            Guid objectId,
-            VdcObjectType vdcObjectType,
-            boolean ignoreEveryone) {
-        MapSqlParameterSource parameterSource =
-                getCustomMapSqlParameterSource().addValue("user_id", userId)
-                        .addValue("group_ids", groupIds)
-                        .addValue("action_group_id", actionGroup.getId())
-                        .addValue("object_id", objectId)
-                        .addValue(
-                                "object_type_id", vdcObjectType.getValue())
-                        .addValue("ignore_everyone", ignoreEveryone);
-
-        String resultKey = "permission_id";
-        Map<String, Object> dbResults =
-                new 
SimpleJdbcCall(jdbcTemplate).withProcedureName("get_entity_permissions_for_user_and_groups")
-                        .declareParameters(new SqlOutParameter(resultKey, 
Types.VARCHAR))
-                        .execute(parameterSource);
-
-        return dbResults.get(resultKey) != null ? new 
Guid(dbResults.get(resultKey).toString()) : null;
     }
 
     public String getEntityNameByIdAndType(Guid objectId, VdcObjectType 
vdcObjectType) {
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAO.java
index d26fb60..501c992 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAO.java
@@ -3,6 +3,7 @@
 import java.util.List;
 
 import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.permissions;
 import org.ovirt.engine.core.compat.Guid;
 
@@ -138,6 +139,15 @@
 
     List<permissions> getTreeForEntity(Guid id, VdcObjectType type, Guid 
userID, boolean isFiltered);
 
+    Guid getEntityPermissions(Guid adElementId, ActionGroup actionGroup, Guid 
objectId, VdcObjectType vdcObjectType);
+
+    Guid getEntityPermissionsForUserAndGroups(Guid userId,
+                                              String groupIds,
+                                              ActionGroup actionGroup,
+                                              Guid objectId,
+                                              VdcObjectType vdcObjectType,
+                                              boolean ignoreEveryone);
+
     /**
      * Removes all permissions for the given entity.
      *
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAODbFacadeImpl.java
index b2943d4..7954a79 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/PermissionDAODbFacadeImpl.java
@@ -2,15 +2,20 @@
 
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Types;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.commons.lang.NotImplementedException;
 import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.RoleType;
 import org.ovirt.engine.core.common.businessentities.permissions;
 import org.ovirt.engine.core.compat.Guid;
 import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.SqlOutParameter;
 import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.simple.SimpleJdbcCall;
 
 /**
  * <code>PermissionsDAODbFacadeImpl</code> provides a concrete implementation 
of {@link PermissionDAO} using code from
@@ -153,6 +158,47 @@
     }
 
     @Override
+    public Guid getEntityPermissions(Guid adElementId, ActionGroup 
actionGroup, Guid objectId,
+                                     VdcObjectType vdcObjectType) {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource().addValue("user_id", adElementId)
+                .addValue("action_group_id", 
actionGroup.getId()).addValue("object_id", objectId).addValue(
+                        "object_type_id", vdcObjectType.getValue());
+
+        String resultKey = "permission_id";
+        Map<String, Object> dbResults =
+                new 
SimpleJdbcCall(jdbcTemplate).withProcedureName("get_entity_permissions")
+                        .declareParameters(new SqlOutParameter(resultKey, 
Types.VARCHAR))
+                        .execute(parameterSource);
+
+        return dbResults.get(resultKey) != null ? new 
Guid(dbResults.get(resultKey).toString()) : null;
+    }
+
+    @Override
+    public Guid getEntityPermissionsForUserAndGroups(Guid userId,
+                                                     String groupIds,
+                                                     ActionGroup actionGroup,
+                                                     Guid objectId,
+                                                     VdcObjectType 
vdcObjectType,
+                                                     boolean ignoreEveryone) {
+        MapSqlParameterSource parameterSource =
+                getCustomMapSqlParameterSource().addValue("user_id", userId)
+                        .addValue("group_ids", groupIds)
+                        .addValue("action_group_id", actionGroup.getId())
+                        .addValue("object_id", objectId)
+                        .addValue(
+                                "object_type_id", vdcObjectType.getValue())
+                        .addValue("ignore_everyone", ignoreEveryone);
+
+        String resultKey = "permission_id";
+        Map<String, Object> dbResults =
+                new 
SimpleJdbcCall(jdbcTemplate).withProcedureName("get_entity_permissions_for_user_and_groups")
+                        .declareParameters(new SqlOutParameter(resultKey, 
Types.VARCHAR))
+                        .execute(parameterSource);
+
+        return dbResults.get(resultKey) != null ? new 
Guid(dbResults.get(resultKey).toString()) : null;
+    }
+
+    @Override
     public void save(permissions permission) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
                 .addValue("ad_element_id", permission.getad_element_id())
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
index fa9d22d..5171e66 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/DbFacadeDAOTest.java
@@ -2,7 +2,6 @@
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -14,7 +13,6 @@
 
 import org.junit.Test;
 import org.ovirt.engine.core.common.VdcObjectType;
-import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.BaseDisk;
 import org.ovirt.engine.core.common.businessentities.Bookmark;
 import org.ovirt.engine.core.common.businessentities.DbUser;
@@ -313,39 +311,4 @@
         String name = network.getName();
         assertTrue(name.equals(dbFacade.getEntityNameByIdAndType(NETWORK_ID, 
VdcObjectType.Network)));
     }
-
-    @Test
-    public void testGetEntityPermissions() {
-        // Should not return null since the user has the relevant permission
-        
assertNotNull(dbFacade.getEntityPermissions(DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS,
-                ActionGroup.VM_BASIC_OPERATIONS,
-                VMT_ID,
-                VdcObjectType.VM));
-
-        // Should return null since the user does not has the relevant 
permission
-        
assertNull(dbFacade.getEntityPermissions(DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS,
-                ActionGroup.CREATE_TEMPLATE,
-                VMT_ID,
-                VdcObjectType.VM));
-    }
-
-    @Test
-    public void testGetEntityPermissionsByUserAndGroups() {
-        // Should not return null since the user has the relevant permission
-        
assertNotNull(dbFacade.getEntityPermissionsForUserAndGroups(Guid.newGuid(),
-                DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS.toString(),
-                ActionGroup.VM_BASIC_OPERATIONS,
-                VMT_ID,
-                VdcObjectType.VM,
-                false));
-
-        // Should return null since the user does not has the relevant 
permission
-        
assertNull(dbFacade.getEntityPermissionsForUserAndGroups(Guid.newGuid(),
-                DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS.toString(),
-                ActionGroup.CREATE_TEMPLATE,
-                VMT_ID,
-                VdcObjectType.VM,
-                false));
-    }
-
 }
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
index be8bada..b65eec2 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/PermissionDAOTest.java
@@ -13,6 +13,7 @@
 
 import org.junit.Test;
 import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.businessentities.ActionGroup;
 import org.ovirt.engine.core.common.businessentities.permissions;
 import org.ovirt.engine.core.compat.Guid;
 
@@ -32,6 +33,9 @@
     private static final Guid USER_ENTITY_ID = new 
Guid("9bf7c640-b620-456f-a550-0348f366544a");
     private static final Guid ROLE_ENTITY_ID = new 
Guid("119caae6-5c1b-4a82-9858-dd9e5d2e1400");
     private static final Guid VDS_GROUP_ID = new 
Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1");
+
+    private static final Guid DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS =
+            new Guid("88D4301A-17AF-496C-A793-584640853D4B");
 
     private PermissionDAO dao;
     private permissions new_permissions;
@@ -510,6 +514,40 @@
         assertTrue(result.isEmpty());
     }
 
+    @Test
+    public void testGetEntityPermissions() {
+        // Should not return null since the user has the relevant permission
+        
assertNotNull(dao.getEntityPermissions(DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS,
+                ActionGroup.VM_BASIC_OPERATIONS,
+                VM_TEMPLATE_ENTITY_ID,
+                VdcObjectType.VM));
+
+        // Should return null since the user does not has the relevant 
permission
+        
assertNull(dao.getEntityPermissions(DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS,
+                ActionGroup.CREATE_TEMPLATE,
+                VM_TEMPLATE_ENTITY_ID,
+                VdcObjectType.VM));
+    }
+
+    @Test
+    public void testGetEntityPermissionsByUserAndGroups() {
+        // Should not return null since the user has the relevant permission
+        assertNotNull(dao.getEntityPermissionsForUserAndGroups(Guid.newGuid(),
+                DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS.toString(),
+                ActionGroup.VM_BASIC_OPERATIONS,
+                VM_TEMPLATE_ENTITY_ID,
+                VdcObjectType.VM,
+                false));
+
+        // Should return null since the user does not has the relevant 
permission
+        assertNull(dao.getEntityPermissionsForUserAndGroups(Guid.newGuid(),
+                DIRECTORY_ELEMENT_ID_WITH_BASIC_PERMISSIONS.toString(),
+                ActionGroup.CREATE_TEMPLATE,
+                VM_TEMPLATE_ENTITY_ID,
+                VdcObjectType.VM,
+                false));
+    }
+
     /**
      * Ensures that saving a permission works as expected.
      */


-- 
To view, visit http://gerrit.ovirt.org/16386
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6085afd4eca6bbd0c5f5ab615d6f06cd242f620a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to