Add new Match application to XACML
[policy/xacml-pdp.git] / applications / match / src / main / java / org / onap / policy / xacml / pdp / application / match / MatchPdpApplication.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.xacml.pdp.application.match;
24
25 import java.nio.file.Path;
26 import java.util.Arrays;
27 import java.util.List;
28 import org.onap.policy.common.endpoints.parameters.RestServerParameters;
29 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
30 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
31 import org.onap.policy.pdp.xacml.application.common.XacmlApplicationException;
32 import org.onap.policy.pdp.xacml.application.common.std.StdMatchableTranslator;
33 import org.onap.policy.pdp.xacml.application.common.std.StdXacmlApplicationServiceProvider;
34
35 public class MatchPdpApplication extends StdXacmlApplicationServiceProvider {
36
37     public static final String ONAP_MATCH_BASE_POLICY_TYPE = "onap.policies.Match";
38     public static final String ONAP_MATCH_DERIVED_POLICY_TYPE = "onap.policies.match.";
39
40     private static final ToscaPolicyTypeIdentifier supportedPolicy = new ToscaPolicyTypeIdentifier(
41             ONAP_MATCH_BASE_POLICY_TYPE, "1.0.0");
42
43     private StdMatchableTranslator translator = new StdMatchableTranslator();
44
45     @Override
46     public String applicationName() {
47         return "match";
48     }
49
50     @Override
51     public List<String> actionDecisionsSupported() {
52         return Arrays.asList("match");
53     }
54
55     @Override
56     public void initialize(Path pathForData, RestServerParameters policyApiParameters)
57             throws XacmlApplicationException {
58         //
59         // Store our API parameters and path for translator so it
60         // can go get Policy Types
61         //
62         this.translator.setPathForData(pathForData);
63         this.translator.setApiRestParameters(policyApiParameters);
64         //
65         // Let our super class do its thing
66         //
67         super.initialize(pathForData, policyApiParameters);
68     }
69
70     @Override
71     public synchronized List<ToscaPolicyTypeIdentifier> supportedPolicyTypes() {
72         return Arrays.asList(supportedPolicy);
73     }
74
75     @Override
76     public boolean canSupportPolicyType(ToscaPolicyTypeIdentifier policyTypeId) {
77         return policyTypeId.getName().startsWith(ONAP_MATCH_DERIVED_POLICY_TYPE);
78     }
79
80     @Override
81     protected ToscaPolicyTranslator getTranslator(String type) {
82         return translator;
83     }
84
85 }