summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java')
-rw-r--r--openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java
new file mode 100644
index 0000000000..57486b81e3
--- /dev/null
+++ b/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/Commands/ImportCommand.java
@@ -0,0 +1,43 @@
+package org.openecomp.core.tools.Commands;
+
+import com.amdocs.zusammen.datatypes.SessionContext;
+import org.apache.commons.io.FileUtils;
+import org.openecomp.core.tools.Commands.importdata.TreeWalker;
+import org.openecomp.core.tools.Commands.exportdata.ImportProperties;
+import org.openecomp.core.tools.util.ZipUtils;
+import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer;
+import org.openecomp.sdc.logging.api.Logger;
+import org.openecomp.sdc.logging.api.LoggerFactory;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class ImportCommand {
+
+ private static final Logger logger = LoggerFactory.getLogger(ImportCommand.class);
+
+
+ public static void importData(SessionContext context, String zippedFile, String filterItem) {
+ try {
+ ImportProperties.initParams();
+ CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
+ if (zippedFile == null){
+ logger.error("Import must have a valid file as an input.");
+ }
+ zippedFile = zippedFile.replaceAll("\\r", "");
+ if(filterItem != null) {
+ filterItem = filterItem.replaceAll("\\r", "");
+ }
+ Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
+ ExportDataCommand.initDir(rootDir);
+ ZipUtils.unzip(Paths.get(zippedFile), rootDir);
+ TreeWalker.walkFiles(context, rootDir, filterItem);
+
+ FileUtils.forceDelete(rootDir.toFile()); // clear all unzip data at the end.
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ ex.printStackTrace();
+ }
+ }
+
+}