summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/zusammen-tools/src/main
diff options
context:
space:
mode:
authorshalomb <shalomb@amdocs.com>2018-01-03 14:22:33 +0200
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-01-23 10:09:49 +0000
commit9370a639b9e692621c59ff3a15590b9354e9d178 (patch)
treea15fc4f27c1d3e1def28bec70db9e3d34344ba69 /openecomp-be/tools/zusammen-tools/src/main
parentcb1095edc294cd3e2958978ccc9e36304db418bb (diff)
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 <shalomb@amdocs.com>
Diffstat (limited to 'openecomp-be/tools/zusammen-tools/src/main')
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/HealAll.java125
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/AddContributorCommand.java104
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/HealAll.java129
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/SetHealingFlag.java (renamed from openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/SetHealingFlag.java)6
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/concurrent/ItemAddContributorsTask.java55
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/exceptions/CommandExecutionRuntimeException.java11
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/main/ZusammenMainTool.java51
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/ItemHandler.java32
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/NotificationHandler.java28
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/store/PermissionHandler.java48
10 files changed, 446 insertions, 143 deletions
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<ItemHealingTask> 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<Future<String>> 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<VersionInfoEntity> filterByEntityType(
- Collection<VersionInfoEntity> 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/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<String> itemList;
+ try {
+ itemList = getItemList(itemListPath);
+ } catch (IOException e) {
+ throw new CommandExecutionRuntimeException(ERROR_TRYING_TO_READ_FILE +
+ "from:" + itemListPath, e);
+ }
+ List<String> userList;
+ try {
+ userList = load(userListPath).collect(Collectors.toList());
+ } catch (IOException e) {
+ throw new CommandExecutionRuntimeException(ERROR_TRYING_TO_READ_FILE +
+ "from:" + userListPath, e);
+ }
+
+ List<ItemAddContributorsTask> 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<String> getItemList(String itemListPath) throws IOException {
+ List<String> itemList;
+ if (itemListPath != null) {
+ itemList = load(itemListPath).collect(Collectors.toList());
+ } else {
+ itemList = new ItemHandler().getItemList();
+ }
+
+ return itemList;
+ }
+
+ private static void executeAllTasks(ExecutorService executor,
+ Collection<? extends Callable<String>> tasks)
+ throws InterruptedException {
+ List<Future<String>> futureTasks;
+ futureTasks = executor.invokeAll(tasks);
+ boolean isThreadOpen = true;
+ while (isThreadOpen) {
+ isThreadOpen = futureTasks.stream().anyMatch(future -> !future.isDone());
+
+ }
+ }
+
+
+
+ private static ItemAddContributorsTask createTask(String itemId, List<String> users) {
+ return new ItemAddContributorsTask(new PermissionHandler(), new NotificationHandler(),
+ itemId, users);
+ }
+
+ private static Stream<String> 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<ItemHealingTask> 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<Future<String>> 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<VersionInfoEntity> filterByEntityType(
+ Collection<VersionInfoEntity> 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
index b885ac5d05..fc20b66e3b 100644
--- 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
@@ -1,4 +1,4 @@
-package org.openecomp.core.tools.Commands;
+package org.openecomp.core.tools.commands;
import com.datastax.driver.core.ResultSet;
import org.openecomp.core.tools.store.HealingHandler;
@@ -14,12 +14,14 @@ import java.util.ArrayList;
public class SetHealingFlag {
+ private SetHealingFlag(){}
+
public static void populateHealingTable(String oldVersion) {
VersionCassandraLoader versionCassandraLoader = new VersionCassandraLoader();
ResultSet listItemVersion = versionCassandraLoader.listItemVersion();
- ArrayList<HealingEntity> healingEntities = new ArrayList<HealingEntity>();
+ ArrayList<HealingEntity> healingEntities = new ArrayList<>();
listItemVersion.iterator().forEachRemaining(entry -> healingEntities.add(new HealingEntity
(entry.getString(0),entry.getString(1),entry.getString(2),true,oldVersion)));
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<String> {
+
+ 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<String> users;
+ private final PermissionHandler permissionHandler;
+ private final NotificationHandler notificationHandler;
+
+ public ItemAddContributorsTask(PermissionHandler permissionHandler, NotificationHandler
+ notificationHandler, String itemId, List<String> 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<String> 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<String> 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<String> getItemList() {
+ ResultSet resultSet = NoSqlDbFactory.getInstance().createInterface()
+ .getMappingManager().createAccessor(ItemAccessor.class).list();
+ List<Row> 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<String> 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<String> 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<String> 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