summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-22 15:33:06 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-24 06:59:47 +0000
commitd378c37fbd1ecec7b43394926f1ca32a695e07de (patch)
tree5c8a085f8732f980d871d966ac49361644efa698 /openecomp-be/lib/openecomp-item-permissions-lib
parenta6ae7294ecd336d7e88f915710b08e2658eaee00 (diff)
Reformat openecomp-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1
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/PermissionsRules.java8
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRulesFactory.java10
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java18
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServicesFactory.java10
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java12
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDaoFactory.java7
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDao.java6
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDaoFactory.java1
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessages.java22
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessagesBuilder.java31
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/notifications/NotificationConstants.java3
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/type/ItemPermissionsEntity.java19
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java1
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java23
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java40
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java15
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java1
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java19
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java24
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesFactoryImpl.java14
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java79
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java5
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionTypes.java10
23 files changed, 136 insertions, 242 deletions
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRules.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRules.java
index b15ad10d7c..49d5ab4053 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRules.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRules.java
@@ -26,11 +26,9 @@ import java.util.Set;
*/
public interface PermissionsRules {
- boolean isAllowed(String userId,String action);
+ boolean isAllowed(String userId, String action);
- void executeAction(String itemId, String userId, String action);
-
- void updatePermission(String itemId,String currentUserId, String permission,Set<String>
- addedUsersIds, Set<String> removedUsersIds);
+ void executeAction(String itemId, String userId, String action);
+ void updatePermission(String itemId, String currentUserId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds);
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRulesFactory.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRulesFactory.java
index a4afa2a5c0..b7efc852b6 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRulesFactory.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRulesFactory.java
@@ -25,11 +25,9 @@ import org.openecomp.core.factory.api.AbstractFactory;
/**
* Created by ayalaben on 6/26/2017
*/
-public abstract class PermissionsRulesFactory extends
- AbstractComponentFactory<PermissionsRules> {
-
- public static PermissionsRulesFactory getInstance() {
- return AbstractFactory.getInstance(PermissionsRulesFactory.class);
- }
+public abstract class PermissionsRulesFactory extends AbstractComponentFactory<PermissionsRules> {
+ public static PermissionsRulesFactory getInstance() {
+ return AbstractFactory.getInstance(PermissionsRulesFactory.class);
+ }
}
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 72ae535b20..fe690df7bb 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
@@ -15,29 +15,27 @@
*/
package org.openecomp.sdc.itempermissions;
-import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
-
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
/**
* Created by ayalaben on 6/22/2017
*/
public interface PermissionsServices {
- Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
+ Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
- Set<String> listUserPermittedItems(String userId, String permission);
+ Set<String> listUserPermittedItems(String userId, String permission);
- void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds);
+ void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds);
- boolean isAllowed(String itemId, String userId, String action);
+ boolean isAllowed(String itemId, String userId, String action);
- void execute(String itemId, String userId, String action);
+ void execute(String itemId, String userId, String action);
- Optional<String> getUserItemPermission(String itemId, String userId);
+ Optional<String> getUserItemPermission(String itemId, String userId);
- void deleteItemPermissions(String itemId);
+ 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/PermissionsServicesFactory.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServicesFactory.java
index 36ed52e440..4ccfee061a 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServicesFactory.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServicesFactory.java
@@ -25,11 +25,9 @@ import org.openecomp.core.factory.api.AbstractFactory;
/**
* Created by ayalaben on 6/22/2017.
*/
-public abstract class PermissionsServicesFactory extends
- AbstractComponentFactory<PermissionsServices> {
-
- public static PermissionsServicesFactory getInstance() {
- return AbstractFactory.getInstance(PermissionsServicesFactory.class);
- }
+public abstract class PermissionsServicesFactory extends AbstractComponentFactory<PermissionsServices> {
+ public static PermissionsServicesFactory getInstance() {
+ return AbstractFactory.getInstance(PermissionsServicesFactory.class);
+ }
}
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 ea2211df85..4bd2adf7e9 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
@@ -15,23 +15,21 @@
*/
package org.openecomp.sdc.itempermissions.dao;
-import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
-
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
/**
* Created by ayalaben on 6/18/2017.
*/
public interface ItemPermissionsDao {
- Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
+ Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
- void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds);
+ void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds);
- Optional<String> getUserItemPermission(String itemId, String userId);
+ Optional<String> getUserItemPermission(String itemId, String userId);
- void deleteItemPermissions(String itemId);
+ 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/ItemPermissionsDaoFactory.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDaoFactory.java
index 9e46f9309f..d192b4e5c6 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDaoFactory.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDaoFactory.java
@@ -27,8 +27,7 @@ import org.openecomp.core.factory.api.AbstractFactory;
*/
public abstract class ItemPermissionsDaoFactory extends AbstractComponentFactory<ItemPermissionsDao> {
- public static ItemPermissionsDaoFactory getInstance() {
- return AbstractFactory.getInstance(ItemPermissionsDaoFactory.class);
- }
-
+ public static ItemPermissionsDaoFactory getInstance() {
+ return AbstractFactory.getInstance(ItemPermissionsDaoFactory.class);
+ }
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDao.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDao.java
index 990fde9f84..56c81b0153 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDao.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDao.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao;
import java.util.Set;
@@ -22,8 +21,5 @@ public interface UserPermissionsDao {
Set<String> listUserPermittedItems(String userId, String permission);
- void updatePermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds);
-
+ void updatePermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds);
}
-
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDaoFactory.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDaoFactory.java
index 582fa23c0d..8ac89eba68 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDaoFactory.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/UserPermissionsDaoFactory.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao;
import org.openecomp.core.factory.api.AbstractComponentFactory;
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessages.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessages.java
index 1b8a36d0d4..c616884fc9 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessages.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessages.java
@@ -24,19 +24,19 @@ package org.openecomp.sdc.itempermissions.errors;
*/
public enum PermissionsErrorMessages {
- NO_PERMISSION_FOR_USER("The user is not permitted to edit this item"),
- USER_NOT_OWNER_SUBMIT("The user must be the owner to submit the item"),
- INVALID_PERMISSION_TYPE("Invalid permission type"),
- INVALID_ACTION_TYPE("Invalid action type");
+ NO_PERMISSION_FOR_USER("The user is not permitted to edit this item"),
+ USER_NOT_OWNER_SUBMIT("The user must be the owner to submit the item"),
+ INVALID_PERMISSION_TYPE("Invalid permission type"),
+ INVALID_ACTION_TYPE("Invalid action type");
- private String errorMessage;
+ private String errorMessage;
- PermissionsErrorMessages(String errorMessage) {
- this.errorMessage = errorMessage;
- }
+ PermissionsErrorMessages(String errorMessage) {
+ this.errorMessage = errorMessage;
+ }
- public String getErrorMessage() {
- return errorMessage;
- }
+ public String getErrorMessage() {
+ return errorMessage;
+ }
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessagesBuilder.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessagesBuilder.java
index 638a7869d6..d092f5b52d 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessagesBuilder.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessagesBuilder.java
@@ -26,23 +26,22 @@ import org.openecomp.sdc.common.errors.ErrorCode;
* Created by ayalaben on 6/28/2017
*/
public class PermissionsErrorMessagesBuilder {
- public static final String PERMISSIONS_ERROR= "PERMISSIONS_ERROR";
- private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
- /**
- * Instantiates a new Submit uncompleted license model error builder.
- *
- * @param error
- */
- public PermissionsErrorMessagesBuilder(PermissionsErrorMessages error) {
- builder.withId(PERMISSIONS_ERROR);
- builder.withCategory(ErrorCategory.APPLICATION);
- builder.withMessage(error.getErrorMessage());
- }
-
- public ErrorCode build() {
- return builder.build();
- }
+ public static final String PERMISSIONS_ERROR = "PERMISSIONS_ERROR";
+ private final ErrorCode.ErrorCodeBuilder builder = new ErrorCode.ErrorCodeBuilder();
+ /**
+ * Instantiates a new Submit uncompleted license model error builder.
+ *
+ * @param error
+ */
+ public PermissionsErrorMessagesBuilder(PermissionsErrorMessages error) {
+ builder.withId(PERMISSIONS_ERROR);
+ builder.withCategory(ErrorCategory.APPLICATION);
+ builder.withMessage(error.getErrorMessage());
+ }
+ public ErrorCode build() {
+ return builder.build();
+ }
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/notifications/NotificationConstants.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/notifications/NotificationConstants.java
index 88cd8de4c2..dcc7365aba 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/notifications/NotificationConstants.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/notifications/NotificationConstants.java
@@ -24,7 +24,8 @@ package org.openecomp.sdc.itempermissions.notifications;
* @since July 10, 2017
*/
public class NotificationConstants {
- public static final String PERMISSION_CHANGED= "PermissionChanged";
+
+ public static final String PERMISSION_CHANGED = "PermissionChanged";
public static final String PERMISSION_ITEM = "permission";
public static final String ITEM_ID_PROP = "itemId";
public static final String ITEM_NAME_PROP = "itemName";
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/type/ItemPermissionsEntity.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/type/ItemPermissionsEntity.java
index 81ad393607..638cd853bb 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/type/ItemPermissionsEntity.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/type/ItemPermissionsEntity.java
@@ -30,21 +30,18 @@ import lombok.Setter;
/**
* Created by ayalaben on 6/18/2017.
*/
-
@Getter
@Setter
@NoArgsConstructor
@Table(keyspace = "dox", name = "item_permissions")
public class ItemPermissionsEntity {
- @PartitionKey
- @Column(name = "item_id")
- private String itemId;
-
- @ClusteringColumn
- @Column(name = "user_id")
- private String userId;
-
- @Column(name = "permission")
- private String permission;
+ @PartitionKey
+ @Column(name = "item_id")
+ private String itemId;
+ @ClusteringColumn
+ @Column(name = "user_id")
+ private String userId;
+ @Column(name = "permission")
+ private String permission;
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java
index 6fd83c2233..89db18b30b 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java
@@ -22,7 +22,6 @@ package org.openecomp.sdc.itempermissions.dao.impl;
import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory;
-
/**
* Created by ayalaben on 6/18/2017.
*/
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 c9c4198081..34c4f39395 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
@@ -13,18 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao.impl;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.mapping.Result;
import com.datastax.driver.mapping.annotations.Accessor;
import com.datastax.driver.mapping.annotations.Query;
-
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
-
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
@@ -36,8 +33,7 @@ import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
- private static ItemPermissionsAccessor accessor =
- noSqlDb.getMappingManager().createAccessor(ItemPermissionsAccessor.class);
+ private static ItemPermissionsAccessor accessor = noSqlDb.getMappingManager().createAccessor(ItemPermissionsAccessor.class);
@Override
public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) {
@@ -45,22 +41,17 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
}
@Override
- public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds) {
+ public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds) {
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));
+ removedUsersIds.stream().filter(
+ userId -> getUserItemPermission(itemId, userId).map(userPermissionOnItem -> userPermissionOnItem.equals(permission)).orElse(false))
+ .forEach(userId -> accessor.deletePermission(itemId, userId));
}
@Override
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));
+ return result.getAvailableWithoutFetching() < 1 ? Optional.empty() : Optional.of(result.one().getString(0));
}
@Override
@@ -68,7 +59,6 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
accessor.deleteItemPermissions(itemId);
}
-
@Accessor
interface ItemPermissionsAccessor {
@@ -86,6 +76,5 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
@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 d0e41d8c91..7e9d289731 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
@@ -13,13 +13,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao.impl;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
-
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
import org.openecomp.sdc.itempermissions.PermissionsRules;
import org.openecomp.sdc.itempermissions.PermissionsServices;
@@ -27,29 +25,22 @@ import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao;
import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
-
/**
* Created by ayalaben on 6/22/2017.
*/
public class PermissionsServicesImpl implements PermissionsServices {
+ private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
private ItemPermissionsDao itemPermissionsDao;
-
private UserPermissionsDao userPermissionsDao;
-
private PermissionsRules permissionsRules;
- private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
-
- public PermissionsServicesImpl(PermissionsRules permissionsRules,
- ItemPermissionsDao itemPermissionsDao,
- UserPermissionsDao userPermissionsDao) {
+ public PermissionsServicesImpl(PermissionsRules permissionsRules, ItemPermissionsDao itemPermissionsDao, UserPermissionsDao userPermissionsDao) {
this.itemPermissionsDao = itemPermissionsDao;
this.permissionsRules = permissionsRules;
this.userPermissionsDao = userPermissionsDao;
}
-
@Override
public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) {
return itemPermissionsDao.listItemPermissions(itemId);
@@ -61,30 +52,18 @@ public class PermissionsServicesImpl implements PermissionsServices {
}
@Override
- public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds) {
-
- String currentUserId = SessionContextProviderFactory.getInstance()
- .createInterface().get().getUser().getUserId();
-
+ public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds) {
+ String currentUserId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
permissionsRules.executeAction(itemId, currentUserId, CHANGE_PERMISSIONS);
-
- permissionsRules.updatePermission(itemId, currentUserId, permission, addedUsersIds,
- removedUsersIds);
-
- itemPermissionsDao.updateItemPermissions(itemId, permission,
- addedUsersIds, removedUsersIds);
-
- userPermissionsDao.updatePermissions(itemId, permission,
- addedUsersIds, removedUsersIds);
-
+ permissionsRules.updatePermission(itemId, currentUserId, permission, addedUsersIds, removedUsersIds);
+ itemPermissionsDao.updateItemPermissions(itemId, permission, addedUsersIds, removedUsersIds);
+ userPermissionsDao.updatePermissions(itemId, permission, addedUsersIds, removedUsersIds);
}
@Override
public boolean isAllowed(String itemId, String userId, String action) {
- return itemPermissionsDao.getUserItemPermission(itemId, userId)
- .map(permission -> permissionsRules.isAllowed(permission, action))
- .orElse(false);
+ return itemPermissionsDao.getUserItemPermission(itemId, userId).map(permission -> permissionsRules.isAllowed(permission, action))
+ .orElse(false);
}
@Override
@@ -101,5 +80,4 @@ public class PermissionsServicesImpl implements PermissionsServices {
public void deleteItemPermissions(String itemId) {
itemPermissionsDao.deleteItemPermissions(itemId);
}
-
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java
index d009f62270..b86d10ceb1 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java
@@ -24,14 +24,13 @@ import org.openecomp.sdc.itempermissions.dao.UserPermissionsDaoFactory;
/**
* Created by ayalaben on 6/22/2017
*/
-public class PrmissionsServicesFactoryImpl extends PermissionsServicesFactory {
+public class PrmissionsServicesFactoryImpl extends PermissionsServicesFactory {
- private static final PermissionsServices INSTANCE =
- new PermissionsServicesImpl(PermissionsRulesFactory.getInstance().createInterface(),
- ItemPermissionsDaoFactory.getInstance().createInterface(), UserPermissionsDaoFactory.getInstance().createInterface());
+ private static final PermissionsServices INSTANCE = new PermissionsServicesImpl(PermissionsRulesFactory.getInstance().createInterface(),
+ ItemPermissionsDaoFactory.getInstance().createInterface(), UserPermissionsDaoFactory.getInstance().createInterface());
- @Override
- public PermissionsServices createInterface() {
- return INSTANCE;
- }
+ @Override
+ public PermissionsServices createInterface() {
+ return INSTANCE;
+ }
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java
index 4c23743ea5..d60013db77 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao.impl;
import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao;
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java
index 8609f2f4a8..25645ab483 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java
@@ -13,17 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.dao.impl;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.mapping.annotations.Accessor;
import com.datastax.driver.mapping.annotations.Query;
-
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
-
import org.openecomp.core.nosqldb.api.NoSqlDb;
import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao;
@@ -31,9 +28,7 @@ import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao;
public class UserPermissionsDaoImpl implements UserPermissionsDao {
private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
- private static UserPermissionsAccessor accessor =
- noSqlDb.getMappingManager().createAccessor(UserPermissionsAccessor.class);
-
+ private static UserPermissionsAccessor accessor = noSqlDb.getMappingManager().createAccessor(UserPermissionsAccessor.class);
@Override
public Set<String> listUserPermittedItems(String userId, String permission) {
@@ -46,14 +41,10 @@ public class UserPermissionsDaoImpl implements UserPermissionsDao {
}
@Override
- public void updatePermissions(String itemId, String permission, Set<String> addedUsersIds,
- Set<String> removedUsersIds) {
+ public void updatePermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds) {
Set<String> itemSet = Collections.singleton(itemId);
-
- addedUsersIds.forEach(userId ->
- accessor.addItem(itemSet, userId, permission));
- removedUsersIds.forEach(userId ->
- accessor.removeItem(itemSet, userId, permission));
+ addedUsersIds.forEach(userId -> accessor.addItem(itemSet, userId, permission));
+ removedUsersIds.forEach(userId -> accessor.removeItem(itemSet, userId, permission));
}
@Accessor
@@ -67,7 +58,5 @@ public class UserPermissionsDaoImpl implements UserPermissionsDao {
@Query("update dox.user_permission_items set item_list=item_list-? WHERE user_id = ? AND permission = ?")
void removeItem(Set<String> items, String userId, String permission);
-
}
-
}
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 1edfad3bbc..66b999951e 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
@@ -13,9 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdc.itempermissions.servlet;
+import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -27,8 +27,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.HttpMethod;
import javax.ws.rs.core.Response;
-
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.openecomp.sdc.common.errors.ErrorCode;
import org.openecomp.sdc.common.errors.ErrorCodeAndMessage;
import org.openecomp.sdc.common.errors.Messages;
@@ -43,9 +41,9 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
public class PermissionsFilter implements Filter {
private static final Logger LOGGER = LoggerFactory.getLogger(PermissionsFilter.class);
- private final PermissionsServices permissionsServices;
private static final String IRRELEVANT_REQUEST = "Irrelevant_Request";
private static final String EDIT_ITEM = "Edit_Item";
+ private final PermissionsServices permissionsServices;
public PermissionsFilter() {
this(PermissionsServicesFactory.getInstance().createInterface());
@@ -62,10 +60,8 @@ public class PermissionsFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
- throws IOException, ServletException {
-
- if ((servletRequest instanceof HttpServletRequest)
- && isRelevant((HttpServletRequest) servletRequest, servletResponse)) {
+ throws IOException, ServletException {
+ if ((servletRequest instanceof HttpServletRequest) && isRelevant((HttpServletRequest) servletRequest, servletResponse)) {
filterChain.doFilter(servletRequest, servletResponse);
}
}
@@ -73,19 +69,15 @@ public class PermissionsFilter implements Filter {
private boolean isRelevant(HttpServletRequest servletRequest, ServletResponse servletResponse) throws IOException {
String method = servletRequest.getMethod();
if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)) {
-
String userId = servletRequest.getHeader("USER_ID");
String itemId = parseItemIdFromPath(servletRequest.getPathInfo());
-
if (!itemId.equals(IRRELEVANT_REQUEST) && !permissionsServices.isAllowed(itemId, userId, EDIT_ITEM)) {
((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_FORBIDDEN);
- servletResponse.getWriter().print(buildResponse(Response.Status.FORBIDDEN,
- Messages.PERMISSIONS_ERROR.getErrorMessage(),
- Messages.PERMISSIONS_ERROR.name()));
+ servletResponse.getWriter()
+ .print(buildResponse(Response.Status.FORBIDDEN, Messages.PERMISSIONS_ERROR.getErrorMessage(), Messages.PERMISSIONS_ERROR.name()));
return false;
}
}
-
return true;
}
@@ -104,9 +96,7 @@ public class PermissionsFilter implements Filter {
}
private String buildResponse(Response.Status status, String message, String id) {
- ErrorCode errorCode = new ErrorCode.ErrorCodeBuilder()
- .withId(id)
- .withMessage(message).build();
+ ErrorCode errorCode = new ErrorCode.ErrorCodeBuilder().withId(id).withMessage(message).build();
return objectToJsonString(new ErrorCodeAndMessage(status, errorCode));
}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesFactoryImpl.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesFactoryImpl.java
index 0562078a6e..c7007a4644 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesFactoryImpl.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesFactoryImpl.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.itempermissions.impl;
import org.openecomp.sdc.itempermissions.PermissionsRules;
@@ -28,9 +27,8 @@ import org.openecomp.sdc.itempermissions.PermissionsRulesFactory;
*/
public class PermissionsRulesFactoryImpl extends PermissionsRulesFactory {
- @Override
- public PermissionsRules createInterface() {
- return new PermissionsRulesImpl();
- }
-
+ @Override
+ public PermissionsRules createInterface() {
+ return new PermissionsRulesImpl();
+ }
}
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 222ed000ae..2b039c7c93 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,6 +15,12 @@
*/
package org.openecomp.sdc.itempermissions.impl;
+import static org.openecomp.sdc.itempermissions.errors.PermissionsErrorMessages.INVALID_ACTION_TYPE;
+import static org.openecomp.sdc.itempermissions.errors.PermissionsErrorMessages.INVALID_PERMISSION_TYPE;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.commons.collections.CollectionUtils;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.itempermissions.PermissionsRules;
@@ -24,22 +30,13 @@ import org.openecomp.sdc.itempermissions.errors.PermissionsErrorMessagesBuilder;
import org.openecomp.sdc.itempermissions.impl.types.PermissionActionTypes;
import org.openecomp.sdc.itempermissions.impl.types.PermissionTypes;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-import static org.openecomp.sdc.itempermissions.errors.PermissionsErrorMessages.INVALID_ACTION_TYPE;
-import static org.openecomp.sdc.itempermissions.errors.PermissionsErrorMessages.INVALID_PERMISSION_TYPE;
-
/**
* Created by ayalaben on 6/26/2017.
*/
public class PermissionsRulesImpl implements PermissionsRules {
-
@Override
public boolean isAllowed(String permission, String action) {
-
if (permission == null) {
return false;
}
@@ -48,35 +45,29 @@ public class PermissionsRulesImpl implements PermissionsRules {
} 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:
case Commit_Item:
case Delete_Item:
case Submit_Item:
- if (permission.equals(PermissionTypes.Contributor.name()) || permission.equals
- (PermissionTypes.Owner.name())) {
+ 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;
-
default:
return false;
}
} catch (IllegalArgumentException ex) {
throw new CoreException(new PermissionsErrorMessagesBuilder(INVALID_ACTION_TYPE).build());
}
-
return false;
}
@@ -87,16 +78,12 @@ public class PermissionsRulesImpl implements PermissionsRules {
case Create_Item:
caseCreateItem(userId, itemId);
break;
-
case Change_Item_Permissions:
break;
-
case Edit_Item:
break;
-
case Submit_Item:
break;
-
default:
}
} catch (IllegalArgumentException ex) {
@@ -104,46 +91,36 @@ 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());
+ @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 (isOwnerAdded(permission, addedUsersIds)) {
+ handleCurrentOwner(itemId, currentUserId);
+ }
}
- 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 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
+ 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);
}
- 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<>();
ownerId.add(userId);
PermissionsServicesFactory.getInstance().createInterface()
- .updateItemPermissions(itemId, PermissionTypes.Owner.name(), ownerId,
- new HashSet<>());
+ .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 e0d03459a5..34c2128a5d 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
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,7 +17,6 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.itempermissions.impl.types;
/**
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionTypes.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionTypes.java
index 1e0acdfe99..67cd837652 100644
--- a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionTypes.java
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionTypes.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -17,13 +17,9 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.openecomp.sdc.itempermissions.impl.types;
/**
* Created by ayalaben on 6/26/2017.
*/
-public enum PermissionTypes {
- Owner,
- Contributor
-}
+public enum PermissionTypes {Owner, Contributor}