summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core')
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java27
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java32
2 files changed, 32 insertions, 27 deletions
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java
index 87a9949468..6421c283f3 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java
@@ -25,6 +25,7 @@ import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
import java.util.Collection;
+import java.util.Optional;
import java.util.Set;
/**
@@ -43,23 +44,25 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
@Override
public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
Set<String> removedUsersIds) {
- addedUsersIds.forEach(userId -> accessor.addPermission(itemId,userId,permission));
- removedUsersIds.forEach(userId -> accessor.deletePermission(itemId,userId));
+ addedUsersIds.forEach(userId -> accessor.addPermission(itemId, userId, permission));
+ removedUsersIds.stream()
+ .filter(userId -> getUserItemPermission(itemId, userId)
+ .map(userPermissionOnItem -> userPermissionOnItem.equals(permission))
+ .orElse(false))
+ .forEach(userId -> accessor.deletePermission(itemId, userId));
}
@Override
- public String getUserItemPermission(String itemId, String userId) {
-
- ResultSet result = accessor.getUserItemPermission(itemId,userId);
- if (result.getAvailableWithoutFetching() < 1) {
- return null;
- }
- return result.one().getString(0);
+ public Optional<String> getUserItemPermission(String itemId, String userId) {
+ ResultSet result = accessor.getUserItemPermission(itemId, userId);
+ return result.getAvailableWithoutFetching() < 1
+ ? Optional.empty()
+ : Optional.of(result.one().getString(0));
}
@Override
public void deleteItemPermissions(String itemId) {
- accessor.deleteItemPermissions(itemId);
+ accessor.deleteItemPermissions(itemId);
}
@@ -69,13 +72,13 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
Result<ItemPermissionsEntity> getItemPermissions(String itemId);
@Query("select permission from dox.item_permissions WHERE item_id = ? AND user_id=?")
- ResultSet getUserItemPermission(String itemId,String userId);
+ ResultSet getUserItemPermission(String itemId, String userId);
@Query("delete from dox.item_permissions where item_id = ? and user_id = ?")
void deletePermission(String itemId, String userId);
@Query("insert into dox.item_permissions (item_id,user_id,permission) values (?,?,?)")
- void addPermission(String itemId,String userId, String permission);
+ void addPermission(String itemId, String userId, String permission);
@Query("delete from dox.item_permissions where item_id=?")
void deleteItemPermissions(String itemId);
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java
index 608102916e..ec914b1530 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java
@@ -23,6 +23,7 @@ import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao;
import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
import java.util.Collection;
+import java.util.Optional;
import java.util.Set;
@@ -40,7 +41,8 @@ public class PermissionsServicesImpl implements PermissionsServices {
private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
public PermissionsServicesImpl(PermissionsRules permissionsRules,
- ItemPermissionsDao itemPermissionsDao,UserPermissionsDao userPermissionsDao) {
+ ItemPermissionsDao itemPermissionsDao,
+ UserPermissionsDao userPermissionsDao) {
this.itemPermissionsDao = itemPermissionsDao;
this.permissionsRules = permissionsRules;
this.userPermissionsDao = userPermissionsDao;
@@ -54,7 +56,7 @@ public class PermissionsServicesImpl implements PermissionsServices {
@Override
public Set<String> listUserPermittedItems(String userId, String permission) {
- return userPermissionsDao.listUserPermittedItems(userId,permission);
+ return userPermissionsDao.listUserPermittedItems(userId, permission);
}
@Override
@@ -62,36 +64,36 @@ public class PermissionsServicesImpl implements PermissionsServices {
Set<String> removedUsersIds) {
String currentUserId = SessionContextProviderFactory.getInstance()
- .createInterface().get().getUser().getUserId();
+ .createInterface().get().getUser().getUserId();
- permissionsRules.executeAction(itemId,currentUserId,CHANGE_PERMISSIONS);
+ permissionsRules.executeAction(itemId, currentUserId, CHANGE_PERMISSIONS);
- permissionsRules.updatePermission(itemId,currentUserId,permission,addedUsersIds,
- removedUsersIds);
+ permissionsRules.updatePermission(itemId, currentUserId, permission, addedUsersIds,
+ removedUsersIds);
itemPermissionsDao.updateItemPermissions(itemId, permission,
- addedUsersIds, removedUsersIds);
+ addedUsersIds, removedUsersIds);
userPermissionsDao.updatePermissions(itemId, permission,
- addedUsersIds, removedUsersIds);
+ addedUsersIds, removedUsersIds);
}
@Override
- public boolean isAllowed(String itemId,String userId,String action) {
-
- String userPermission = itemPermissionsDao.getUserItemPermission(itemId,userId);
- return permissionsRules.isAllowed(userPermission,action);
+ public boolean isAllowed(String itemId, String userId, String action) {
+ return itemPermissionsDao.getUserItemPermission(itemId, userId)
+ .map(permission -> permissionsRules.isAllowed(permission, action))
+ .orElse(false);
}
@Override
- public void execute(String itemId,String userId,String action) {
+ public void execute(String itemId, String userId, String action) {
permissionsRules.executeAction(itemId, userId, action);
}
@Override
- public String getUserItemPermiission(String itemId, String userId) {
- return itemPermissionsDao.getUserItemPermission(itemId,userId);
+ public Optional<String> getUserItemPermission(String itemId, String userId) {
+ return itemPermissionsDao.getUserItemPermission(itemId, userId);
}
@Override