Reorder xacml 2.0.0 loading
[policy/xacml-pdp.git] / applications / common / src / main / java / org / onap / policy / pdp / xacml / application / common / std / StdMetadataTranslator.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 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
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.pdp.xacml.application.common.std;
24
25 import com.att.research.xacml.api.Request;
26 import com.att.research.xacml.api.Response;
27 import com.att.research.xacml.util.XACMLPolicyWriter;
28
29 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Map.Entry;
35
36 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
37
38 import org.onap.policy.models.decisions.concepts.DecisionRequest;
39 import org.onap.policy.models.decisions.concepts.DecisionResponse;
40 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyConversionException;
41 import org.onap.policy.pdp.xacml.application.common.ToscaPolicyTranslator;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 public class StdMetadataTranslator implements ToscaPolicyTranslator {
46
47     private static final Logger LOGGER = LoggerFactory.getLogger(StdMetadataTranslator.class);
48
49     public StdMetadataTranslator() {
50         super();
51     }
52
53     @SuppressWarnings("unchecked")
54     @Override
55     public List<PolicyType> scanAndConvertPolicies(Map<String, Object> toscaObject)
56             throws ToscaPolicyConversionException {
57         //
58         // Our return object
59         //
60         List<PolicyType> scannedPolicies = new ArrayList<>();
61         //
62         // Iterate each of the Policies
63         //
64         List<Object> policies = (List<Object>) toscaObject.get("policies");
65         for (Object policyObject : policies) {
66             //
67             // Get the contents
68             //
69             LOGGER.debug("Found policy {}", policyObject.getClass());
70             Map<String, Object> policyContents = (Map<String, Object>) policyObject;
71             for (Entry<String, Object> entrySet : policyContents.entrySet()) {
72                 LOGGER.debug("Entry set {}", entrySet);
73                 //
74                 // Convert this policy
75                 //
76                 PolicyType policy = this.convertPolicy(entrySet);
77                 try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
78                     XACMLPolicyWriter.writePolicyFile(os, policy);
79                     LOGGER.debug("{}", os);
80                 } catch (IOException e) {
81                     LOGGER.error("Failed to convert {}", e);
82                 }
83                 //
84                 // Convert and add in the new policy
85                 //
86                 scannedPolicies.add(policy);
87             }
88         }
89
90         return scannedPolicies;
91     }
92
93     @Override
94     public Request convertRequest(DecisionRequest request) {
95         // TODO Auto-generated method stub
96         return null;
97     }
98
99     @Override
100     public DecisionResponse convertResponse(Response xacmlResponse) {
101         // TODO Auto-generated method stub
102         return null;
103     }
104
105     private PolicyType convertPolicy(Entry<String, Object> entrySet) throws ToscaPolicyConversionException {
106
107         return null;
108     }
109
110 }