Adding UI extensibility
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / dal / aai / config / ActiveInventoryRestConfig.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.dal.aai.config;
24
25 import java.util.Arrays;
26 import java.util.List;
27 import java.util.Properties;
28
29 import org.onap.aai.sparky.dal.aai.enums.RestAuthenticationMode;
30 import org.onap.aai.sparky.util.ConfigHelper;
31
32 /**
33  * The Class ActiveInventoryRestConfig.
34  */
35 public class ActiveInventoryRestConfig {
36
37   private String host;
38
39   private String port;
40
41   private int connectTimeoutInMs;
42
43   private int readTimeoutInMs;
44
45   private int numRequestRetries;
46
47   private int numResolverWorkers;
48
49   private List<String> shallowEntities;
50
51   private RestAuthenticationMode authenticationMode;
52
53   public List<String> getShallowEntities() {
54     return shallowEntities;
55   }
56
57   /**
58    * Instantiates a new active inventory rest config.
59    *
60    * @param props the props
61    */
62   public ActiveInventoryRestConfig(Properties props) {
63
64     if (props == null || props.isEmpty()) {
65       return;
66     }
67
68     Properties restProps = ConfigHelper.getConfigWithPrefix("aai.rest", props);
69
70     host = restProps.getProperty("host", "localhost");
71     port = restProps.getProperty("port", "8443");
72     numRequestRetries = Integer.parseInt(restProps.getProperty("numRequestRetries", "5"));
73     numResolverWorkers = Integer.parseInt(restProps.getProperty("numResolverWorkers", "15"));
74
75     connectTimeoutInMs = Integer.parseInt(restProps.getProperty("connectTimeoutInMs", "5000"));
76     readTimeoutInMs = Integer.parseInt(restProps.getProperty("readTimeoutInMs", "10000"));
77
78     String shallowEntitiesProperty = restProps.getProperty("shallowEntities", "");
79     shallowEntities = Arrays.asList(shallowEntitiesProperty.split(","));
80
81     authenticationMode =
82         RestAuthenticationMode.getRestAuthenticationMode(restProps.getProperty("authenticationMode",
83             RestAuthenticationMode.SSL_CERT.getAuthenticationModeLabel()));
84
85     /*
86      * In any kind of error scenario, set the authentication mode to SSL_CERT as our default. This
87      * is an arbitrary default, but was chosen based on the way this code worked before introduction
88      * of the SSL Basic Auth settings.
89      */
90     if (authenticationMode == RestAuthenticationMode.UNKNOWN_MODE) {
91       authenticationMode = RestAuthenticationMode.SSL_CERT;
92     }
93
94   }
95
96   public RestAuthenticationMode getAuthenticationMode() {
97     return authenticationMode;
98   }
99
100   public void setAuthenticationMode(RestAuthenticationMode authenticationMode) {
101     this.authenticationMode = authenticationMode;
102   }
103
104
105   /**
106    * Checks if is shallow entity.
107    *
108    * @param entityType the entity type
109    * @return true, if is shallow entity
110    */
111   public boolean isShallowEntity(String entityType) {
112     if (entityType == null) {
113       return false;
114     }
115
116     for (String entity : shallowEntities) {
117       if (entityType.equalsIgnoreCase(entity)) {
118         return true;
119       }
120     }
121
122     return false;
123   }
124
125   public int getNumResolverWorkers() {
126     return numResolverWorkers;
127   }
128
129   public void setNumResolverWorkers(int numResolverWorkers) {
130     this.numResolverWorkers = numResolverWorkers;
131   }
132
133   public String getHost() {
134     return host;
135   }
136
137   public String getPort() {
138     return port;
139   }
140
141   public void setHost(String host) {
142     this.host = host;
143   }
144
145   public void setPort(String port) {
146     this.port = port;
147   }
148
149   public int getConnectTimeoutInMs() {
150     return connectTimeoutInMs;
151   }
152
153   public void setConnectTimeoutInMs(int connectTimeoutInMs) {
154     this.connectTimeoutInMs = connectTimeoutInMs;
155   }
156
157   public int getReadTimeoutInMs() {
158     return readTimeoutInMs;
159   }
160
161   public void setReadTimeoutInMs(int readTimeoutInMs) {
162     this.readTimeoutInMs = readTimeoutInMs;
163   }
164
165   public int getNumRequestRetries() {
166     return numRequestRetries;
167   }
168
169   public void setNumRequestRetries(int numRequestRetries) {
170     this.numRequestRetries = numRequestRetries;
171   }
172
173 }