3730bba47fa4a9b37dfc38621452f0f65c3f73d3
[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  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.testsuites.integration.common.model.java;
23
24 import java.util.Random;
25
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      * Gets the event.
36      *
37      * @param executor the executor
38      * @return the event
39      */
40     public boolean getEvent(final TaskExecutionContext executor) {
41         String idString = executor.subject.getId();
42         executor.logger.debug(idString);
43
44         String albumNameString = executor.getContextAlbum("GlobalContextAlbum").getName();
45         executor.logger.debug(albumNameString);
46
47         String inFieldsString = executor.inFields.toString();
48         executor.logger.debug(inFieldsString);
49         final Random rand = new Random();
50         if (executor.inFields.containsKey("TestDecideCaseSelected")) {
51             executor.outFields.put("TestActCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
52             executor.outFields.put("TestActStateTime", System.nanoTime());
53         } else if (executor.inFields.containsKey("TestEstablishCaseSelected")) {
54             executor.outFields.put("TestDecideCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
55             executor.outFields.put("TestDecideStateTime", System.nanoTime());
56         } else if (executor.inFields.containsKey("TestMatchCaseSelected")) {
57             executor.outFields.put("TestEstablishCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
58             executor.outFields.put("TestEstablishStateTime", System.nanoTime());
59         } else {
60             executor.outFields.put("TestMatchCaseSelected", (byte) rand.nextInt(BOUND_FOR_RANDOM_INT));
61             executor.outFields.put("TestMatchStateTime", System.nanoTime());
62         }
63         return true;
64     }
65 }