diff options
author | 2018-05-23 11:38:51 +0300 | |
---|---|---|
committer | 2018-05-23 09:09:03 +0000 | |
commit | 66b0d09b07a0d16daacbb4c08da8cfe7e55bc28b (patch) | |
tree | f94de8fab9b97733fcc1a70fbf4fd4ba5eb008fc /openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java | |
parent | 134783cf629d515f35df39d1e0a583ecf8ffdc56 (diff) |
Fix bug in change item owner
Change-Id: I200387d41f95d61ad0f6be6663b8d8fac198aa90
Issue-ID: SDC-1355
Signed-off-by: talig <talig@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java')
-rw-r--r-- | openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java index feb3d59f7f..2ab9326f6a 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java @@ -15,8 +15,10 @@ */ package org.openecomp.sdc.itempermissions.impl; +import org.apache.commons.collections.CollectionUtils; import org.openecomp.sdc.common.errors.CoreException; import org.openecomp.sdc.itempermissions.PermissionsRules; +import org.openecomp.sdc.itempermissions.PermissionsServices; import org.openecomp.sdc.itempermissions.PermissionsServicesFactory; import org.openecomp.sdc.itempermissions.errors.PermissionsErrorMessagesBuilder; import org.openecomp.sdc.itempermissions.impl.types.PermissionActionTypes; @@ -118,33 +120,39 @@ public class PermissionsRulesImpl implements PermissionsRules { } } - @Override - public void updatePermission(String itemId, String currentUserId, String permission, Set<String> - addedUsersIds, Set<String> removedUsersIds) { - try { - PermissionTypes.valueOf(permission); - } catch (IllegalArgumentException ex) { - throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_PERMISSION_TYPE).build()); - } - - if (permission.equals(PermissionTypes.Owner.name())) { - makeCurrentUserContributor(itemId,currentUserId); - } + @Override + public void updatePermission(String itemId, String currentUserId, String permission, Set<String> + addedUsersIds, Set<String> removedUsersIds) { + try { + PermissionTypes.valueOf(permission); + } catch (IllegalArgumentException ex) { + throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_PERMISSION_TYPE).build()); } - private void makeCurrentUserContributor(String itemId, String currentUserId) { - - String currentPermission = PermissionsServicesFactory.getInstance().createInterface(). - getUserItemPermiission(itemId,currentUserId); - - if(currentPermission != null) { - - PermissionsServicesFactory.getInstance().createInterface() - .updateItemPermissions(itemId, PermissionTypes.Contributor.name(), - Collections.singleton(currentUserId), new HashSet<>()); + if (isOwnerAdded(permission, addedUsersIds)) { + handleCurrentOwner(itemId, currentUserId); + } + } + + private boolean isOwnerAdded(String permission, Set<String> addedUsersIds) { + return permission.equals(PermissionTypes.Owner.name()) && + CollectionUtils.isNotEmpty(addedUsersIds); + } + + private void handleCurrentOwner(String itemId, String currentUserId) { + PermissionsServices permissionsServices = + PermissionsServicesFactory.getInstance().createInterface(); + if (!permissionsServices.getUserItemPermission(itemId, currentUserId).isPresent()) { + return; // no current owner - first owner addition } -} + Set<String> currentUserSet = Collections.singleton(currentUserId); + permissionsServices + .updateItemPermissions(itemId, PermissionTypes.Contributor.name(), currentUserSet, + new HashSet<>()); + permissionsServices.updateItemPermissions(itemId, PermissionTypes.Owner.name(), new HashSet<>(), + currentUserSet); + } private void caseCreateItem(String userId, String itemId) { HashSet<String> ownerId = new HashSet<>(); |