summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib
diff options
context:
space:
mode:
authorayalaben <Ayala.Benzvi@Amdocs.Com>2018-02-11 11:11:00 +0200
committerayalaben <ayala.benzvi@amdocs.com>2018-02-11 15:27:45 +0200
commitda603323ec3cdf4257707ac1cb4d5d657783ae9f (patch)
treea8e65ce8629da0e56d5ac7fa7993b518d360a761 /openecomp-be/lib/openecomp-item-permissions-lib
parent27fed258bd045e4af8cdc1181ebf3cef8d0822cc (diff)
Delete Item Draft
Change-Id: I13767ab6a7be82ae89f80d50b5857aabe6e55906 Issue-ID: SDC-1014 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-item-permissions-lib')
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java2
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java4
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java11
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java9
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java3
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java186
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java1
7 files changed, 120 insertions, 96 deletions
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java
index 09c8102ef0..8c0008454e 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java
@@ -22,5 +22,5 @@ public interface PermissionsServices {
String getUserItemPermiission(String itemId, String userId);
-
+ void deleteItemPermissions(String itemId);
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java
index a0f51f90bb..ee5e1f3e3a 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java
@@ -17,5 +17,7 @@ public interface ItemPermissionsDao {
void addUserPermission(String itemId, String userId, String permission);
- String getUserItemPermiission(String itemId, String userId);
+ String getUserItemPermission(String itemId, String userId);
+
+ 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/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 e1a9d1c874..8c62aa02fe 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
@@ -38,7 +38,7 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
}
@Override
- public String getUserItemPermiission(String itemId, String userId) {
+ public String getUserItemPermission(String itemId, String userId) {
ResultSet result = accessor.getUserItemPermission(itemId,userId);
if (result.getAvailableWithoutFetching() < 1) {
@@ -47,6 +47,11 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
return result.one().getString(0);
}
+ @Override
+ public void deleteItemPermissions(String itemId) {
+ accessor.deleteItemPermissions(itemId);
+ }
+
@Accessor
interface ItemPermissionsAccessor {
@@ -62,5 +67,9 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
@Query("insert into dox.item_permissions (item_id,user_id,permission) values (?,?,?)")
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 ae40ea8d97..08b51eee86 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
@@ -53,7 +53,7 @@ public class PermissionsServicesImpl implements PermissionsServices {
@Override
public boolean isAllowed(String itemId,String userId,String action) {
- String userPermission = permissionsDao.getUserItemPermiission(itemId,userId);
+ String userPermission = permissionsDao.getUserItemPermission(itemId,userId);
return permissionsRules.isAllowed(userPermission,action);
}
@@ -64,7 +64,12 @@ public class PermissionsServicesImpl implements PermissionsServices {
@Override
public String getUserItemPermiission(String itemId, String userId) {
- return permissionsDao.getUserItemPermiission(itemId,userId);
+ return permissionsDao.getUserItemPermission(itemId,userId);
+ }
+
+ @Override
+ public void deleteItemPermissions(String itemId) {
+ permissionsDao.deleteItemPermissions(itemId);
}
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java
index 4a8f44657e..baafb4a9eb 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java
@@ -27,6 +27,7 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.HttpMethod;
import java.io.IOException;
/**
@@ -63,7 +64,7 @@ public class PermissionsFilter implements Filter {
String method = servletRequest.getMethod();
- if (method.equals("POST") || method.equals("PUT")) {
+ if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)) {
String userId = servletRequest.getHeader("USER_ID");
String itemId = parseItemIdFromPath(servletRequest.getPathInfo());
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<String>
- addedUsersIds,Set<String> 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<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())) {
- HashSet<String> currentOwner = new HashSet<String>();
- currentOwner.add(currentUserId);
+ HashSet<String> currentOwner = new HashSet<>();
+ currentOwner.add(currentUserId);
+
+ PermissionsServicesFactory.getInstance().createInterface()
+ .updateItemPermissions(itemId, PermissionTypes.Contributor.name(),
+ currentOwner, new HashSet<String>());
+ }
+ }
- PermissionsServicesFactory.getInstance().createInterface()
- .updateItemPermissions(itemId,PermissionTypes.Contributor.name(),
- currentOwner,new HashSet<String>());
+ protected void caseCreateItem(String userId, String itemId) {
+ HashSet<String> ownerId = new HashSet<>();
+ ownerId.add(userId);
+ PermissionsServicesFactory.getInstance().createInterface()
+ .updateItemPermissions(itemId, PermissionTypes.Owner.name(), ownerId,
+ new HashSet<String>());
}
- }
-
- protected void caseCreateItem(String userId,String itemId) {
- HashSet<String> ownerId = new HashSet<String>();
- ownerId.add(userId);
- PermissionsServicesFactory.getInstance().createInterface()
- .updateItemPermissions(itemId, PermissionTypes.Owner.name(), ownerId,
- new HashSet<String>());
- }
}
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;
}