Changes for checkstyle 8.32
[policy/apex-pdp.git] / core / core-engine / src / main / java / org / onap / policy / apex / core / engine / executor / context / AxStateFacade.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.core.engine.executor.context;
22
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Set;
27 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
28 import org.onap.policy.apex.model.basicmodel.service.ModelService;
29 import org.onap.policy.apex.model.policymodel.concepts.AxState;
30 import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
31
32 /**
33  * The Class AxStateFacade acts as a facade into the AxState class so that task logic can easily
34  * access information in an AxState instance.
35  *
36  * @author Sven van der Meer (sven.van.der.meer@ericsson.com)
37  */
38 public class AxStateFacade {
39     // CHECKSTYLE:OFF: checkstyle:visibilityModifier Logic has access to this field
40
41     /** The full definition information for the state. */
42     public final AxState state;
43
44     // CHECKSTYLE:ON: checkstyle:visibilityModifier
45
46     /**
47      * Instantiates a new AxState facade.
48      *
49      * @param state the state for which a facade is being presented
50      */
51     public AxStateFacade(final AxState state) {
52         this.state = state;
53     }
54
55     /**
56      * Gets the default task key of the state.
57      *
58      * @return the default task key
59      */
60     public AxArtifactKey getDefaultTaskKey() {
61         return state.getDefaultTask();
62     }
63
64     /**
65      * Gets the ID of the state.
66      *
67      * @return the ID
68      */
69     public String getId() {
70         return state.getKey().getId();
71     }
72
73     /**
74      * Gets the name of the state.
75      *
76      * @return the state name
77      */
78     public String getStateName() {
79         return state.getKey().getLocalName();
80     }
81
82     /**
83      * Check if a task is defined for a given task name on a state and, if so, return its key.
84      *
85      * @param taskName the name of the task to get
86      * @return the task key or null if it does not exist
87      */
88     public AxArtifactKey getTaskKey(final String taskName) {
89         if (taskName == null) {
90             return null;
91         }
92
93         return ModelService.getModel(AxTasks.class).get(taskName).getKey();
94     }
95
96     /**
97      * Check if a task is defined for a given task name on a state and, if so, return its key.
98      *
99      * @return unmodifiable list of names of tasks available
100      */
101     public List<String> getTaskNames() {
102         final Set<AxArtifactKey> tasks = state.getTaskReferences().keySet();
103         final List<String> ret = new ArrayList<>(tasks.size());
104         for (final AxArtifactKey task : tasks) {
105             ret.add(task.getName());
106         }
107         return Collections.unmodifiableList(ret);
108     }
109 }