fix incorrect dependency
[sdc.git] / openecomp-be / tools / zusammen-tools / src / main / java / org / openecomp / core / tools / Commands / ImportCommand.java
1 package org.openecomp.core.tools.Commands;
2
3 import com.amdocs.zusammen.datatypes.SessionContext;
4 import org.apache.commons.io.FileUtils;
5 import org.openecomp.core.tools.Commands.importdata.TreeWalker;
6 import org.openecomp.core.tools.Commands.exportdata.ImportProperties;
7 import org.openecomp.core.tools.util.ZipUtils;
8 import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer;
9 import org.openecomp.sdc.logging.api.Logger;
10 import org.openecomp.sdc.logging.api.LoggerFactory;
11
12 import java.nio.file.Path;
13 import java.nio.file.Paths;
14
15 public class ImportCommand {
16
17     private static final Logger logger = LoggerFactory.getLogger(ImportCommand.class);
18
19
20     public static void importData(SessionContext context, String zippedFile, String filterItem) {
21         try {
22             ImportProperties.initParams();
23             CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
24             if (zippedFile == null){
25                 logger.error("Import must have a valid file as an input.");
26             }
27             if (zippedFile != null) {
28                 zippedFile = zippedFile.replaceAll("\\r", "");
29                 if (filterItem != null) {
30                     filterItem = filterItem.replaceAll("\\r", "");
31                 }
32                 Path rootDir = Paths.get(ImportProperties.ROOT_DIRECTORY);
33                 ExportDataCommand.initDir(rootDir);
34                 ZipUtils.unzip(Paths.get(zippedFile), rootDir);
35                 TreeWalker.walkFiles(context, rootDir, filterItem);
36                 FileUtils.forceDelete(rootDir.toFile()); // clear all unzip data at the end.
37             }
38
39
40         } catch (Exception ex) {
41             logger.error(ex.getMessage(), ex);
42         }
43     }
44
45 }