summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-impl/src/main
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/openecomp-item-permissions-impl/src/main
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/openecomp-item-permissions-impl/src/main')
-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
4 files changed, 39 insertions, 69 deletions
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}