diff options
author | ayalaben <ayala.benzvi@amdocs.com> | 2018-04-10 13:43:01 +0300 |
---|---|---|
committer | Oren Kleks <orenkle@amdocs.com> | 2018-04-12 07:15:06 +0000 |
commit | 8dfa832a4bbe276fdf898330325321a776ac253e (patch) | |
tree | 2ed00333197348dfb0b933f2c6935ca1c9db9122 /openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core | |
parent | fe35212bee3b89dcee98a11dd364218c587aa41a (diff) |
User Permission items
Change-Id: Ice1d126dd29e9f49ca90ada7b1671c72545c9ee8
Issue-ID: SDC-1202
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core')
6 files changed, 172 insertions, 17 deletions
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 8c62aa02fe..87a9949468 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 @@ -1,3 +1,18 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + * 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; @@ -28,16 +43,11 @@ public class ItemPermissionsDaoImpl implements ItemPermissionsDao { @Override public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds, Set<String> removedUsersIds) { - addedUsersIds.forEach(userId -> accessor.addPermission(itemId,userId,permission)); + 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 getUserItemPermission(String itemId, String userId) { ResultSet result = accessor.getUserItemPermission(itemId,userId); @@ -70,6 +80,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 08b51eee86..608102916e 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 @@ -1,9 +1,25 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + * 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.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.dao.UserPermissionsDao; import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; import java.util.Collection; @@ -15,22 +31,30 @@ import java.util.Set; */ public class PermissionsServicesImpl implements PermissionsServices { - private ItemPermissionsDao permissionsDao; + private ItemPermissionsDao itemPermissionsDao; + + private UserPermissionsDao userPermissionsDao; private PermissionsRules permissionsRules; private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions"; public PermissionsServicesImpl(PermissionsRules permissionsRules, - ItemPermissionsDao permissionsDao) { - this.permissionsDao = permissionsDao; + ItemPermissionsDao itemPermissionsDao,UserPermissionsDao userPermissionsDao) { + this.itemPermissionsDao = itemPermissionsDao; this.permissionsRules = permissionsRules; + this.userPermissionsDao = userPermissionsDao; } @Override public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) { - return permissionsDao.listItemPermissions(itemId); + return itemPermissionsDao.listItemPermissions(itemId); + } + + @Override + public Set<String> listUserPermittedItems(String userId, String permission) { + return userPermissionsDao.listUserPermittedItems(userId,permission); } @Override @@ -45,15 +69,18 @@ public class PermissionsServicesImpl implements PermissionsServices { permissionsRules.updatePermission(itemId,currentUserId,permission,addedUsersIds, removedUsersIds); - permissionsDao.updateItemPermissions(itemId, permission, + itemPermissionsDao.updateItemPermissions(itemId, permission, addedUsersIds, removedUsersIds); + userPermissionsDao.updatePermissions(itemId, permission, + addedUsersIds, removedUsersIds); + } @Override public boolean isAllowed(String itemId,String userId,String action) { - String userPermission = permissionsDao.getUserItemPermission(itemId,userId); + String userPermission = itemPermissionsDao.getUserItemPermission(itemId,userId); return permissionsRules.isAllowed(userPermission,action); } @@ -64,12 +91,12 @@ public class PermissionsServicesImpl implements PermissionsServices { @Override public String getUserItemPermiission(String itemId, String userId) { - return permissionsDao.getUserItemPermission(itemId,userId); + return itemPermissionsDao.getUserItemPermission(itemId,userId); } @Override public void deleteItemPermissions(String itemId) { - permissionsDao.deleteItemPermissions(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 34532cb384..d009f62270 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 @@ -1,9 +1,25 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + * 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.PermissionsRulesFactory; import org.openecomp.sdc.itempermissions.PermissionsServices; import org.openecomp.sdc.itempermissions.PermissionsServicesFactory; import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory; +import org.openecomp.sdc.itempermissions.dao.UserPermissionsDaoFactory; /** * Created by ayalaben on 6/22/2017 @@ -11,8 +27,8 @@ import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory; public class PrmissionsServicesFactoryImpl extends PermissionsServicesFactory { private static final PermissionsServices INSTANCE = - new org.openecomp.sdc.itempermissions.dao.impl.PermissionsServicesImpl(PermissionsRulesFactory.getInstance().createInterface(), - ItemPermissionsDaoFactory.getInstance().createInterface()); + new PermissionsServicesImpl(PermissionsRulesFactory.getInstance().createInterface(), + ItemPermissionsDaoFactory.getInstance().createInterface(), UserPermissionsDaoFactory.getInstance().createInterface()); @Override public PermissionsServices createInterface() { 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 new file mode 100644 index 0000000000..86a64ddf1d --- /dev/null +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoFactoryImpl.java @@ -0,0 +1,30 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + * 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; +import org.openecomp.sdc.itempermissions.dao.UserPermissionsDaoFactory; + +public class UserPermissionsDaoFactoryImpl extends UserPermissionsDaoFactory { + + private static UserPermissionsDao INSTANCE =new UserPermissionsDaoImpl(); + + @Override + public UserPermissionsDao 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/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 new file mode 100644 index 0000000000..dad8f25535 --- /dev/null +++ b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/UserPermissionsDaoImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + * 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 org.openecomp.core.nosqldb.api.NoSqlDb; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; +import org.openecomp.sdc.itempermissions.dao.UserPermissionsDao; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class UserPermissionsDaoImpl implements UserPermissionsDao { + + private static final NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static UserPermissionsAccessor accessor = + noSqlDb.getMappingManager().createAccessor(UserPermissionsAccessor.class); + + + @Override + public Set<String> listUserPermittedItems(String userId, String permission) { + ResultSet resultSet = accessor.getUserPermissionItems(userId,permission); + if(resultSet.isExhausted()){ + return new HashSet<>(); + } else { + return resultSet.one().getSet(0,String.class); + } + } + + @Override + 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)); + } + + @Accessor + interface UserPermissionsAccessor { + + @Query("select item_list from dox.user_permission_items WHERE user_id = ? AND permission = ?") + ResultSet getUserPermissionItems(String userId, String permission); + + @Query("update dox.user_permission_items set item_list=item_list+? WHERE user_id = ? AND permission = ?") + void addItem(Set<String> items, String userId, String permission); + + @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/resources/factoryConfiguration.json b/openecomp-be/lib/openecomp-item-permissions-lib/openecomp-item-permissions-core/src/main/resources/factoryConfiguration.json index d23948437f..95a8448719 100644 --- 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 @@ -1,4 +1,5 @@ { "org.openecomp.sdc.itempermissions.dao.ItemPermissionsDaoFactory": "org.openecomp.sdc.itempermissions.dao.impl.ItemPermissionsDaoFactoryImpl", + "org.openecomp.sdc.itempermissions.dao.UserPermissionsDaoFactory": "org.openecomp.sdc.itempermissions.dao.impl.UserPermissionsDaoFactoryImpl", "org.openecomp.sdc.itempermissions.PermissionsServicesFactory" : "org.openecomp.sdc.itempermissions.dao.impl.PrmissionsServicesFactoryImpl" }
\ No newline at end of file |