From da603323ec3cdf4257707ac1cb4d5d657783ae9f Mon Sep 17 00:00:00 2001 From: ayalaben Date: Sun, 11 Feb 2018 11:11:00 +0200 Subject: Delete Item Draft Change-Id: I13767ab6a7be82ae89f80d50b5857aabe6e55906 Issue-ID: SDC-1014 Signed-off-by: ayalaben --- .../itempermissions/impl/PermissionsRulesImpl.java | 186 +++++++++++---------- .../impl/types/PermissionActionTypes.java | 1 + 2 files changed, 97 insertions(+), 90 deletions(-) (limited to 'openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src') 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 1f56c1038a..f80379aa91 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 @@ -19,109 +19,115 @@ import static org.openecomp.sdc.itempermissions.errors.PermissionsErrorMessages. public class PermissionsRulesImpl implements PermissionsRules { - @Override - public boolean isAllowed(String permission, String action) { + @Override + public boolean isAllowed(String permission, String action) { - if (permission == null) { - return false; - } - try { - PermissionTypes.valueOf(permission); - } catch (IllegalArgumentException ex) { - throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_PERMISSION_TYPE).build()); - } + if (permission == null) { + return false; + } + try { + PermissionTypes.valueOf(permission); + } catch (IllegalArgumentException ex) { + throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_PERMISSION_TYPE).build()); + } - try { - switch (PermissionActionTypes.valueOf(action)) { - case Create_Item: - return true; - - case Edit_Item: - if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals - (PermissionTypes.Owner.name())) { - return true; - } - break; - case Commit_Item: - if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals - (PermissionTypes.Owner.name())) { - return true; + try { + switch (PermissionActionTypes.valueOf(action)) { + case Create_Item: + return true; + + case Edit_Item: + if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals + (PermissionTypes.Owner.name())) { + return true; + } + break; + case Commit_Item: + if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals + (PermissionTypes.Owner.name())) { + return true; + } + break; + case Delete_Item: + if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals + (PermissionTypes.Owner.name())) { + return true; + } + break; + + case Change_Item_Permissions: + if (permission.equals(PermissionTypes.Owner.name())) { + return true; + } + break; + + case Submit_Item: + if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals + (PermissionTypes.Owner.name())) { + return true; + } + break; + + default: + return false; + } + } catch (IllegalArgumentException ex) { + throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_ACTION_TYPE).build()); } - break; - - case Change_Item_Permissions: - if (permission.equals(PermissionTypes.Owner.name())) { - return true; - } - break; - - case Submit_Item: - if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals - (PermissionTypes.Owner.name())) { - return true; - } - break; - - default: - return false; - } - } catch (IllegalArgumentException ex) { - throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_ACTION_TYPE).build()); - } - return false; - } + return false; + } - @Override - public void executeAction(String itemId, String userId, String action) { - try { - switch (PermissionActionTypes.valueOf(action)) { - case Create_Item: - caseCreateItem(userId,itemId); - break; + @Override + public void executeAction(String itemId, String userId, String action) { + try { + switch (PermissionActionTypes.valueOf(action)) { + case Create_Item: + caseCreateItem(userId, itemId); + break; - case Change_Item_Permissions: - break; + case Change_Item_Permissions: + break; - case Edit_Item: - break; + case Edit_Item: + break; - case Submit_Item: - break; + case Submit_Item: + break; - default: - } - } catch (IllegalArgumentException ex) { - throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_ACTION_TYPE).build()); - } - } - - @Override - public void updatePermission(String itemId,String currentUserId, String permission, Set - addedUsersIds,Set removedUsersIds) { - try { - PermissionTypes.valueOf(permission); - } catch (IllegalArgumentException ex) { - throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_PERMISSION_TYPE).build()); + default: + } + } catch (IllegalArgumentException ex) { + throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_ACTION_TYPE).build()); + } } - if (permission.equals(PermissionTypes.Owner.name())) { + @Override + public void updatePermission(String itemId, String currentUserId, String permission, Set + addedUsersIds, Set removedUsersIds) { + try { + PermissionTypes.valueOf(permission); + } catch (IllegalArgumentException ex) { + throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_PERMISSION_TYPE).build()); + } + + if (permission.equals(PermissionTypes.Owner.name())) { - HashSet currentOwner = new HashSet(); - currentOwner.add(currentUserId); + HashSet currentOwner = new HashSet<>(); + currentOwner.add(currentUserId); + + PermissionsServicesFactory.getInstance().createInterface() + .updateItemPermissions(itemId, PermissionTypes.Contributor.name(), + currentOwner, new HashSet()); + } + } - PermissionsServicesFactory.getInstance().createInterface() - .updateItemPermissions(itemId,PermissionTypes.Contributor.name(), - currentOwner,new HashSet()); + protected void caseCreateItem(String userId, String itemId) { + HashSet ownerId = new HashSet<>(); + ownerId.add(userId); + PermissionsServicesFactory.getInstance().createInterface() + .updateItemPermissions(itemId, PermissionTypes.Owner.name(), ownerId, + new HashSet()); } - } - - protected void caseCreateItem(String userId,String itemId) { - HashSet ownerId = new HashSet(); - ownerId.add(userId); - PermissionsServicesFactory.getInstance().createInterface() - .updateItemPermissions(itemId, PermissionTypes.Owner.name(), ownerId, - new HashSet()); - } } diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java index 3d1b8a82d7..3911f2ad7b 100644 --- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java @@ -9,6 +9,7 @@ public enum PermissionActionTypes { Change_Item_Permissions, Edit_Item, Commit_Item, + Delete_Item, Submit_Item; } -- cgit 1.2.3-korg