summaryrefslogtreecommitdiffstats
path: root/openecomp-be/tools/zusammen-tools/src/main/java/org/openecomp/core/tools/importinfo/ImportDataCommand.java
blob: 17b7d64cb4a5d0303e70517d39f91ddddc6a1904 (plain)
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
package org.openecomp.core.tools.importinfo;


import org.apache.commons.io.FileUtils;
import org.openecomp.core.tools.exportinfo.ExportDataCommand;
import org.openecomp.core.tools.util.Utils;
import org.openecomp.core.tools.util.ZipUtils;
import org.openecomp.core.zusammen.impl.CassandraConnectionInitializer;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Stream;

public class ImportDataCommand {

    private static final Logger logger = LoggerFactory.getLogger(ImportDataCommand.class);

    public static void execute(String uploadFile) {
        try {
            CassandraConnectionInitializer.setCassandraConnectionPropertiesToSystem();
            Path outputFolder = Paths.get(ImportProperties.ROOT_DIRECTORY);
            ExportDataCommand.initDir(outputFolder); //clear old imports.
            ZipUtils.unzip(Paths.get(uploadFile), outputFolder);
            try( Stream<Path> files = Files.list(outputFolder)) {
                files.forEach(new ImportSingleTable()::importFile);
            }
            FileUtils.forceDelete(outputFolder.toFile()); // leaves directory clean
        } catch (IOException e) {
            Utils.logError(logger, e);
        }
    }
}