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