2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modified Copyright (C) 2018 Samsung Electronics Co., Ltd.
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.
19 * ============LICENSE_END=========================================================
21 package org.onap.policy.pdp.rest.api.services;
25 import org.onap.policy.api.AttributeType;
26 import org.onap.policy.api.PolicyException;
27 import org.onap.policy.api.PolicyParameters;
28 import org.onap.policy.common.logging.flexlogger.FlexLogger;
29 import org.onap.policy.common.logging.flexlogger.Logger;
30 import org.onap.policy.pdp.rest.api.utils.PolicyApiUtils;
31 import org.onap.policy.utils.PolicyUtils;
32 import org.onap.policy.xacml.api.XACMLErrorConstants;
33 import org.onap.policy.xacml.std.pap.StdPAPPolicy;
34 import org.onap.policy.xacml.std.pap.StdPAPPolicyParams;
37 * BRMS RAW Policy Implementation.
41 public class BRMSRawPolicyService {
42 private static Logger LOGGER = FlexLogger.getLogger(BRMSRawPolicyService.class.getName());
43 private static PAPServices papServices = null;
45 private PolicyParameters policyParameters = null;
46 private String message = null;
47 private String policyName = null;
48 private String policyScope = null;
49 private String date = null;
50 private boolean levelCheck = false;
51 private String brmsRawBody = null;
53 public BRMSRawPolicyService(String policyName, String policyScope,
54 PolicyParameters policyParameters, String date) {
55 this.policyParameters = policyParameters;
56 this.policyName = policyName;
57 this.policyScope = policyScope;
59 papServices = new PAPServices();
62 public Boolean getValidation() {
63 brmsRawBody = policyParameters.getConfigBody();
64 if (brmsRawBody == null || brmsRawBody.trim().isEmpty()) {
65 message = XACMLErrorConstants.ERROR_DATA_ISSUE + " No Rule Body given";
68 message = PolicyUtils.brmsRawValidate(brmsRawBody);
69 if (message.contains("[ERR")) {
70 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Raw rule given is invalid" + message;
73 levelCheck = PolicyApiUtils.isNumeric(policyParameters.getRiskLevel());
75 message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Incorrect Risk Level given.";
81 public String getMessage() {
85 public String getResult(boolean updateFlag) throws PolicyException {
86 String response = null;
87 String operation = null;
93 Map<String, String> ruleAttributes = null;
94 if (policyParameters.getAttributes() != null) {
95 ruleAttributes = policyParameters.getAttributes().get(AttributeType.RULE);
98 StdPAPPolicy newPAPPolicy = new StdPAPPolicy(StdPAPPolicyParams.builder()
99 .configPolicyType("BRMS_Raw")
100 .policyName(policyName)
101 .description(policyParameters.getPolicyDescription())
102 .configName("BRMS_RAW_RULE")
103 .editPolicy(updateFlag)
105 .dynamicFieldConfigAttributes(ruleAttributes)
108 .configBodyData(brmsRawBody)
109 .riskLevel(policyParameters.getRiskLevel())
110 .riskType(policyParameters.getRiskType())
111 .guard(String.valueOf(policyParameters.getGuard()))
113 .brmsController(policyParameters.getControllerName())
114 .brmsDependency(policyParameters.getDependencyNames())
117 response = (String) papServices.callPAP(newPAPPolicy, new String[]{"operation=" + operation, "apiflag=api",
118 "policyType=Config"}, policyParameters.getRequestID(), "ConfigBrmsRaw");
119 LOGGER.info(response);