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/tools | |
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/tools')
4 files changed, 68 insertions, 0 deletions
diff --git a/openecomp-be/tools/build/scripts/cassandra-commands.json b/openecomp-be/tools/build/scripts/cassandra-commands.json index 34916fe74d..0b0519a3df 100644 --- a/openecomp-be/tools/build/scripts/cassandra-commands.json +++ b/openecomp-be/tools/build/scripts/cassandra-commands.json @@ -22,6 +22,7 @@ "healing" : "CREATE TABLE IF NOT EXISTS healing (space text,item_id text,version_id text, healing_needed boolean,old_version text, PRIMARY KEY((space,item_id),version_id))", "migration": "CREATE TABLE IF NOT EXISTS migration (id text, ismigrated boolean, primary key (id))", "item_permissions" : "CREATE TABLE IF NOT EXISTS item_permissions (item_id text,user_id text, permission text, PRIMARY KEY(item_id,user_id)) WITH CLUSTERING ORDER BY (user_id DESC)", + "user_permission_items" : "CREATE TABLE IF NOT EXISTS user_permission_items (user_id text,permission text, item_list set<text>, PRIMARY KEY ((user_id), permission))", "notification_subscribers": "CREATE TABLE IF NOT EXISTS NOTIFICATION_SUBSCRIBERS (entity_id text PRIMARY KEY, subscribers set<text>)", "last_notification": "CREATE TABLE IF NOT EXISTS last_notification (owner_id text PRIMARY KEY, event_id timeuuid)", "notifications": "CREATE TABLE IF NOT EXISTS notifications (owner_id text, event_id timeuuid, read boolean, originator_id text, event_type text, event_attributes text, PRIMARY KEY (owner_id, event_id)) WITH CLUSTERING ORDER BY (event_id DESC)", @@ -46,6 +47,7 @@ "activity_log": "DROP TABLE IF EXISTS activity_log", "migration": "DROP TABLE IF EXISTS migration", "item_permissions": "DROP TABLE IF EXISTS item_permissions", + "user_permission_items" : "DROP TABLE IF EXISTS user_permission_items", "notification_subscribers": "DROP TABLE IF EXISTS notification_subscribers", "last_notification": "DROP TABLE IF EXISTS last_notification", "notifications": "DROP TABLE IF EXISTS notifications", diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/PopulateUserPermissions.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/PopulateUserPermissions.java new file mode 100644 index 0000000000..bf85bd19b5 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/PopulateUserPermissions.java @@ -0,0 +1,43 @@ +/* + * 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.core.tools.commands; + +import org.openecomp.core.tools.store.PermissionHandler; +import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity; + +import java.util.*; + + +public class PopulateUserPermissions { + + private static PermissionHandler permissionHandler = new PermissionHandler(); + + private PopulateUserPermissions(){ } + + public static void execute(){ + + List<ItemPermissionsEntity> permissions = permissionHandler.getAll(); + + permissions.forEach(itemPermissionsEntity -> + permissionHandler.addItem + (Collections.singleton(itemPermissionsEntity.getItemId()), + itemPermissionsEntity.getUserId(),itemPermissionsEntity.getPermission())); + + System.exit(0); + + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java index 42a63e8938..1080a23dfa 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java @@ -2,6 +2,7 @@ package org.openecomp.core.tools.main; import org.openecomp.core.tools.commands.AddContributorCommand; import org.openecomp.core.tools.commands.HealAll; +import org.openecomp.core.tools.commands.PopulateUserPermissions; import org.openecomp.core.tools.commands.SetHealingFlag; import org.openecomp.core.tools.exportinfo.ExportDataCommand; import org.openecomp.core.tools.importinfo.ImportDataCommand; @@ -59,6 +60,9 @@ public class ZusammenMainTool { case HEAL_ALL: HealAll.healAll(ToolsUtil.getParam("t", args)); break; + case POPULATE_USER_PERMISSIONS: + PopulateUserPermissions.execute(); + break; case ADD_CONTRIBUTOR: AddContributorCommand.add(ToolsUtil.getParam("p", args), ToolsUtil.getParam("u", args)); @@ -93,6 +97,7 @@ public class ZusammenMainTool { EXPORT, IMPORT, HEAL_ALL, + POPULATE_USER_PERMISSIONS, ADD_CONTRIBUTOR } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java index 9b7b0f62e6..ecde9e900a 100644 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java @@ -2,13 +2,17 @@ package org.openecomp.core.tools.store; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Row; +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.type.ItemPermissionsEntity; +import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.Set; public class PermissionHandler { @@ -32,6 +36,14 @@ public class PermissionHandler { accessor.setItemUserPermission(itemId, user, permission); } + public void addItem(Set<String> items, String userId, String permission){ + accessor.addItem(items,userId,permission); + } + + public List<ItemPermissionsEntity> getAll(){ + return accessor.getAll().all(); + } + @Accessor interface PermissionAccessor { @@ -43,6 +55,12 @@ public class PermissionHandler { @Query("SELECT permission FROM dox.item_permissions WHERE item_id=? AND user_id=?") ResultSet getItemUserPermission(String itemId, String userId); + + @Query("SELECT * from dox.item_permissions") + Result<ItemPermissionsEntity> getAll(); + + @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); } }
\ No newline at end of file |