summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl')
-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
8 files changed, 311 insertions, 0 deletions
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