Update css file name in conf.py
[policy/engine.git] / PolicyEngineClient / src / test / java / org / onap / policyengine / BrmsParamPolicyClient.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineClient
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
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policyengine;
22
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.UUID;
28
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;
34
35 public class BrmsParamPolicyClient {
36
37     /**
38      * main.
39      *
40      * @param args String[] of arguments
41      */
42     public static void main(String[] args) {
43         try {
44
45             PolicyParameters policyParameters = new PolicyParameters();
46
47             // Set Policy Type(Mandatory)
48             policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
49
50             // Set Policy Name(Mandatory)
51             policyParameters.setPolicyName("Lakshman.testParamPolicyThree");
52
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");
63
64             // Set description of the policy(Optional)
65             policyParameters.setPolicyDescription("This is a sample BRMS Param policy creation example");
66
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
71             // name.
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);
78
79             // Set a random UUID(Mandatory)
80             policyParameters.setRequestID(UUID.randomUUID());
81
82             // CreatePolicy method to create Policy.
83
84             PolicyEngine policyEngine = new PolicyEngine("config.properties");
85             PolicyChangeResponse response = policyEngine.updatePolicy(policyParameters);
86
87             if (response.getResponseCode() == 200) {
88                 System.out.println(response.getResponseMessage());
89                 System.out.println("Policy Created Successfully!");
90             } else {
91                 System.out.println("Error! " + response.getResponseMessage());
92             }
93         } catch (Exception e) {
94             System.err.println(e.getMessage() + e);
95         }
96
97     }
98
99 }