2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.policy.xacml.std.pap;
22 import java.io.Serializable;
23 import java.util.Collections;
24 import java.util.HashMap;
26 import java.util.Properties;
28 import com.att.research.xacml.api.pap.PDPPIPConfig;
29 import com.fasterxml.jackson.annotation.JsonIgnore;
30 import org.onap.policy.common.logging.flexlogger.FlexLogger;
31 import org.onap.policy.common.logging.flexlogger.Logger;
33 public class StdPDPPIPConfig implements PDPPIPConfig, Serializable {
34 private static final long serialVersionUID = 1L;
35 private static Logger logger = FlexLogger.getLogger(StdPDPPIPConfig.class);
41 private String description;
43 private String classname;
45 private Map<String,String> config = new HashMap<>();
47 public StdPDPPIPConfig() {
49 // Default constructor
53 public StdPDPPIPConfig(String id) {
57 public StdPDPPIPConfig(String id, String name, String description) {
60 this.description = description;
63 public StdPDPPIPConfig(String id, Properties properties) {
65 if ( ! this.initialize(properties) ) {
66 throw new IllegalArgumentException("PIP Engine '" + id + "' has no classname property in config");
70 public boolean initialize(Properties properties) {
71 boolean classnameSeen = false;
72 for (Object key : properties.keySet()) {
73 if (key.toString().startsWith(this.id + ".")) {
74 if (logger.isDebugEnabled()) {
75 logger.debug("Found: " + key);
77 if (key.toString().equals(this.id + ".name")) {
78 this.name = properties.getProperty(key.toString());
79 } else if (key.toString().equals(this.id + ".description")) {
80 this.description = properties.getProperty(key.toString());
81 } else if (key.toString().equals(this.id + ".classname")) {
82 this.classname = properties.getProperty(key.toString());
85 // all properties, including the special ones located above, are included in the properties list
86 this.config.put(key.toString(), properties.getProperty(key.toString()));
93 public String getId() {
97 public void setId(String id) {
102 public String getName() {
106 public void setName(String name) {
111 public String getDescription() {
112 return this.description;
115 public void setDescription(String description) {
116 this.description = description;
120 public String getClassname() {
124 public void setClassname(String classname) {
125 this.classname = classname;
130 public Map<String,String> getConfiguration() {
131 return Collections.unmodifiableMap(this.config);
134 public void setValues(Map<String,String> config) {
135 this.config = config;
140 public boolean isConfigured() {
142 // Also include this in the JSON I/O if it is a data field rather than calculated
148 public int hashCode() {
149 final int prime = 31;
151 result = prime * result
152 + ((classname == null) ? 0 : classname.hashCode());
153 result = prime * result + ((config == null) ? 0 : config.hashCode());
154 result = prime * result
155 + ((description == null) ? 0 : description.hashCode());
156 result = prime * result + ((id == null) ? 0 : id.hashCode());
157 result = prime * result + ((name == null) ? 0 : name.hashCode());
162 public boolean equals(Object obj) {
167 if (getClass() != obj.getClass())
169 StdPDPPIPConfig other = (StdPDPPIPConfig) obj;
170 if (classname == null) {
171 if (other.classname != null)
173 } else if (!classname.equals(other.classname))
175 if (config == null) {
176 if (other.config != null)
178 } else if (!config.equals(other.config))
180 if (description == null) {
181 if (other.description != null)
183 } else if (!description.equals(other.description))
186 if (other.id != null)
188 } else if (!id.equals(other.id))
191 if (other.name != null)
193 } else if (!name.equals(other.name))
199 public String toString() {
200 return "StdPDPPIPConfig [id=" + id + ", name=" + name
201 + ", description=" + description + ", classname=" + classname
202 + ", config=" + config + "]";
208 // Methods needed for JSON serialization/deserialization
211 public Map<String, String> getConfig() {
214 public void setConfig(Map<String, String> config) {
215 this.config = config;