2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 package org.onap.clamp.clds.model.refprop;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Iterator;
29 import java.util.List;
30 import java.util.Properties;
32 import javax.annotation.PostConstruct;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.context.ApplicationContext;
37 import org.springframework.core.io.Resource;
39 import com.att.eelf.configuration.EELFLogger;
40 import com.att.eelf.configuration.EELFManager;
41 import com.fasterxml.jackson.databind.JsonNode;
42 import com.fasterxml.jackson.databind.ObjectMapper;
45 * Holds reference properties.
47 public class RefProp {
48 protected static final EELFLogger logger = EELFManager.getInstance().getLogger(RefProp.class);
49 protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
52 private ApplicationContext appContext;
54 private Properties prop;
56 @Value("${org.onap.clamp.config.files.cldsReference:'classpath:/clds/clds-reference.properties'}")
57 private String cldsReferenceValuesFile;
60 * Load reference properties via null constructor
64 public RefProp() throws IOException {
68 public void loadConfig() throws IOException {
69 prop = new Properties();
70 Resource resource = appContext.getResource(cldsReferenceValuesFile);
71 prop.load(resource.getInputStream());
80 public String getStringValue(String key) {
81 return prop.getProperty(key);
85 * get property value for a combo key (key1 + "." + key2). If not found just
92 public String getStringValue(String key1, String key2) {
93 String value = getStringValue(key1 + "." + key2);
94 if (value == null || value.length() == 0) {
95 value = getStringValue(key1);
101 * Return json as objects that can be updated
105 * @throws IOException
107 public JsonNode getJsonTemplate(String key) throws IOException {
108 ObjectMapper objectMapper = new ObjectMapper();
109 return objectMapper.readValue(getStringValue(key), JsonNode.class);
113 * Return json as objects that can be updated. First try with combo key
114 * (key1 + "." + key2), otherwise default to just key1.
119 * @throws IOException
121 public JsonNode getJsonTemplate(String key1, String key2) throws IOException {
122 ObjectMapper objectMapper = new ObjectMapper();
123 return objectMapper.readValue(getStringValue(key1, key2), JsonNode.class);
127 * Get list of values for a property field containing json and a
128 * field/keyword within that json.
133 * @throws IOException
135 public List<String> decodeToList(String fieldName, String value) throws IOException {
136 JsonNode decode = getJsonTemplate(fieldName);
137 Iterator<JsonNode> itr = decode.path(value).elements();
138 ArrayList<String> al = new ArrayList<>();
139 while (itr.hasNext()) {
140 JsonNode node = itr.next();
141 al.add(node.asText());