re base code
[sdc.git] / asdctool / src / main / java / org / openecomp / sdc / asdctool / simulator / tenant / ImportCassandraTableTool.java
1 package org.openecomp.sdc.asdctool.simulator.tenant;
2
3 import org.openecomp.sdc.be.config.ConfigurationManager;
4 import org.openecomp.sdc.common.api.ConfigurationSource;
5 import org.openecomp.sdc.common.impl.ExternalConfiguration;
6 import org.openecomp.sdc.common.impl.FSConfigurationSource;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9
10 import java.util.HashMap;
11 import java.util.Map;
12 import java.util.function.Consumer;
13
14 /**
15  * Main class of utility imports CSV file into the specified table
16  * The old stuff of the table is removed.
17  * 
18  * Accepts 3 mandatory arguments:
19  *                      1. Path to configuration folder
20  *                      2. Name of the table
21  *                      3. Path to the CSV file
22  *   
23  *  Example of usage:
24  *              \src\main\resources\config\ operationalenvironment "C:\Users\dr2032\Documents\env.csv"
25  *  
26  *  See relevant import handler for example of csv file line. 
27  *  
28  *  The list of supported tables:
29  *              1. operationalenvironment
30  *  
31  *  
32  * @author dr2032
33  *
34  */
35 public class ImportCassandraTableTool {
36         private static final Logger LOGGER = LoggerFactory.getLogger(ImportCassandraTableTool.class);
37         
38         private static Map<String, Consumer<String>> mapHandlers = new HashMap<>();
39         
40         static {
41                 mapHandlers.put(OperationalEvnironmentImportHandler.getTableName().toLowerCase(), OperationalEvnironmentImportHandler::execute);
42         }
43         
44         public static void main(String[] args) {
45                 if(args.length == 3) {
46                         String appConfigDir = args[0];
47                         String tableName = args[1];
48                         String fileName = args[2];
49                         
50                         ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
51                         new ConfigurationManager(configurationSource);
52                 
53                         Consumer<String> executor = mapHandlers.get(tableName.toLowerCase());
54                         if (executor != null) {
55                                 executor.accept(fileName);
56                         } 
57                         else {
58                                 LOGGER.warn("Import to table [{}] is not supported yet!", tableName);
59                         }
60                 }
61                 else {
62                         LOGGER.warn("Invalid number of arguments. The 1st shoduld be path to config dir, the 2nd - table name and the 3rd - path to CSV file.");
63                 }
64                 
65                 
66                 System.exit(0);
67         }
68         
69 }