020b2f3c47c3b4c76af5923231722243b0e724a3
[sdc.git] /
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()+File.separator, "");
25         String[] splitted = logicalPath.split(File.separator);
26         if(filterItem != null && splitted.length > 0 && !splitted[0].contains(filterItem)){
27             return;
28         }
29         switch (splitted.length) {
30             case 0:
31                 //root - ignore
32                 break;
33             case 1:     // handle Item
34                 new ItemImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
35                 new VersionInfoImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
36                 break;
37             case 2:
38                 //ignore this level
39                 break;
40             case 3: // handle version
41                 new VersionImport().loadPath(sessionContext,path,splitted[splitted.length -2]);
42                 break;
43             default:
44                 //handle elements
45                 new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted);
46                 break;
47         }
48
49     }
50
51 }