2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2020 Nordix Foundation.
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.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.pdp.xacml.application.common.matchable;
26 import com.att.research.xacml.api.Identifier;
27 import com.att.research.xacml.std.IdentifierImpl;
28 import java.util.Collections;
30 import java.util.Map.Entry;
31 import lombok.NonNull;
32 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
35 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
36 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslatorUtils;
38 public class MatchablePropertyTypeMap extends MatchablePropertyTypeBase<Map<String, MatchablePropertyType<?>>> {
39 MatchableProperty primitiveProperty;
44 * @param toscaProperty ToscaProperty object
46 public MatchablePropertyTypeMap(@NonNull ToscaProperty toscaProperty) {
49 ToscaSchemaDefinition schema = toscaProperty.getEntrySchema();
50 this.primitiveProperty = MatchablePolicyType.handlePrimitive(schema.getType(), schema);
53 @SuppressWarnings("unchecked")
55 public Map<String, MatchablePropertyType<?>> validate(Object value) throws ToscaPolicyConversionException {
56 if (value instanceof Map) {
57 return (Map<String, MatchablePropertyType<?>>) value;
59 return Collections.emptyMap();
63 public Object generate(Object value, Identifier attributeId) throws ToscaPolicyConversionException {
64 var anyOf = new AnyOfType();
65 for (Entry<String, MatchablePropertyType<?>> entrySet : this.validate(value).entrySet()) {
66 final String id = entrySet.getKey();
67 final Object val = entrySet.getValue();
69 // For map we use the LHS as part of the attribute id
71 Identifier newId = new IdentifierImpl(attributeId + ":" + id);
73 // Build the AnyOfType
75 anyOf = ToscaPolicyTranslatorUtils.buildAndAppendAllof(anyOf,
76 primitiveProperty.getType().generate(val, newId));