org.onap migration
[vid.git] / vid-automation / src / main / java / vid / automation / test / services / ServicesService.java
1 package vid.automation.test.services;
2
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import org.openecomp.sdc.ci.tests.utilities.FileHandling;
5 import vid.automation.test.model.Service;
6 import vid.automation.test.model.ServicesObject;
7
8 import java.io.File;
9 import java.io.IOException;
10 import java.util.HashMap;
11
12 /**
13  * Created by itzikliderman on 08/09/2017.
14  */
15 public class ServicesService {
16     private HashMap<String, Service> services;
17
18     public ServicesService() throws IOException {
19         services = getServicesFromJson();
20
21     }
22
23     HashMap<String, Service> getServicesFromJson() throws IOException {
24         String fileName = "services";
25         ObjectMapper mapper = new ObjectMapper();
26         ServicesObject servicesObject;
27         try {
28             File servicesFile = FileHandling.getConfigFile(fileName);
29             if(!servicesFile.exists()) {
30                 String basePath = System.getProperty("BASE_PATH");
31                 servicesFile = new File( basePath + File.separator + "conf" + File.separator + fileName);
32             }
33             servicesObject = mapper.readValue(servicesFile, ServicesObject.class);
34             return servicesObject.services;
35         } catch (IOException e) {
36             e.printStackTrace();
37             return null;
38         } catch (Exception e) {
39             e.printStackTrace();
40             return null;
41         }
42     }
43
44     public Service getService(String serviceId) {
45         return services.get(serviceId);
46     }
47 }