aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib
diff options
context:
space:
mode:
authortalig <talig@amdocs.com>2017-12-20 14:30:43 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-21 11:12:33 +0000
commit8e9c0653dd6c6862123c9609ae34e1206d86456e (patch)
tree5eeef00ec0677133baa439ca8d7ffd7aca4804b6 /openecomp-be/lib/openecomp-item-permissions-lib
parent785ebcc95de3e064e843bec04ba7a209d854fc7c (diff)
Add collaboration feature
Issue-ID: SDC-767 Change-Id: I14fb4c1f54086ed03a56a7ff7fab9ecd40381795 Signed-off-by: talig <talig@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/pom.xml32
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRules.java17
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRulesFactory.java16
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java26
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServicesFactory.java16
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java21
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDaoFactory.java15
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessages.java23
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessagesBuilder.java29
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/notifications/NotificationConstants.java14
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/type/ItemPermissionsEntity.java50
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml63
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java19
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java66
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java70
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java21
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java72
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/resources/factoryConfiguration.json4
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/test/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImplTest.java111
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/pom.xml27
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesFactoryImpl.java16
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java126
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java14
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionTypes.java9
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/resources/factoryConfiguration.json3
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java101
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/resources/logback.xml15
-rw-r--r--openecomp-be/lib/openecomp-item-permissions-lib/pom.xml24
28 files changed, 1020 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/pom.xml b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/pom.xml
new file mode 100644
index 0000000000..f69f3041a7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/pom.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+ <modelVersion>4.0.0</modelVersion>
+
+
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-item-permissions-lib</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>openecomp-item-permissions-api</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-nosqldb-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-facade-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ </dependencies>
+
+</project> \ No newline at end of file
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
new file mode 100644
index 0000000000..b5a119e8ed
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRules.java
@@ -0,0 +1,17 @@
+package org.openecomp.sdc.itempermissions;
+
+import java.util.Set;
+
+/**
+ * Created by ayalaben on 6/22/2017.
+ */
+public interface PermissionsRules {
+
+ 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);
+
+}
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
new file mode 100644
index 0000000000..c3e0672939
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsRulesFactory.java
@@ -0,0 +1,16 @@
+package org.openecomp.sdc.itempermissions;
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+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);
+ }
+
+}
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
new file mode 100644
index 0000000000..09c8102ef0
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServices.java
@@ -0,0 +1,26 @@
+package org.openecomp.sdc.itempermissions;
+
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * Created by ayalaben on 6/22/2017
+ */
+public interface PermissionsServices {
+
+ Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
+
+ void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
+ Set<String> removedUsersIds);
+
+ boolean isAllowed(String itemId,String userId,String action);
+
+ void execute(String itemId,String userId,String action);
+
+ String getUserItemPermiission(String itemId, String userId);
+
+
+
+}
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
new file mode 100644
index 0000000000..97769bcc82
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/PermissionsServicesFactory.java
@@ -0,0 +1,16 @@
+package org.openecomp.sdc.itempermissions;
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+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);
+ }
+
+}
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
new file mode 100644
index 0000000000..a0f51f90bb
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDao.java
@@ -0,0 +1,21 @@
+package org.openecomp.sdc.itempermissions.dao;
+
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * Created by ayalaben on 6/18/2017.
+ */
+public interface ItemPermissionsDao {
+
+ Collection<ItemPermissionsEntity> listItemPermissions(String itemId);
+
+ void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
+ Set<String> removedUsersIds);
+
+ void addUserPermission(String itemId, String userId, String permission);
+
+ String getUserItemPermiission(String itemId, String userId);
+}
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
new file mode 100644
index 0000000000..95d541e028
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/dao/ItemPermissionsDaoFactory.java
@@ -0,0 +1,15 @@
+package org.openecomp.sdc.itempermissions.dao;
+
+import org.openecomp.core.factory.api.AbstractComponentFactory;
+import org.openecomp.core.factory.api.AbstractFactory;
+
+/**
+ * Created by ayalaben on 6/18/2017.
+ */
+public abstract class ItemPermissionsDaoFactory extends AbstractComponentFactory<ItemPermissionsDao> {
+
+ 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/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
new file mode 100644
index 0000000000..a3fb9a14a8
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessages.java
@@ -0,0 +1,23 @@
+package org.openecomp.sdc.itempermissions.errors;
+
+/**
+ * Created by ayalaben on 6/28/2017
+ */
+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");
+
+ private String errorMessage;
+
+ PermissionsErrorMessages(String errorMessage) {
+ this.errorMessage = 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
new file mode 100644
index 0000000000..f0c13d9cda
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/errors/PermissionsErrorMessagesBuilder.java
@@ -0,0 +1,29 @@
+package org.openecomp.sdc.itempermissions.errors;
+
+import org.openecomp.sdc.common.errors.ErrorCategory;
+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();
+ }
+
+
+}
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
new file mode 100644
index 0000000000..d4235cd6c6
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/notifications/NotificationConstants.java
@@ -0,0 +1,14 @@
+package org.openecomp.sdc.itempermissions.notifications;
+
+/**
+ * @author avrahamg
+ * @since July 10, 2017
+ */
+public class NotificationConstants {
+ 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";
+ public static final String PERMISSION_GRANTED = "granted";
+ public static final String PERMISSION_USER = "userId";
+}
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
new file mode 100644
index 0000000000..22ff43778c
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-api/src/main/java/org/openecomp/sdc/itempermissions/type/ItemPermissionsEntity.java
@@ -0,0 +1,50 @@
+package org.openecomp.sdc.itempermissions.type;
+
+import com.datastax.driver.mapping.annotations.ClusteringColumn;
+import com.datastax.driver.mapping.annotations.Column;
+import com.datastax.driver.mapping.annotations.PartitionKey;
+import com.datastax.driver.mapping.annotations.Table;
+
+/**
+ * Created by ayalaben on 6/18/2017.
+ */
+
+@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;
+
+
+ public String getItemId() {
+ return itemId;
+ }
+
+ public void setItemId(String itemId) {
+ this.itemId = itemId;
+ }
+
+ public String getUserId() {
+ return userId;
+ }
+
+ public void setUserId(String userId) {
+ this.userId = userId;
+ }
+
+ public String getPermission() {
+ return permission;
+ }
+
+ public void setPermission(String permission) {
+ this.permission = permission;
+ }
+}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml
new file mode 100644
index 0000000000..a420b23f6e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/pom.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-item-permissions-lib</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>openecomp-item-permissions-core</artifactId>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-session-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-item-permissions-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-facade-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ <dependency>
+ <groupId>org.openecomp.sdc.core</groupId>
+ <artifactId>openecomp-nosqldb-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-notification-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <version>RELEASE</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>RELEASE</version>
+ </dependency>
+
+ </dependencies>
+
+</project> \ No newline at end of file
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
new file mode 100644
index 0000000000..87c0338c25
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoFactoryImpl.java
@@ -0,0 +1,19 @@
+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.
+ */
+public class ItemPermissionsDaoFactoryImpl extends ItemPermissionsDaoFactory {
+
+ private static ItemPermissionsDao INSTANCE =new ItemPermissionsDaoImpl();
+
+ @Override
+ public ItemPermissionsDao 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/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
new file mode 100644
index 0000000000..e1a9d1c874
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsDaoImpl.java
@@ -0,0 +1,66 @@
+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 org.openecomp.core.nosqldb.api.NoSqlDb;
+import org.openecomp.core.nosqldb.factory.NoSqlDbFactory;
+import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
+
+import java.util.Collection;
+import java.util.Set;
+
+/**
+ * Created by ayalaben on 6/20/2017.
+ */
+public class ItemPermissionsDaoImpl implements ItemPermissionsDao {
+ private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface();
+ private static ItemPermissionsAccessor accessor =
+ noSqlDb.getMappingManager().createAccessor(ItemPermissionsAccessor.class);
+
+ @Override
+ public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) {
+ return accessor.getItemPermissions(itemId).all();
+ }
+
+ @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));
+ }
+
+ @Override
+ public void addUserPermission(String itemId, String userId, String permission){
+ accessor.addPermission(itemId,userId,permission);
+ }
+
+ @Override
+ public String getUserItemPermiission(String itemId, String userId) {
+
+ ResultSet result = accessor.getUserItemPermission(itemId,userId);
+ if (result.getAvailableWithoutFetching() < 1) {
+ return null;
+ }
+ return result.one().getString(0);
+ }
+
+
+ @Accessor
+ interface ItemPermissionsAccessor {
+ @Query("select * from dox.item_permissions WHERE item_id = ?")
+ Result<ItemPermissionsEntity> getItemPermissions(String itemId);
+
+ @Query("select permission from dox.item_permissions WHERE item_id = ? AND user_id=?")
+ 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);
+
+ }
+}
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
new file mode 100644
index 0000000000..ae40ea8d97
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImpl.java
@@ -0,0 +1,70 @@
+package org.openecomp.sdc.itempermissions.dao.impl;
+
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.itempermissions.PermissionsRules;
+import org.openecomp.sdc.itempermissions.PermissionsServices;
+import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
+
+import java.util.Collection;
+import java.util.Set;
+
+
+/**
+ * Created by ayalaben on 6/22/2017.
+ */
+public class PermissionsServicesImpl implements PermissionsServices {
+
+ private ItemPermissionsDao permissionsDao;
+
+ private PermissionsRules permissionsRules;
+
+ private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
+
+ public PermissionsServicesImpl(PermissionsRules permissionsRules,
+ ItemPermissionsDao permissionsDao) {
+ this.permissionsDao = permissionsDao;
+ this.permissionsRules = permissionsRules;
+ }
+
+
+ @Override
+ public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) {
+ return permissionsDao.listItemPermissions(itemId);
+ }
+
+ @Override
+ 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);
+
+ permissionsDao.updateItemPermissions(itemId, permission,
+ addedUsersIds, removedUsersIds);
+
+ }
+
+ @Override
+ public boolean isAllowed(String itemId,String userId,String action) {
+
+ String userPermission = permissionsDao.getUserItemPermiission(itemId,userId);
+ return permissionsRules.isAllowed(userPermission,action);
+ }
+
+ @Override
+ public void execute(String itemId,String userId,String action) {
+ permissionsRules.executeAction(itemId, userId, action);
+ }
+
+ @Override
+ public String getUserItemPermiission(String itemId, String userId) {
+ return permissionsDao.getUserItemPermiission(itemId,userId);
+ }
+
+}
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
new file mode 100644
index 0000000000..34532cb384
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/PrmissionsServicesFactoryImpl.java
@@ -0,0 +1,21 @@
+package org.openecomp.sdc.itempermissions.dao.impl;
+
+import org.openecomp.sdc.itempermissions.PermissionsRulesFactory;
+import org.openecomp.sdc.itempermissions.PermissionsServices;
+import org.openecomp.sdc.itempermissions.PermissionsServicesFactory;
+import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory;
+
+/**
+ * Created by ayalaben on 6/22/2017
+ */
+public class PrmissionsServicesFactoryImpl extends PermissionsServicesFactory {
+
+ private static final PermissionsServices INSTANCE =
+ new org.openecomp.sdc.itempermissions.dao.impl.PermissionsServicesImpl(PermissionsRulesFactory.getInstance().createInterface(),
+ ItemPermissionsDaoFactory.getInstance().createInterface());
+
+ @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/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
new file mode 100644
index 0000000000..21acc07733
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/servlet/PermissionsFilter.java
@@ -0,0 +1,72 @@
+package org.openecomp.sdc.itempermissions.servlet;
+
+import org.openecomp.sdc.itempermissions.PermissionsServices;
+import org.openecomp.sdc.itempermissions.PermissionsServicesFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Created by ayalaben on 6/27/2017.
+ */
+public class PermissionsFilter implements Filter {
+
+ private final PermissionsServices permissionsServices;
+ public static final String IRRELEVANT_REQUEST = "Irrelevant_Request";
+ public static final String EDIT_ITEM = "Edit_Item";
+
+ public PermissionsFilter() {
+ this.permissionsServices = PermissionsServicesFactory.getInstance().createInterface();
+ }
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+
+ }
+
+ @Override
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
+ FilterChain filterChain) throws IOException, ServletException {
+
+ if (servletRequest instanceof HttpServletRequest) {
+ if (((HttpServletRequest) servletRequest).getMethod().equals("POST")
+ || ((HttpServletRequest) servletRequest).getMethod().equals("PUT")) {
+
+ String userId = ((HttpServletRequest) servletRequest).getHeader("USER_ID");
+ String itemId = parseItemIdFromPath(((HttpServletRequest) servletRequest).getPathInfo());
+ if ( ! itemId.equals(IRRELEVANT_REQUEST)) {
+ if ( ! permissionsServices.isAllowed(itemId,userId,EDIT_ITEM)) {
+ ((HttpServletResponse) servletResponse).setStatus(HttpServletResponse.SC_FORBIDDEN);
+ servletResponse.getWriter().print("Permissions Error. The user does not have " +
+ "permission to perform" +
+ " this action.");
+ return;
+ }
+ }
+ }
+ }
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ private String parseItemIdFromPath(String pathInfo) {
+ String[] tokens = pathInfo.split("/");
+ if (tokens.length < 4) {
+ return IRRELEVANT_REQUEST;
+ } else {
+ return tokens[3];
+ }
+ }
+
+ @Override
+ public void destroy() {
+
+ }
+}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/resources/factoryConfiguration.json
new file mode 100644
index 0000000000..d23948437f
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/resources/factoryConfiguration.json
@@ -0,0 +1,4 @@
+{
+ "org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory": "org.openecomp.sdc.itempermissions.dao.impl.ItemPermissionsDaoFactoryImpl",
+"org.openecomp.sdc.itempermissions.PermissionsServicesFactory" : "org.openecomp.sdc.itempermissions.dao.impl.PrmissionsServicesFactoryImpl"
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/test/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImplTest.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/test/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImplTest.java
new file mode 100644
index 0000000000..0a87c29f50
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/test/java/org/openecomp/sdc/itempermissions/dao/impl/PermissionsServicesImplTest.java
@@ -0,0 +1,111 @@
+package org.openecomp.sdc.itempermissions.dao.impl;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.openecomp.sdc.common.session.SessionContextProviderFactory;
+import org.openecomp.sdc.itempermissions.PermissionsRules;
+import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
+import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * Created by ayalaben on 7/9/2017
+ */
+public class PermissionsServicesImplTest {
+
+ private static final String ITEM1_ID = "1";
+ private static final String PERMISSION = "Owner";
+ private static final String USER2_ID = "testUser2";
+ private static final String USER1_ID = "testUser1";
+ private static final String ACTION_SUBMIT = "Submit_Item";
+ private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
+
+ static {
+ SessionContextProviderFactory.getInstance().createInterface().create("testUser1");
+ }
+
+ @Mock
+ private ItemPermissionsDao permissionsDaoMock;
+ @Mock
+ private PermissionsRules permissionsRules;
+ @InjectMocks
+ @Spy
+ private PermissionsServicesImpl permissionsServices;
+
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testListItemPermissionsWhenNone() {
+ Collection<ItemPermissionsEntity> permissions =
+ permissionsServices.listItemPermissions(ITEM1_ID);
+ Assert.assertEquals(permissions.size(), 0);
+ }
+
+
+ @Test
+ public void testListItemPermissions(){
+ doReturn(Arrays.asList(
+ createPermissionEntity(ITEM1_ID, USER1_ID, PERMISSION),
+ createPermissionEntity(ITEM1_ID, USER2_ID, PERMISSION)))
+ .when(permissionsDaoMock).listItemPermissions(anyObject());
+
+ Collection<ItemPermissionsEntity> actual =
+ permissionsServices.listItemPermissions(ITEM1_ID);
+ Assert.assertEquals(actual.size(), 2);
+ }
+
+
+ @Test
+ public void testIsAllowed(){
+ when(permissionsDaoMock.getUserItemPermiission(ITEM1_ID,USER1_ID)).thenReturn(PERMISSION);
+ when(permissionsRules.isAllowed(PERMISSION,ACTION_SUBMIT)).thenReturn(true);
+
+ Boolean result = permissionsServices.isAllowed(ITEM1_ID,USER1_ID,ACTION_SUBMIT);
+
+ Assert.assertTrue(result);
+
+ }
+ @Test
+ public void testUpdatePermissions(){
+
+ Set<String> addedUsers = new HashSet<String>();
+ addedUsers.add(USER2_ID);
+
+ permissionsServices.updateItemPermissions(ITEM1_ID,PERMISSION,addedUsers,
+ new HashSet<String>());
+
+ verify(permissionsRules).executeAction(ITEM1_ID,USER1_ID,CHANGE_PERMISSIONS);
+ verify(permissionsRules).updatePermission(ITEM1_ID,USER1_ID,PERMISSION,addedUsers,new HashSet<String>());
+ verify(permissionsDaoMock).updateItemPermissions(ITEM1_ID,PERMISSION,addedUsers,new
+ HashSet<String>());
+ }
+
+
+ public static ItemPermissionsEntity createPermissionEntity(String itemId, String
+ userId, String permission) {
+ ItemPermissionsEntity permissionsEntity = new ItemPermissionsEntity();
+ permissionsEntity.setItemId(itemId);
+ permissionsEntity.setUserId(userId);
+ permissionsEntity.setPermission(permission);
+ return permissionsEntity;
+ }
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/pom.xml b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/pom.xml
new file mode 100644
index 0000000000..0a3bf6eb9d
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-item-permissions-lib</artifactId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+ <artifactId>openecomp-item-permissions-impl</artifactId>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-item-permissions-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-item-permissions-core</artifactId>
+ <version>${project.version}</version>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+</project> \ No newline at end of file
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
new file mode 100644
index 0000000000..c74907ce03
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesFactoryImpl.java
@@ -0,0 +1,16 @@
+package org.openecomp.sdc.itempermissions.impl;
+
+import org.openecomp.sdc.itempermissions.PermissionsRules;
+import org.openecomp.sdc.itempermissions.PermissionsRulesFactory;
+
+/**
+ * Created by ayalaben on 6/26/2017.
+ */
+public class PermissionsRulesFactoryImpl extends PermissionsRulesFactory {
+
+ @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
new file mode 100644
index 0000000000..22d81a73dc
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImpl.java
@@ -0,0 +1,126 @@
+package org.openecomp.sdc.itempermissions.impl;
+
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.itempermissions.PermissionsRules;
+import org.openecomp.sdc.itempermissions.PermissionsServicesFactory;
+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.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;
+ }
+ 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;
+ }
+ break;
+
+ case Change_Item_Permissions:
+ if (permission.equals(PermissionTypes.Owner.name())) {
+ return true;
+ }
+ break;
+
+ case Submit_Item:
+ 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;
+ }
+
+ @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 Edit_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());
+ }
+
+ if (permission.equals(PermissionTypes.Owner.name())) {
+
+ HashSet<String> currentOwner = new HashSet<String>();
+ currentOwner.add(currentUserId);
+
+ PermissionsServicesFactory.getInstance().createInterface()
+ .updateItemPermissions(itemId,PermissionTypes.Contributor.name(),
+ currentOwner,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
new file mode 100644
index 0000000000..3d1b8a82d7
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionActionTypes.java
@@ -0,0 +1,14 @@
+package org.openecomp.sdc.itempermissions.impl.types;
+
+/**
+ * Created by ayalaben on 6/26/2017
+ */
+public enum PermissionActionTypes {
+
+ Create_Item,
+ Change_Item_Permissions,
+ Edit_Item,
+ Commit_Item,
+ Submit_Item;
+
+}
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
new file mode 100644
index 0000000000..e3c93c5e6e
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/java/org/openecomp/sdc/itempermissions/impl/types/PermissionTypes.java
@@ -0,0 +1,9 @@
+package org.openecomp.sdc.itempermissions.impl.types;
+
+/**
+ * Created by ayalaben on 6/26/2017.
+ */
+public enum PermissionTypes {
+ Owner,
+ Contributor
+}
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/resources/factoryConfiguration.json
new file mode 100644
index 0000000000..a3d3dae5c5
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main/resources/factoryConfiguration.json
@@ -0,0 +1,3 @@
+{
+ "org.openecomp.sdc.itempermissions.PermissionsRulesFactory": "org.openecomp.sdc.itempermissions.impl.PermissionsRulesFactoryImpl"
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java
new file mode 100644
index 0000000000..635a0b2a25
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/java/org/openecomp/sdc/itempermissions/impl/PermissionsRulesImplTest.java
@@ -0,0 +1,101 @@
+package org.openecomp.sdc.itempermissions.impl;
+
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.openecomp.sdc.common.errors.CoreException;
+import org.openecomp.sdc.itempermissions.dao.impl.PermissionsServicesImpl;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.HashSet;
+
+
+/**
+ * Created by ayalaben on 7/10/2017
+ */
+public class PermissionsRulesImplTest {
+
+ private static final String ITEM1_ID = "1";
+ private static final String USER1_ID = "testUser1";
+ private static final String PERMISSION_OWNER = "Owner";
+ private static final String PERMISSION_CONTRIBUTOR = "Contributor";
+ private static final String INVALID_PERMISSION = "Invalid_Permission";
+ private static final String SUBMIT_ACTION = "Submit_Item";
+ private static final String EDIT_ACTION = "Edit_Item";
+ private static final String CHANGE_PERMISSIONS_ACTION = "Change_Item_Permissions";
+ private static final String INVALID_ACTION = "Invalid_Action";
+
+ @Mock
+ private PermissionsServicesImpl permissionsServices;
+
+ @InjectMocks
+ @Spy
+ private PermissionsRulesImpl permissionsRules;
+
+
+ @BeforeMethod
+ public void setUp() throws Exception {
+
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
+ "Invalid permission type")
+ public void testIsAllowedWhenInvalidPermission() {
+ permissionsRules.isAllowed(INVALID_PERMISSION, EDIT_ACTION);
+ }
+
+ @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
+ "Invalid action type")
+ public void testIsAllowedWhenInvalidAction() {
+ permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR, INVALID_ACTION);
+ }
+
+ @Test
+ public void testIsAllowedCaseSubmitOwner(){
+ Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,SUBMIT_ACTION));
+ }
+
+ @Test
+ public void testIsAllowedCaseSubmitNotOwner(){
+ Assert.assertFalse(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,SUBMIT_ACTION));
+ }
+
+ @Test
+ public void testIsAllowedCaseEditOwner(){
+ Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,EDIT_ACTION));
+ }
+
+ @Test
+ public void testIsAllowedCaseEditContributer(){
+ Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,EDIT_ACTION));
+ }
+
+ @Test
+ public void testIsAllowedCaseChangePermissionsContributer(){
+ Assert.assertFalse(permissionsRules.isAllowed(PERMISSION_CONTRIBUTOR,CHANGE_PERMISSIONS_ACTION));
+ }
+
+ @Test
+ public void testIsAllowedCaseChangePermissionsOwner(){
+ Assert.assertTrue(permissionsRules.isAllowed(PERMISSION_OWNER,CHANGE_PERMISSIONS_ACTION));
+ }
+
+ @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
+ "Invalid permission type")
+ public void testUpdatePermissionWhenInvalidPermission() {
+ permissionsRules.updatePermission(ITEM1_ID,USER1_ID,INVALID_PERMISSION,new HashSet<String>(),
+ new HashSet<String>());
+ }
+
+ @Test(expectedExceptions = CoreException.class,expectedExceptionsMessageRegExp =
+ "Invalid action type")
+ public void testExecuteActionInvalidAction(){
+ permissionsRules.executeAction(ITEM1_ID,USER1_ID,INVALID_ACTION);
+ }
+
+
+} \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/resources/logback.xml b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/resources/logback.xml
new file mode 100644
index 0000000000..c1932e31e8
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/test/resources/logback.xml
@@ -0,0 +1,15 @@
+<configuration>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <!-- encoders are assigned the type
+ ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
+ <encoder>
+ <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="warn">
+ <appender-ref ref="STDOUT" />
+ </root>
+
+</configuration> \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-item-permissions-lib/pom.xml b/openecomp-be/lib/openecomp-item-permissions-lib/pom.xml
new file mode 100644
index 0000000000..fbf8ca5ab4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-item-permissions-lib/pom.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>openecomp-sdc-lib</artifactId>
+ <groupId>org.openecomp.sdc</groupId>
+ <version>1.2.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>openecomp-item-permissions-lib</artifactId>
+ <packaging>pom</packaging>
+
+
+ <modules>
+ <module>openecomp-item-permissions-api</module>
+ <module>openecomp-item-permissions-impl</module>
+ <module>openecomp-item-permissions-core</module>
+ </modules>
+
+</project> \ No newline at end of file