2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 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=========================================================
21 package org.onap.policy.xacml.std.pap;
23 import com.att.research.xacml.api.pap.PDPPIPConfig;
24 import com.fasterxml.jackson.annotation.JsonIgnore;
26 import java.io.Serializable;
27 import java.util.Collections;
28 import java.util.HashMap;
30 import java.util.Properties;
31 import lombok.EqualsAndHashCode;
32 import lombok.ToString;
34 @EqualsAndHashCode(callSuper = false)
36 public class StdPDPPIPConfig implements PDPPIPConfig, Serializable {
37 private static final long serialVersionUID = 1L;
43 private String description;
45 private String classname;
47 private Map<String, String> config = new HashMap<>();
49 public StdPDPPIPConfig() {
51 // Default constructor
55 public StdPDPPIPConfig(String id) {
64 * @param description String
66 public StdPDPPIPConfig(String id, String name, String description) {
69 this.description = description;
76 * @param properties Properties
78 public StdPDPPIPConfig(String id, Properties properties) {
80 if (!this.initialize(properties)) {
81 throw new IllegalArgumentException("PIP Engine '" + id + "' has no classname property in config");
88 * @param properties Properties
91 public boolean initialize(Properties properties) {
92 boolean classnameSeen = false;
93 for (Object key : properties.keySet()) {
94 if (key.toString().startsWith(this.id + ".")) {
95 if (key.toString().equals(this.id + ".name")) {
96 this.name = properties.getProperty(key.toString());
97 } else if (key.toString().equals(this.id + ".description")) {
98 this.description = properties.getProperty(key.toString());
99 } else if (key.toString().equals(this.id + ".classname")) {
100 this.classname = properties.getProperty(key.toString());
101 classnameSeen = true;
103 // all properties, including the special ones located above, are included in the properties list
104 this.config.put(key.toString(), properties.getProperty(key.toString()));
107 return classnameSeen;
111 public String getId() {
115 public void setId(String id) {
120 public String getName() {
124 public void setName(String name) {
129 public String getDescription() {
130 return this.description;
133 public void setDescription(String description) {
134 this.description = description;
138 public String getClassname() {
142 public void setClassname(String classname) {
143 this.classname = classname;
148 public Map<String, String> getConfiguration() {
149 return Collections.unmodifiableMap(this.config);
152 public void setValues(Map<String, String> config) {
153 this.config = config;
158 public boolean isConfigured() {
160 // Also include this in the JSON I/O if it is a data field rather than calculated
166 // Methods needed for JSON serialization/deserialization
169 public Map<String, String> getConfig() {
173 public void setConfig(Map<String, String> config) {
174 this.config = config;