From 9370a639b9e692621c59ff3a15590b9354e9d178 Mon Sep 17 00:00:00 2001 From: shalomb Date: Wed, 3 Jan 2018 14:22:33 +0200 Subject: Add contributors for items vi zusammen tool Add contributors for items vi zusammen tool new command fix sonar issues Change-Id: I890480cd410a8ab73156bab7ef80846f7e50dd9c Issue-ID: SDC-871 Signed-off-by: shalomb --- .../org/openecomp/core/tools/Commands/HealAll.java | 125 -------------------- .../core/tools/Commands/SetHealingFlag.java | 31 ----- .../core/tools/commands/AddContributorCommand.java | 104 +++++++++++++++++ .../org/openecomp/core/tools/commands/HealAll.java | 129 +++++++++++++++++++++ .../core/tools/commands/SetHealingFlag.java | 33 ++++++ .../tools/concurrent/ItemAddContributorsTask.java | 55 +++++++++ .../CommandExecutionRuntimeException.java | 11 ++ .../core/tools/main/ZusammenMainTool.java | 51 +++++--- .../openecomp/core/tools/store/ItemHandler.java | 32 +++++ .../core/tools/store/NotificationHandler.java | 28 +++++ .../core/tools/store/PermissionHandler.java | 48 ++++++++ .../exportinfo/serialize/VLMExtractTest.java | 47 -------- .../exportinfo/serialize/VLMExtractTest.java | 47 ++++++++ 13 files changed, 522 insertions(+), 219 deletions(-) delete mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/HealAll.java delete mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/SetHealingFlag.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java create mode 100644 openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java delete mode 100644 openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java create mode 100644 openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/commands/exportinfo/serialize/VLMExtractTest.java (limited to 'openecomp-be/tools') diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/HealAll.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/HealAll.java deleted file mode 100644 index 7868927c93..0000000000 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/HealAll.java +++ /dev/null @@ -1,125 +0,0 @@ -package org.openecomp.core.tools.Commands; - -import org.apache.commons.collections.CollectionUtils; -import org.openecomp.core.tools.concurrent.ItemHealingTask; -import org.openecomp.core.tools.exceptions.HealingRuntimeException; -import org.openecomp.core.tools.loaders.VersionInfoCassandraLoader; -import org.openecomp.sdc.healing.api.HealingManager; -import org.openecomp.sdc.healing.factory.HealingManagerFactory; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; -import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; -import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory; -import org.openecomp.sdc.versioning.dao.types.Version; -import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; - -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; -import java.time.Duration; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.stream.Stream; - -/** - * Created by ayalaben on 11/6/2017 - */ -public class HealAll { - - private static final int DEFAULT_THREAD_NUMBER = 100; - private static List tasks = new ArrayList<>(); - private static VendorSoftwareProductManager vspManager = VspManagerFactory - .getInstance().createInterface(); - private static HealingManager healingManager = HealingManagerFactory.getInstance() - .createInterface(); - - private HealAll() { - } - - public static void healAll(String threadNumber) { - - String logFileName = "healing.log"; - try (BufferedWriter log = new BufferedWriter(new FileWriter(logFileName, true))) { - - writeToLog("----starting healing------", log); - Instant startTime = Instant.now(); - - int numberOfThreads = Objects.nonNull(threadNumber) ? Integer.valueOf(threadNumber) : - DEFAULT_THREAD_NUMBER; - ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads); - - filterByEntityType(VersionInfoCassandraLoader.list(), - VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE).forEach - (HealAll::addTaskToTasks); - - executeAllTasks(executor, log); - - writeToLog("----finished healing------", log); - Instant endTime = Instant.now(); - writeToLog("Total runtime was: " + Duration.between(startTime, endTime), log); - } catch (IOException e) { - throw new HealingRuntimeException("can't initial healing log file '" + logFileName + "'", e); - } - - System.exit(1); - } - - private static void executeAllTasks(ExecutorService executor, BufferedWriter log) { - List> futureTasks; - try { - futureTasks = executor.invokeAll(tasks); - futureTasks.forEach(future -> { - try { - log.write(future.get()); - log.newLine(); - } catch (Exception e) { - writeToLog(e.getMessage(), log); - } - }); - } catch (InterruptedException e) { - writeToLog("migration tasks failed with message: " + e.getMessage(), log); - throw new HealingRuntimeException(e); - } - - boolean isThreadOpen = true; - while (isThreadOpen) { - isThreadOpen = futureTasks.stream().anyMatch(future -> !future.isDone()); - } - } - - private static Version resolveVersion(VersionInfoEntity versionInfoEntity) { - if (Objects.nonNull(versionInfoEntity.getCandidate())) { - return versionInfoEntity.getCandidate().getVersion(); - } else if (!CollectionUtils.isEmpty(versionInfoEntity.getViewableVersions())) { - return versionInfoEntity.getViewableVersions().stream().max(Version::compateTo).get(); - } - return versionInfoEntity.getActiveVersion(); - } - - private static void writeToLog(String message, BufferedWriter log) { - try { - log.write(message); - log.newLine(); - } catch (IOException e) { - throw new HealingRuntimeException("unable to write to healing all log file.", e); - } - } - - private static Stream filterByEntityType( - Collection versionInfoEntities, String entityType) { - return versionInfoEntities.stream().filter(versionInfoEntity -> versionInfoEntity - .getEntityType().equals(entityType)); - } - - private static void addTaskToTasks(VersionInfoEntity versionInfoEntity) { - tasks.add(new ItemHealingTask(versionInfoEntity.getEntityId(), resolveVersion - (versionInfoEntity).toString(), - vspManager, healingManager)); - } - -} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/SetHealingFlag.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/SetHealingFlag.java deleted file mode 100644 index b885ac5d05..0000000000 --- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/SetHealingFlag.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.openecomp.core.tools.Commands; - -import com.datastax.driver.core.ResultSet; -import org.openecomp.core.tools.store.HealingHandler; -import org.openecomp.core.tools.store.VersionCassandraLoader; -import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity; - -import java.util.ArrayList; - - -/** - * Created by ayalaben on 10/15/2017 - */ -public class SetHealingFlag { - - - public static void populateHealingTable(String oldVersion) { - - VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader(); - ResultSet listItemVersion = versionCassandraLoader.listItemVersion(); - - ArrayList healingEntities = new ArrayList(); - - listItemVersion.iterator().forEachRemaining(entry -> healingEntities.add(new HealingEntity - (entry.getString(0),entry.getString(1),entry.getString(2),true,oldVersion))); - - HealingHandler healingHandler = new HealingHandler(); - healingHandler.populateHealingTable(healingEntities); - - } -} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java new file mode 100644 index 0000000000..caa688d007 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java @@ -0,0 +1,104 @@ +package org.openecomp.core.tools.commands; + +import org.openecomp.core.tools.concurrent.ItemAddContributorsTask; +import org.openecomp.core.tools.exceptions.CommandExecutionRuntimeException; +import org.openecomp.core.tools.store.ItemHandler; +import org.openecomp.core.tools.store.NotificationHandler; +import org.openecomp.core.tools.store.PermissionHandler; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class AddContributorCommand { + + + private static final int DEFAULT_THREAD_NUMBER = 8; + private static final String ERROR_TRYING_TO_READ_FILE = "Error while trying to read item list"; + private static final String COMMAND_ADD_CONTRIBUTOR_FAILED = + "Command AddContributor execution failed."; + + private AddContributorCommand() { + // it's a utility class, prevent instantiation + } + + public static void add(String itemListPath, String userListPath) { + + List itemList; + try { + itemList = getItemList(itemListPath); + } catch (IOException e) { + throw new CommandExecutionRuntimeException(ERROR_TRYING_TO_READ_FILE + + "from:" + itemListPath, e); + } + List userList; + try { + userList = load(userListPath).collect(Collectors.toList()); + } catch (IOException e) { + throw new CommandExecutionRuntimeException(ERROR_TRYING_TO_READ_FILE + + "from:" + userListPath, e); + } + + List tasks = + itemList.stream().map(itemid -> createTask(itemid, userList)).collect(Collectors.toList()); + + ExecutorService executor = null; + + try { + executor = Executors.newFixedThreadPool(DEFAULT_THREAD_NUMBER); + executeAllTasks(executor, tasks); + } catch (InterruptedException e) { + throw new CommandExecutionRuntimeException(COMMAND_ADD_CONTRIBUTOR_FAILED, e); + } finally { + if (executor != null) { + executor.shutdownNow(); + } + } + } + + private static List getItemList(String itemListPath) throws IOException { + List itemList; + if (itemListPath != null) { + itemList = load(itemListPath).collect(Collectors.toList()); + } else { + itemList = new ItemHandler().getItemList(); + } + + return itemList; + } + + private static void executeAllTasks(ExecutorService executor, + Collection> tasks) + throws InterruptedException { + List> futureTasks; + futureTasks = executor.invokeAll(tasks); + boolean isThreadOpen = true; + while (isThreadOpen) { + isThreadOpen = futureTasks.stream().anyMatch(future -> !future.isDone()); + + } + } + + + + private static ItemAddContributorsTask createTask(String itemId, List users) { + return new ItemAddContributorsTask(new PermissionHandler(), new NotificationHandler(), + itemId, users); + } + + private static Stream load(String filePath) + throws IOException { + return Files.lines(Paths.get(filePath)); + + } + + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java new file mode 100644 index 0000000000..8bcfcbacde --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java @@ -0,0 +1,129 @@ +package org.openecomp.core.tools.commands; + +import org.apache.commons.collections.CollectionUtils; +import org.openecomp.core.tools.concurrent.ItemHealingTask; +import org.openecomp.core.tools.exceptions.HealingRuntimeException; +import org.openecomp.core.tools.loaders.VersionInfoCassandraLoader; +import org.openecomp.sdc.healing.api.HealingManager; +import org.openecomp.sdc.healing.factory.HealingManagerFactory; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductConstants; +import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager; +import org.openecomp.sdc.vendorsoftwareproduct.VspManagerFactory; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.openecomp.sdc.versioning.dao.types.VersionInfoEntity; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.stream.Stream; + +/** + * Created by ayalaben on 11/6/2017 + */ +public class HealAll { + + private static final int DEFAULT_THREAD_NUMBER = 100; + private static List tasks = new ArrayList<>(); + private static VendorSoftwareProductManager vspManager = VspManagerFactory + .getInstance().createInterface(); + private static HealingManager healingManager = HealingManagerFactory.getInstance() + .createInterface(); + + private HealAll() { + } + + public static void healAll(String threadNumber) { + + String logFileName = "healing.log"; + try (BufferedWriter log = new BufferedWriter(new FileWriter(logFileName, true))) { + + writeToLog("----starting healing------", log); + Instant startTime = Instant.now(); + + int numberOfThreads = Objects.nonNull(threadNumber) ? Integer.valueOf(threadNumber) : + DEFAULT_THREAD_NUMBER; + ExecutorService executor = Executors.newFixedThreadPool(numberOfThreads); + + filterByEntityType(VersionInfoCassandraLoader.list(), + VendorSoftwareProductConstants.VENDOR_SOFTWARE_PRODUCT_VERSIONABLE_TYPE).forEach + (HealAll::addTaskToTasks); + + executeAllTasks(executor, log); + + writeToLog("----finished healing------", log); + Instant endTime = Instant.now(); + writeToLog("Total runtime was: " + Duration.between(startTime, endTime), log); + } catch (IOException e) { + throw new HealingRuntimeException("can't initial healing log file '" + logFileName + "'", e); + } + + System.exit(1); + } + + private static void executeAllTasks(ExecutorService executor, BufferedWriter log) { + List> futureTasks; + try { + futureTasks = executor.invokeAll(tasks); + futureTasks.forEach(future -> { + try { + log.write(future.get()); + log.newLine(); + } catch (Exception e) { + writeToLog(e.getMessage(), log); + } + }); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + writeToLog("migration tasks failed with message: " + e.getMessage(), log); + throw new HealingRuntimeException(e); + } + + boolean isThreadOpen = true; + while (isThreadOpen) { + isThreadOpen = futureTasks.stream().anyMatch(future -> !future.isDone()); + } + } + + + private static Version resolveVersion(VersionInfoEntity versionInfoEntity) { + if (Objects.nonNull(versionInfoEntity.getCandidate())) { + return versionInfoEntity.getCandidate().getVersion(); + } else if (!CollectionUtils.isEmpty(versionInfoEntity.getViewableVersions())) { + + return versionInfoEntity.getViewableVersions().stream().max(Version::compateTo) + .orElse(new Version()); + } + return versionInfoEntity.getActiveVersion(); + } + + private static void writeToLog(String message, BufferedWriter log) { + try { + log.write(message); + log.newLine(); + } catch (IOException e) { + throw new HealingRuntimeException("unable to write to healing all log file.", e); + } + } + + private static Stream filterByEntityType( + Collection versionInfoEntities, String entityType) { + return versionInfoEntities.stream().filter(versionInfoEntity -> versionInfoEntity + .getEntityType().equals(entityType)); + } + + private static void addTaskToTasks(VersionInfoEntity versionInfoEntity) { + tasks.add(new ItemHealingTask(versionInfoEntity.getEntityId(), resolveVersion + (versionInfoEntity).toString(), + vspManager, healingManager)); + } + +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java new file mode 100644 index 0000000000..fc20b66e3b --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java @@ -0,0 +1,33 @@ +package org.openecomp.core.tools.commands; + +import com.datastax.driver.core.ResultSet; +import org.openecomp.core.tools.store.HealingHandler; +import org.openecomp.core.tools.store.VersionCassandraLoader; +import org.openecomp.core.tools.store.zusammen.datatypes.HealingEntity; + +import java.util.ArrayList; + + +/** + * Created by ayalaben on 10/15/2017 + */ +public class SetHealingFlag { + + + private SetHealingFlag(){} + + public static void populateHealingTable(String oldVersion) { + + VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader(); + ResultSet listItemVersion = versionCassandraLoader.listItemVersion(); + + ArrayList healingEntities = new ArrayList<>(); + + listItemVersion.iterator().forEachRemaining(entry -> healingEntities.add(new HealingEntity + (entry.getString(0),entry.getString(1),entry.getString(2),true,oldVersion))); + + HealingHandler healingHandler = new HealingHandler(); + healingHandler.populateHealingTable(healingEntities); + + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java new file mode 100644 index 0000000000..9429445813 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java @@ -0,0 +1,55 @@ +package org.openecomp.core.tools.concurrent; + +import org.openecomp.core.tools.store.NotificationHandler; +import org.openecomp.core.tools.store.PermissionHandler; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.concurrent.Callable; + + +public class ItemAddContributorsTask implements Callable { + + private static final String CONTRIBUTOR = "Contributor"; + private static final String SUCCESSFUL_RETURN_MESSAGE = "Users added successfully as " + + "contributors to item id:%s."; + private final String itemId; + private final List users; + private final PermissionHandler permissionHandler; + private final NotificationHandler notificationHandler; + + public ItemAddContributorsTask(PermissionHandler permissionHandler, NotificationHandler + notificationHandler, String itemId, List users) { + this.itemId = itemId.trim(); + this.users = new ArrayList<>(users); + this.permissionHandler = permissionHandler; + this.notificationHandler = notificationHandler; + } + + @Override + public String call() { + users.forEach(this::handleUser); + return String.format(SUCCESSFUL_RETURN_MESSAGE, itemId); + } + + private void handleUser(String user) { + Optional userPermission = getUserPermission(user); + if (!userPermission.isPresent()) { + setUserPermission(user, CONTRIBUTOR); + registerUserNotificationSubscription(user); + } + } + + private void registerUserNotificationSubscription(String user) { + notificationHandler.registerNotificationForUserOnEntity(user, itemId); + } + + private void setUserPermission(String user, String permission) { + permissionHandler.setItemUserPermission(itemId, user, permission); + } + + private Optional getUserPermission(String user) { + return permissionHandler.getItemUserPermission(itemId, user); + } +} diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java new file mode 100644 index 0000000000..3345a3ef1f --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java @@ -0,0 +1,11 @@ +package org.openecomp.core.tools.exceptions; + +public class CommandExecutionRuntimeException extends RuntimeException { + public CommandExecutionRuntimeException(String message, Exception exception) { + super(message, exception); + } + + public CommandExecutionRuntimeException(String message) { + super(message); + } +} 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 acc60deb16..e0dfa44430 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,8 +2,9 @@ package org.openecomp.core.tools.main; import com.amdocs.zusammen.datatypes.SessionContext; import com.amdocs.zusammen.datatypes.UserInfo; -import org.openecomp.core.tools.Commands.HealAll; -import org.openecomp.core.tools.Commands.SetHealingFlag; +import org.openecomp.core.tools.commands.AddContributorCommand; +import org.openecomp.core.tools.commands.HealAll; +import org.openecomp.core.tools.commands.SetHealingFlag; import org.openecomp.core.tools.exportinfo.ExportDataCommand; import org.openecomp.core.tools.importinfo.ImportDataCommand; import org.openecomp.core.tools.util.ToolsUtil; @@ -23,11 +24,23 @@ public class ZusammenMainTool { public static void main(String[] args) { - String command = ToolsUtil.getParam("c",args); + COMMANDS command = getCommand(args); + if(command == null){ printMessage(logger, "parameter -c is mandatory. script usage: zusammenMainTool.sh -c {command name} " + "[additional arguments depending on the command] "); + printMessage(logger, + "reset old version: -c RESET_OLD_VERSION [-v {version}]"); + printMessage(logger, + "export: -c EXPORT [-i {item id}]"); + printMessage(logger, + "import: -c IMPORT -f {zip file full path}"); + printMessage(logger, + "heal all: -c HEAL_ALL [-t {number of threads}]"); + printMessage(logger, + "add users as contributors: -c ADD_CONTRIBUTOR [-p {item id list file path}] -u {user " + + "list file path}"); System.exit(-1); } Instant startTime = Instant.now(); @@ -37,7 +50,8 @@ public class ZusammenMainTool { context.setTenant("dox"); - switch (COMMANDS.valueOf(command)){ + + switch (command){ case RESET_OLD_VERSION: SetHealingFlag.populateHealingTable(ToolsUtil.getParam("v",args)); break; @@ -49,6 +63,9 @@ public class ZusammenMainTool { break; case HEAL_ALL: HealAll.healAll(ToolsUtil.getParam("t",args)); + break; + case ADD_CONTRIBUTOR: + AddContributorCommand.add(ToolsUtil.getParam("p",args),ToolsUtil.getParam("u",args)); } @@ -66,19 +83,21 @@ public class ZusammenMainTool { } - private enum COMMANDS{ - - - RESET_OLD_VERSION("reset-old-version"), - EXPORT("export"), - IMPORT("import"), - HEAL_ALL("heal-all"); - - COMMANDS(String command) { - this.command = command; + private static COMMANDS getCommand(String[] args) { + String commandSrt = ToolsUtil.getParam("c",args); + try{ + return COMMANDS.valueOf(commandSrt); + }catch (IllegalArgumentException iae){ + printMessage(logger,"message:"+commandSrt+ " is illegal."); } - - private String command; + return null; } + private enum COMMANDS{ + RESET_OLD_VERSION, + EXPORT, + IMPORT, + HEAL_ALL, + ADD_CONTRIBUTOR; + } } diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java new file mode 100644 index 0000000000..3928683727 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java @@ -0,0 +1,32 @@ +package org.openecomp.core.tools.store; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class ItemHandler { + + public List getItemList() { + ResultSet resultSet = NoSqlDbFactory.getInstance().createInterface() + .getMappingManager().createAccessor(ItemAccessor.class).list(); + List rows = resultSet.all(); + + if (rows != null) { + return rows.stream().map(row -> row.getString("item_id")).collect(Collectors.toList()); + } + return Collections.emptyList(); + } + + @Accessor + interface ItemAccessor { + @Query("SELECT item_id FROM zusammen_dox.item") + ResultSet list(); + } + +} \ No newline at end of file diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java new file mode 100644 index 0000000000..cc7daf6058 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java @@ -0,0 +1,28 @@ +package org.openecomp.core.tools.store; + +import com.datastax.driver.mapping.annotations.Accessor; +import com.datastax.driver.mapping.annotations.Query; +import org.openecomp.core.nosqldb.factory.NoSqlDbFactory; + +import java.util.HashSet; +import java.util.Set; + +public class NotificationHandler { + + public void registerNotificationForUserOnEntity(String user, String entityId) { + + Set userSet = new HashSet<>(); + userSet.add(user); + NoSqlDbFactory.getInstance().createInterface().getMappingManager() + .createAccessor(NotificationAccessor.class) + .updateNotificationSubscription(userSet, entityId); + } + + @Accessor + interface NotificationAccessor { + + @Query("UPDATE dox.notification_subscribers SET subscribers = subscribers + ? where " + + "entity_id = ?") + void updateNotificationSubscription(Set users, String entityId); + } +} \ No newline at end of file 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 new file mode 100644 index 0000000000..9b7b0f62e6 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java @@ -0,0 +1,48 @@ +package org.openecomp.core.tools.store; + +import com.datastax.driver.core.ResultSet; +import com.datastax.driver.core.Row; +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 java.util.Objects; +import java.util.Optional; + +public class PermissionHandler { + + private static NoSqlDb noSqlDb = NoSqlDbFactory.getInstance().createInterface(); + private static PermissionAccessor accessor = + noSqlDb.getMappingManager().createAccessor(PermissionAccessor.class); + + + public Optional getItemUserPermission(String itemId, String user) { + ResultSet resultSet = accessor.getItemUserPermission(itemId, user); + Row row = resultSet.one(); + + if (Objects.nonNull(row)) { + return Optional.of(row.getString("permission")); + } else { + return Optional.empty(); + } + } + + public void setItemUserPermission(String itemId, String user, String permission) { + accessor.setItemUserPermission(itemId, user, permission); + } + + + @Accessor + interface PermissionAccessor { + + + @Query("INSERT into dox.item_permissions (item_id,user_id,permission) VALUES (?,?,?)") + void setItemUserPermission(String permission, String itemId, String userId); + + + @Query("SELECT permission FROM dox.item_permissions WHERE item_id=? AND user_id=?") + ResultSet getItemUserPermission(String itemId, String userId); + } + +} \ No newline at end of file diff --git a/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java b/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java deleted file mode 100644 index ed1ad2b2f4..0000000000 --- a/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/Commands/exportinfo/serialize/VLMExtractTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.openecomp.core.tools.Commands.exportinfo.serialize; - -import org.openecomp.core.tools.exportinfo.ExportSerializer; -import org.testng.annotations.Test; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -public class VLMExtractTest { - - - - @Test - public void extractVLM(){ - String vlmId = "979a56c7b2fa41e6a5742137f53a5c1b"; - String elemenet_info_string = "{\n" + - " \"name\": \"VendorSoftwareProduct\",\n" + - " \"properties\": {\n" + - " \"subCategory\": \"resourceNewCategory.dcae component.collector\",\n" + - " \"name\": \"vsp1\",\n" + - " \"icon\": \"icon\",\n" + - " \"onboardingMethod\": \"NetworkPackage\",\n" + - " \"description\": \"d\",\n" + - " \"vendorId\": \""+vlmId+"\",\n" + - " \"category\": \"resourceNewCategory.dcae component\",\n" + - " \"vendorName\": \"vlm1\",\n" + - " \"elementType\": \"VendorSoftwareProduct\"\n" + - " }\n" + - "}\n" ; - String extractedVlmId = new CustomExportSerializer().extractVlm(elemenet_info_string); - assertNotNull(extractedVlmId); - assertEquals(extractedVlmId,vlmId); - - } - - @Test(expectedExceptions = IllegalStateException.class) - public void failToExtractVLMBecauseJsonIsCorrupted(){ - String elemenet_info_string = "gfhhhghgh"; - assertNull(new CustomExportSerializer().extractVlm(elemenet_info_string)); - } - - private static final class CustomExportSerializer extends ExportSerializer{ - public String extractVlm(String inJson) { - return super.extractVlm(inJson); - } - } -} diff --git a/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/commands/exportinfo/serialize/VLMExtractTest.java b/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/commands/exportinfo/serialize/VLMExtractTest.java new file mode 100644 index 0000000000..7b86903308 --- /dev/null +++ b/openecomp-be/tools/zusammen-tools/src/test/java/org/openecomp/core/tools/commands/exportinfo/serialize/VLMExtractTest.java @@ -0,0 +1,47 @@ +package org.openecomp.core.tools.commands.exportinfo.serialize; + +import org.openecomp.core.tools.exportinfo.ExportSerializer; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +public class VLMExtractTest { + + + + @Test + public void extractVLM(){ + String vlmId = "979a56c7b2fa41e6a5742137f53a5c1b"; + String elemenet_info_string = "{\n" + + " \"name\": \"VendorSoftwareProduct\",\n" + + " \"properties\": {\n" + + " \"subCategory\": \"resourceNewCategory.dcae component.collector\",\n" + + " \"name\": \"vsp1\",\n" + + " \"icon\": \"icon\",\n" + + " \"onboardingMethod\": \"NetworkPackage\",\n" + + " \"description\": \"d\",\n" + + " \"vendorId\": \""+vlmId+"\",\n" + + " \"category\": \"resourceNewCategory.dcae component\",\n" + + " \"vendorName\": \"vlm1\",\n" + + " \"elementType\": \"VendorSoftwareProduct\"\n" + + " }\n" + + "}\n" ; + String extractedVlmId = new CustomExportSerializer().extractVlm(elemenet_info_string); + assertNotNull(extractedVlmId); + assertEquals(extractedVlmId,vlmId); + + } + + @Test(expectedExceptions = IllegalStateException.class) + public void failToExtractVLMBecauseJsonIsCorrupted(){ + String elemenet_info_string = "gfhhhghgh"; + assertNull(new CustomExportSerializer().extractVlm(elemenet_info_string)); + } + + private static final class CustomExportSerializer extends ExportSerializer{ + public String extractVlm(String inJson) { + return super.extractVlm(inJson); + } + } +} -- cgit 1.2.3-korg