[POLICY-11] Sample Query with variable arguments
[policy/drools-applications.git] / template.demo / src / main / java / org / openecomp / policy / template / demo / PolicyEngine.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * demo
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
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.openecomp.policy.template.demo;
22  
23  import java.util.HashMap;
24  import java.util.LinkedList;
25  import java.util.Map;
26  import java.util.Queue;
27  
28  import org.openecomp.policy.controlloop.VirtualControlLoopNotification;
29  import org.openecomp.policy.appc.Request;
30  import org.openecomp.policy.controlloop.util.Serialization;
31  
32  
33  public class PolicyEngine {
34  
35         private static Map<String, Map<String, Queue<Object>>> busMap = new HashMap<String, Map<String, Queue<Object>>>();
36         
37         public PolicyEngine() {}
38         
39         public boolean deliver(String busType, String topic, Object obj) {
40                 if (obj instanceof VirtualControlLoopNotification) {
41                         VirtualControlLoopNotification notification = (VirtualControlLoopNotification) obj;
42                         System.out.println("Notification to be sent:");
43                         System.out.println(Serialization.gsonPretty.toJson(notification));
44                 }
45                 if (obj instanceof Request) {
46                         Request request = (Request) obj;
47                         System.out.println("APPC request to be sent:");
48                         System.out.println("Request: " + request.Action + " RequestID: " + request.CommonHeader.RequestID + " Payload: " + request.Payload);
49                 }
50                 //
51                 // Does the bus exist?
52                 //
53                 if (busMap.containsKey(busType) == false) {
54                         System.out.println("creating new bus type " + busType);
55                         //
56                         // Create the bus
57                         //
58                         busMap.put(busType, new HashMap<String, Queue<Object>>());
59                 }
60                 //
61                 // Get the bus
62                 //
63                 Map<String, Queue<Object>> topicMap = busMap.get(busType);
64                 //
65                 // Does the topic exist?
66                 //
67                 if (topicMap.containsKey(topic) == false) {
68                         System.out.println("creating new topic " + topic);
69                         //
70                         // Create the topic
71                         //
72                         topicMap.put(topic, new LinkedList<Object>());
73                 }
74                 //
75                 // Get the topic queue
76                 //
77                 System.out.println("queueing");
78                 return topicMap.get(topic).add(obj);
79         
80         }
81  }