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=========================================================
21 package org.onap.policy.admin;
23 import org.onap.policy.common.logging.flexlogger.FlexLogger;
24 import org.onap.policy.common.logging.flexlogger.Logger;
25 import org.onap.policy.controller.ActionPolicyController;
26 import org.onap.policy.controller.CreateBRMSParamController;
27 import org.onap.policy.controller.CreateBRMSRawController;
28 import org.onap.policy.controller.CreateClosedLoopFaultController;
29 import org.onap.policy.controller.CreateClosedLoopPMController;
30 import org.onap.policy.controller.CreateDcaeMicroServiceController;
31 import org.onap.policy.controller.CreateFirewallController;
32 import org.onap.policy.controller.CreatePolicyController;
33 import org.onap.policy.controller.DecisionPolicyController;
34 import org.onap.policy.rest.adapter.PolicyRestAdapter;
35 import org.onap.policy.rest.jpa.PolicyEntity;
37 import com.att.research.xacml.util.XACMLProperties;
39 public class PolicyAdapter {
41 private static final Logger LOGGER = FlexLogger.getLogger(PolicyAdapter.class);
43 public void configure(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
44 if(extendedOptions(policyAdapter, entity)){
47 String policyNameValue = policyAdapter.getPolicyName().substring(0, policyAdapter.getPolicyName().indexOf('_'));
48 String configPolicyName = null ;
49 if(policyAdapter.getPolicyName().startsWith("Config_PM")){
50 configPolicyName = "ClosedLoop_PM";
51 }else if(policyAdapter.getPolicyName().startsWith("Config_Fault")){
52 configPolicyName = "ClosedLoop_Fault";
53 }else if(policyAdapter.getPolicyName().startsWith("Config_FW")){
54 configPolicyName = "Firewall Config";
55 }else if(policyAdapter.getPolicyName().startsWith("Config_BRMS_Raw")){
56 configPolicyName = "BRMS_Raw";
57 }else if(policyAdapter.getPolicyName().startsWith("Config_BRMS_Param")){
58 configPolicyName = "BRMS_Param";
59 }else if(policyAdapter.getPolicyName().startsWith("Config_MS")){
60 configPolicyName = "Micro Service";
61 }else if(policyAdapter.getPolicyName().startsWith("Action") || policyAdapter.getPolicyName().startsWith("Decision") ){
62 // No configPolicyName is applicable
64 configPolicyName = "Base";
66 if (policyNameValue != null) {
67 policyAdapter.setPolicyType(policyNameValue);
69 if (configPolicyName != null) {
70 policyAdapter.setConfigPolicyType(configPolicyName);
73 if("Action".equalsIgnoreCase(policyAdapter.getPolicyType())){
74 new ActionPolicyController().prePopulateActionPolicyData(policyAdapter, entity);
76 if("Decision".equalsIgnoreCase(policyAdapter.getPolicyType())){
77 new DecisionPolicyController().prePopulateDecisionPolicyData(policyAdapter, entity);
79 if("Config".equalsIgnoreCase(policyAdapter.getPolicyType())){
80 if("Base".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
81 new CreatePolicyController().prePopulateBaseConfigPolicyData(policyAdapter, entity);
83 else if("BRMS_Raw".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
84 new CreateBRMSRawController().prePopulateBRMSRawPolicyData(policyAdapter, entity);
86 else if("BRMS_Param".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
87 new CreateBRMSParamController().prePopulateBRMSParamPolicyData(policyAdapter, entity);
89 else if("ClosedLoop_Fault".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
90 new CreateClosedLoopFaultController().prePopulateClosedLoopFaultPolicyData(policyAdapter, entity);
92 else if("ClosedLoop_PM".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
93 new CreateClosedLoopPMController().prePopulateClosedLoopPMPolicyData(policyAdapter, entity);
95 else if("Micro Service".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
96 new CreateDcaeMicroServiceController().prePopulateDCAEMSPolicyData(policyAdapter, entity);
98 else if("Firewall Config".equalsIgnoreCase(policyAdapter.getConfigPolicyType())){
99 new CreateFirewallController().prePopulateFWPolicyData(policyAdapter, entity);
104 public boolean extendedOptions(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
108 public static PolicyAdapter getInstance() {
110 Class<?> policyAdapter = Class.forName(XACMLProperties.getProperty("policyAdapter.impl.className", PolicyAdapter.class.getName()));
111 return (PolicyAdapter) policyAdapter.newInstance();
112 } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException e) {
113 LOGGER.error("Exception Occured"+e);