aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/zusammen-tools/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/tools/zusammen-tools/src/main/java')
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java69
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java4
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java2
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java61
4 files changed, 135 insertions, 1 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java
new file mode 100644
index 0000000000..96bc22e204
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CleanUserDataCommand.java
@@ -0,0 +1,69 @@
+package org.openecomp.core.tools.commands;
+
+import static org.openecomp.core.tools.commands.CommandName.CLEAN_USER_DATA;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.UserInfo;
+import com.amdocs.zusammen.datatypes.item.ItemVersion;
+import java.util.Collection;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.openecomp.core.zusammen.db.ZusammenConnector;
+import org.openecomp.core.zusammen.db.ZusammenConnectorFactory;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+public class CleanUserDataCommand extends Command {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CleanUserDataCommand.class);
+ private static final String ITEM_ID_OPTION = "i";
+ private static final String USER_OPTION = "u";
+
+ CleanUserDataCommand() {
+ options.addOption(
+ Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id").desc("id of the item to clean, mandatory")
+ .build());
+ options.addOption(Option.builder(USER_OPTION).hasArg().argName("user")
+ .desc("the user of which the item data will be cleaned for, mandatory").build());
+ }
+
+ @Override
+ public boolean execute(String[] args) {
+ CommandLine cmd = parseArgs(args);
+ if (!cmd.hasOption(ITEM_ID_OPTION) || !cmd.hasOption(USER_OPTION)) {
+ LOGGER.error("Arguments i and u are mandatory");
+ return false;
+ }
+ String itemId = cmd.getOptionValue(ITEM_ID_OPTION);
+ String user = cmd.getOptionValue(USER_OPTION);
+
+ SessionContext context = createSessionContext(user);
+ ZusammenConnector zusammenConnector = ZusammenConnectorFactory.getInstance().createInterface();
+
+ Id itemIdObj = new Id(itemId);
+ Collection<ItemVersion> versions = zusammenConnector.listPublicVersions(context, itemIdObj);
+ for (ItemVersion version : versions) {
+ try {
+ zusammenConnector.cleanVersion(context, itemIdObj, version.getId());
+ } catch (Exception e) {
+ LOGGER.error(
+ String.format("Error occurred while cleaning item %s version %s from user %s space", itemId,
+ version.getId(), user), e);
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public CommandName getCommandName() {
+ return CLEAN_USER_DATA;
+ }
+
+ private static SessionContext createSessionContext(String user) {
+ SessionContext sessionContext = new SessionContext();
+ sessionContext.setUser(new UserInfo(user));
+ sessionContext.setTenant("dox");
+ return sessionContext;
+ }
+}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java
index 7fa04a3907..7490f03a82 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandName.java
@@ -6,5 +6,7 @@ public enum CommandName {
IMPORT,
HEAL_ALL,
POPULATE_USER_PERMISSIONS,
- ADD_CONTRIBUTOR
+ ADD_CONTRIBUTOR,
+ CLEAN_USER_DATA,
+ DELETE_PUBLIC_VERSION
}
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java
index b6cc0487ea..dc237b5ccc 100644
--- a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/CommandsHolder.java
@@ -35,6 +35,8 @@ public class CommandsHolder {
new HealAll().register();
new PopulateUserPermissions().register();
new AddContributorCommand().register();
+ new CleanUserDataCommand().register();
+ new DeletePublicVersionCommand().register();
}
private CommandsHolder() {
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java
new file mode 100644
index 0000000000..fee07501d4
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/commands/DeletePublicVersionCommand.java
@@ -0,0 +1,61 @@
+package org.openecomp.core.tools.commands;
+
+import static org.openecomp.core.tools.commands.CommandName.DELETE_PUBLIC_VERSION;
+
+import com.amdocs.zusammen.datatypes.Id;
+import com.amdocs.zusammen.datatypes.SessionContext;
+import com.amdocs.zusammen.datatypes.UserInfo;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.openecomp.core.zusammen.db.ZusammenConnector;
+import org.openecomp.core.zusammen.db.ZusammenConnectorFactory;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+public class DeletePublicVersionCommand extends Command {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DeletePublicVersionCommand.class);
+ private static final String ITEM_ID_OPTION = "i";
+ private static final String VERSION_ID_OPTION = "v";
+
+ DeletePublicVersionCommand() {
+ options.addOption(Option.builder(ITEM_ID_OPTION).hasArg().argName("item_id")
+ .desc("id of the item to delete from public, mandatory").build());
+ options.addOption(Option.builder(VERSION_ID_OPTION).hasArg().argName("version_id")
+ .desc("id of the version to delete from public, mandatory").build());
+ }
+
+ @Override
+ public boolean execute(String[] args) {
+ CommandLine cmd = parseArgs(args);
+ if (!cmd.hasOption(ITEM_ID_OPTION) || !cmd.hasOption(VERSION_ID_OPTION)) {
+ LOGGER.error("Arguments i and v are mandatory");
+ return false;
+ }
+ String itemId = cmd.getOptionValue(ITEM_ID_OPTION);
+ String versionId = cmd.getOptionValue(VERSION_ID_OPTION);
+
+ SessionContext context = createSessionContext();
+ ZusammenConnector zusammenConnector = ZusammenConnectorFactory.getInstance().createInterface();
+
+ try {
+ zusammenConnector.cleanVersion(context, new Id(itemId), new Id(versionId));
+ } catch (Exception e) {
+ LOGGER.error(String.format("Error occurred while deleting item %s version %s from public space", itemId,
+ versionId), e);
+ }
+ return true;
+ }
+
+ @Override
+ public CommandName getCommandName() {
+ return DELETE_PUBLIC_VERSION;
+ }
+
+ private static SessionContext createSessionContext() {
+ SessionContext sessionContext = new SessionContext();
+ sessionContext.setUser(new UserInfo("public"));
+ sessionContext.setTenant("dox");
+ return sessionContext;
+ }
+}