Merge "remove nexus function from entrypoint"
[policy/drools-applications.git] / controlloop / m2 / base / src / main / java / org / onap / policy / m2 / base / Util.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * m2/base
4  * ================================================================================
5  * Copyright (C) 2020 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.policy.m2.base;
22
23 import org.onap.policy.drools.core.PolicyContainer;
24 import org.onap.policy.drools.core.PolicySession;
25 import org.onap.policy.drools.system.PolicyController;
26 import org.onap.policy.drools.system.PolicyControllerConstants;
27 import org.onap.policy.drools.system.PolicyEngineConstants;
28
29 /**
30  * This class contains static utility methods.
31  */
32 public class Util {
33     // Add a private Util to hide the implicit public one.
34     private Util() {
35         //not called
36     }
37
38     /**
39      * Find the PolicyController associated with the specified PolicySession.
40      *
41      * @param session the current PolicySession
42      * @return the associated PolicyController (or 'null' if not found)
43      */
44     public static PolicyController getPolicyController(PolicySession session) {
45         PolicyContainer container = session.getPolicyContainer();
46         return PolicyControllerConstants.getFactory().get(
47                    container.getGroupId(), container.getArtifactId());
48     }
49
50     /**
51      * Send a UEB/DMAAP message to the specified topic, using the specified
52      * PolicyController.
53      *
54      * @param topic UEB/DMAAP topic
55      * @param event the message to encode, and send
56      * @return 'true' if successful, 'false' if delivery failed
57      * @throws IllegalStateException if the topic can't be found,
58      *     or there are multiple topics with the same name
59      */
60     public static boolean deliver(String topic, Object event) {
61         return PolicyEngineConstants.getManager().deliver(topic, event);
62     }
63 }