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;
7 import javax.validation.constraints.Min;
9 import java.io.IOException;
10 import java.nio.file.Files;
11 import java.nio.file.Path;
12 import java.util.ArrayList;
13 import java.util.Arrays;
14 import java.util.List;
15 import java.util.stream.Stream;
17 public class TreeWalker {
18 private static final Logger logger = LoggerFactory.getLogger(TreeWalker.class);
20 public static final void walkFiles(SessionContext sessionContext,Path rootDir, String filterItem) throws IOException {
21 try (Stream<Path> walk = Files.walk(rootDir)) {
22 walk.parallel().filter(path -> Files.isDirectory(path)).
23 forEach(path -> handlePath(sessionContext,path, rootDir, filterItem));
27 private static final void handlePath(SessionContext sessionContext, Path path, Path root,String filterItem) {
28 String logicalPath = path.toString().replace(root.toString(), "");
29 if (logicalPath.startsWith(File.separator)){
30 logicalPath = logicalPath.substring(1);
32 String[] splitted = logicalPath.split(File.separator);
33 if(filterItem != null && splitted.length > 0 && !splitted[0].contains(filterItem)){
36 switch (splitted.length) {
40 case 1: // handle Item
41 new ItemImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
42 new VersionInfoImport().loadPath(sessionContext,path,splitted[splitted.length -1]);
47 case 3: // handle version
48 new VersionImport().loadPath(sessionContext,path,splitted[splitted.length -2]);
52 new ElementImport().loadPath(sessionContext,path,splitted[splitted.length -1],splitted);