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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.core.engine.executor.context;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
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;
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.
36 * @author Sven van der Meer (sven.van.der.meer@ericsson.com)
38 public class AxStateFacade {
39 // CHECKSTYLE:OFF: checkstyle:visibilityModifier Logic has access to this field
41 /** The full definition information for the state. */
42 public final AxState state;
44 // CHECKSTYLE:ON: checkstyle:visibilityModifier
47 * Instantiates a new AxState facade.
49 * @param state the state for which a facade is being presented
51 public AxStateFacade(final AxState state) {
56 * Gets the default task key of the state.
58 * @return the default task key
60 public AxArtifactKey getDefaultTaskKey() {
61 return state.getDefaultTask();
65 * Gets the ID of the state.
69 public String getId() {
70 return state.getKey().getId();
74 * Gets the name of the state.
76 * @return the state name
78 public String getStateName() {
79 return state.getKey().getLocalName();
83 * Check if a task is defined for a given task name on a state and, if so, return its key.
85 * @param taskName the name of the task to get
86 * @return the task key or null if it does not exist
88 public AxArtifactKey getTaskKey(final String taskName) {
89 if (taskName == null) {
93 return ModelService.getModel(AxTasks.class).get(taskName).getKey();
97 * Check if a task is defined for a given task name on a state and, if so, return its key.
99 * @return unmodifiable list of names of tasks available
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());
107 return Collections.unmodifiableList(ret);