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() {
51 public StdPDPPIPConfig(String id) {
55 public StdPDPPIPConfig(String id, String name, String description) {
58 this.description = description;
61 public StdPDPPIPConfig(String id, Properties properties) {
63 if ( ! this.initialize(properties) ) {
64 throw new IllegalArgumentException("PIP Engine '" + id + "' has no classname property in config");
68 public boolean initialize(Properties properties) {
69 boolean classnameSeen = false;
70 for (Object key : properties.keySet()) {
71 if (key.toString().startsWith(this.id + ".")) {
72 if (logger.isDebugEnabled()) {
73 logger.debug("Found: " + key);
75 if (key.toString().equals(this.id + ".name")) {
76 this.name = properties.getProperty(key.toString());
77 } else if (key.toString().equals(this.id + ".description")) {
78 this.description = properties.getProperty(key.toString());
79 } else if (key.toString().equals(this.id + ".classname")) {
80 this.classname = properties.getProperty(key.toString());
83 // all properties, including the special ones located above, are included in the properties list
84 this.config.put(key.toString(), properties.getProperty(key.toString()));
91 public String getId() {
95 public void setId(String id) {
100 public String getName() {
104 public void setName(String name) {
109 public String getDescription() {
110 return this.description;
113 public void setDescription(String description) {
114 this.description = description;
118 public String getClassname() {
122 public void setClassname(String classname) {
123 this.classname = classname;
128 public Map<String,String> getConfiguration() {
129 return Collections.unmodifiableMap(this.config);
132 public void setValues(Map<String,String> config) {
133 this.config = config;
138 public boolean isConfigured() {
140 // Also include this in the JSON I/O if it is a data field rather than calculated
146 public int hashCode() {
147 final int prime = 31;
149 result = prime * result
150 + ((classname == null) ? 0 : classname.hashCode());
151 result = prime * result + ((config == null) ? 0 : config.hashCode());
152 result = prime * result
153 + ((description == null) ? 0 : description.hashCode());
154 result = prime * result + ((id == null) ? 0 : id.hashCode());
155 result = prime * result + ((name == null) ? 0 : name.hashCode());
160 public boolean equals(Object obj) {
165 if (getClass() != obj.getClass())
167 StdPDPPIPConfig other = (StdPDPPIPConfig) obj;
168 if (classname == null) {
169 if (other.classname != null)
171 } else if (!classname.equals(other.classname))
173 if (config == null) {
174 if (other.config != null)
176 } else if (!config.equals(other.config))
178 if (description == null) {
179 if (other.description != null)
181 } else if (!description.equals(other.description))
184 if (other.id != null)
186 } else if (!id.equals(other.id))
189 if (other.name != null)
191 } else if (!name.equals(other.name))
197 public String toString() {
198 return "StdPDPPIPConfig [id=" + id + ", name=" + name
199 + ", description=" + description + ", classname=" + classname
200 + ", config=" + config + "]";
206 // Methods needed for JSON serialization/deserialization
209 public Map<String, String> getConfig() {
212 public void setConfig(Map<String, String> config) {
213 this.config = config;