1 package org.openecomp.core.tools.Commands.importdata;
3 import com.amdocs.zusammen.datatypes.SessionContext;
4 import org.openecomp.sdc.logging.api.Logger;
5 import org.openecomp.sdc.logging.api.LoggerFactory;
8 import java.io.IOException;
9 import java.nio.file.Files;
10 import java.nio.file.Path;
11 import java.util.stream.Stream;
13 public class TreeWalker {
14 private static final Logger logger = LoggerFactory.getLogger(TreeWalker.class);
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));
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);
28 String[] splitted = logicalPath.split(File.separator);
29 if(filterItem != null && splitted.length > 0 && !splitted[0].contains(filterItem)){
32 switch (splitted.length) {
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]);
43 case 3: // handle version
44 new VersionImport().loadPath(sessionContext,path,splitted[splitted.length -2]);
48 new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted);