remove ODL/karaf from common
[ccsdk/sli/core.git] / sli / common / src / main / java / org / onap / ccsdk / sli / core / sli / SvcLogicStoreFactory.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                              reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.ccsdk.sli.core.sli;
23
24 import java.io.File;
25 import java.io.FileInputStream;
26 import java.io.InputStream;
27 import java.util.Properties;
28 import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class SvcLogicStoreFactory {
33
34         private static final Logger LOG = LoggerFactory.getLogger(SvcLogicStoreFactory.class);
35
36         public static SvcLogicStore getSvcLogicStore(String propfile)
37                         throws SvcLogicException {
38                 File propFile = new File(propfile);
39                 if (!propFile.canRead()) {
40                         throw new ConfigurationException("Cannot read property file "
41                                         + propfile);
42
43                 }
44
45                 try {
46                         return getSvcLogicStore(new FileInputStream(propFile));
47                 } catch (Exception e) {
48                         throw new ConfigurationException(
49                                         "Could load service store from properties file " + propfile,
50                                         e);
51                 }
52
53         }
54
55         public static SvcLogicStore getSvcLogicStore(InputStream inStr) throws SvcLogicException
56         {
57                 Properties props = new Properties();
58
59                 try {
60                         props.load(inStr);
61                 } catch (Exception e) {
62                         throw new ConfigurationException("Could not get load properties from input stream", e);
63                 }
64
65                 return getSvcLogicStore(props);
66         }
67
68         public static SvcLogicStore getSvcLogicStore(Properties props)
69                         throws SvcLogicException {
70                 String storeType = props.getProperty("org.onap.ccsdk.sli.dbtype");
71                 if ((storeType == null) || (storeType.length() == 0)) {
72                         throw new ConfigurationException(
73                                         "property org.onap.ccsdk.sli.dbtype unset");
74
75                 }
76
77                 SvcLogicStore retval;
78                 LOG.debug("Using org.onap.ccsdk.sli.dbtype={}", storeType);
79
80                 if ("jdbc".equalsIgnoreCase(storeType)) {
81                         retval = new SvcLogicJdbcStore();
82
83                 } else if ("dblib".equalsIgnoreCase(storeType)) {
84             retval = new SvcLogicDblibStore(new DBResourceManager(props));
85         } else {
86                         throw new ConfigurationException("unsupported dbtype (" + storeType
87                                         + ")");
88
89                 }
90
91
92                 retval.init(props);
93                 return retval;
94         }
95
96 }