re base code
[sdc.git] / utils / webseal-simulator / src / main / java / org / openecomp / sdc / webseal / simulator / conf / Conf.java
1 package org.openecomp.sdc.webseal.simulator.conf;
2
3 import com.typesafe.config.Config;
4 import com.typesafe.config.ConfigFactory;
5 import org.openecomp.sdc.webseal.simulator.User;
6
7 import java.io.File;
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11
12 public class Conf {
13
14         private static Conf conf= null;         
15         private String feHost;
16         Map<String,User> users = new HashMap<String,User>();
17         
18         private Conf(){ 
19                 initConf();
20         }
21         
22         private void initConf() {
23                 try{
24                         String confPath = System.getProperty("config.resource");                        
25                         if (confPath == null){
26                                 System.out.println("config.resource is empty - goint to get it from config.home");
27                                 confPath = System.getProperty("config.home") + "/webseal.conf";
28                         }
29                         System.out.println("confPath=" + confPath );
30                         Config confFile = ConfigFactory.parseFileAnySyntax(new File(confPath));
31                         Config resolve = confFile.resolve();            
32                         setFeHost(resolve.getString("webseal.fe"));
33                         List<? extends Config> list = resolve.getConfigList("webseal.users");                   
34                         for (Config conf : list  ){
35                                 String userId = conf.getString("userId");
36                                 String password = conf.getString("password");
37                                 String firstName = conf.getString("firstName");
38                                 String lastName = conf.getString("lastName");
39                                 String email = conf.getString("email");
40                                 String role = conf.getString("role");
41                                 users.put(userId,new User(firstName,lastName,email,userId,role,password));                              
42                         }
43                                         
44                 }catch(Exception e){
45                         e.printStackTrace();
46                 }
47         }
48
49         public static Conf getInstance(){
50                 if (conf == null){
51                         conf = new Conf();
52                 }
53                 return conf;
54         }
55
56         public String getFeHost() {
57                 return feHost;
58         }
59
60         public void setFeHost(String feHost) {
61                 this.feHost = feHost;
62         }
63         
64         public Map<String,User> getUsers() {
65                 return users;
66         }       
67         
68 }