2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 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
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.policyengine;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.HashMap;
27 import java.util.UUID;
29 import org.onap.policy.api.AttributeType;
30 import org.onap.policy.api.PolicyChangeResponse;
31 import org.onap.policy.api.PolicyConfigType;
32 import org.onap.policy.api.PolicyEngine;
33 import org.onap.policy.api.PolicyParameters;
35 public class BrmsParamPolicyClient {
40 * @param args String[] of arguments
42 public static void main(String[] args) {
45 PolicyParameters policyParameters = new PolicyParameters();
47 // Set Policy Type(Mandatory)
48 policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
50 // Set Policy Name(Mandatory)
51 policyParameters.setPolicyName("Lakshman.testParamPolicyThree");
53 // Set Safe Policy value for Risk Type
54 SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
55 Date date = dateformat3.parse("15/10/2016");
56 policyParameters.setTtlDate(date);
57 // Set Safe Policy value for Guard
58 policyParameters.setGuard(true);
59 // Set Safe Policy value for Risk Level
60 policyParameters.setRiskLevel("5");
61 // Set Safe Policy value for Risk Type
62 policyParameters.setRiskType("PROD");
64 // Set description of the policy(Optional)
65 policyParameters.setPolicyDescription("This is a sample BRMS Param policy creation example");
67 // Set BRMS Param Template Attributes(Mandatory)
68 Map<String, String> ruleAttributes = new HashMap<>();
69 ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary.
70 // Set Rule to a PDP Controller, default is the controller
72 ruleAttributes.put("controller", "default");
73 ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us.
74 ruleAttributes.put("value", "abcd"); // Template specific key and value set by us.
75 Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
76 attributes.put(AttributeType.RULE, ruleAttributes);
77 policyParameters.setAttributes(attributes);
79 // Set a random UUID(Mandatory)
80 policyParameters.setRequestID(UUID.randomUUID());
82 // CreatePolicy method to create Policy.
84 PolicyEngine policyEngine = new PolicyEngine("config.properties");
85 PolicyChangeResponse response = policyEngine.updatePolicy(policyParameters);
87 if (response.getResponseCode() == 200) {
88 System.out.println(response.getResponseMessage());
89 System.out.println("Policy Created Successfully!");
91 System.out.println("Error! " + response.getResponseMessage());
93 } catch (Exception e) {
94 System.err.println(e.getMessage() + e);