fix incorrect dependency
[sdc.git] / openecomp-be / tools / zusammen-tools / src / main / java / org / openecomp / core / tools / Commands / importdata / TreeWalker.java
1 package org.openecomp.core.tools.Commands.importdata;
2
3 import com.amdocs.zusammen.datatypes.SessionContext;
4 import org.openecomp.sdc.logging.api.Logger;
5 import org.openecomp.sdc.logging.api.LoggerFactory;
6
7 import java.io.File;
8 import java.io.IOException;
9 import java.nio.file.Files;
10 import java.nio.file.Path;
11 import java.util.stream.Stream;
12
13 public class TreeWalker {
14     private static final Logger logger = LoggerFactory.getLogger(TreeWalker.class);
15
16     public static final void walkFiles(SessionContext sessionContext,Path rootDir, String filterItem) throws IOException {
17         try (Stream<Path> walk = Files.walk(rootDir)) {
18             walk.parallel().filter(path -> Files.isDirectory(path)).
19                     forEach(path -> handlePath(sessionContext,path, rootDir, filterItem));
20         }
21     }
22
23     private static final void handlePath(SessionContext sessionContext, Path path, Path root,String filterItem) {
24         String logicalPath = path.toString().replace(root.toString(), "");
25         if (logicalPath.startsWith(File.separator)){
26             logicalPath = logicalPath.substring(1);
27         }
28         String[] splitted = logicalPath.split(File.separator);
29         if(filterItem != null && splitted.length > 0 && !splitted[0].contains(filterItem)){
30             return;
31         }
32         switch (splitted.length) {
33             case 0:
34                 //root - ignore
35                 break;
36             case 1:     // handle Item
37                 new ItemImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
38                 new VersionInfoImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
39                 break;
40             case 2:
41                 //ignore this level
42                 break;
43             case 3: // handle version
44                 new VersionImport().loadPath(sessionContext,path,splitted[splitted.length -2]);
45                 break;
46             default:
47                 //handle elements
48                  new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted);
49                 break;
50         }
51
52     }
53
54 }