dbd3d918f34486b39ff7f30971e3e7ac8743a253
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.testsuites.integration.common.model.java;
24
25 import java.util.Random;
26 import org.onap.policy.apex.core.engine.executor.context.TaskExecutionContext;
27
28 /**
29  * The Class DefaultTask_Logic is default task logic in Java.
30  */
31 public class DefaultTaskLogic {
32     private static final int BOUND_FOR_RANDOM_INT = 4;
33
34     /*
35      * This is not used for encryption/security, thus disabling sonar.
36      */
37     private static final Random rand = new Random();    // NOSONAR
38
39     /**
40      * Gets the event.
41      *
42      * @param executor the executor
43      * @return the event
44      */
45     public boolean getEvent(final TaskExecutionContext executor) {
46         String idString = executor.subject.getId();
47         executor.logger.debug(idString);
48
49         String albumNameString = executor.getContextAlbum("GlobalContextAlbum").getName();
50         executor.logger.debug(albumNameString);
51
52         String inFieldsString = executor.inFields.toString();
53         executor.logger.debug(inFieldsString);
54         if (executor.inFields.containsKey("TestDecideCaseSelected")) {
55             executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
56             executor.outFields.put("TestActStateTime", System.nanoTime());
57         } else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
58             executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
59             executor.outFields.put("TestDecideStateTime", System.nanoTime());
60         } else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
61             executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
62             executor.outFields.put("TestEstablishStateTime", System.nanoTime());
63         } else {
64             executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
65             executor.outFields.put("TestMatchStateTime", System.nanoTime());
66         }
67         return true;
68     }
69 }