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;
28 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
29 import org.onap.policy.apex.model.basicmodel.service.ModelService;
30 import org.onap.policy.apex.model.policymodel.concepts.AxState;
31 import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
34 * The Class AxStateFacade acts as a facade into the AxState class so that task logic can easily
35 * access information in an AxState instance.
37 * @author Sven van der Meer (sven.van.der.meer@ericsson.com)
39 public class AxStateFacade {
40 // CHECKSTYLE:OFF: checkstyle:visibilityModifier Logic has access to this field
42 /** The full definition information for the state. */
43 public final AxState state;
45 // CHECKSTYLE:ON: checkstyle:visibilityModifier
48 * Instantiates a new AxState facade.
50 * @param state the state for which a facade is being presented
52 public AxStateFacade(final AxState state) {
57 * Gets the default task key of the state.
59 * @return the default task key
61 public AxArtifactKey getDefaultTaskKey() {
62 return state.getDefaultTask();
66 * Gets the ID of the state.
70 public String getId() {
71 return state.getKey().getId();
75 * Gets the name of the state.
77 * @return the state name
79 public String getStateName() {
80 return state.getKey().getLocalName();
84 * Check if a task is defined for a given task name on a state and, if so, return its key.
86 * @param taskName the name of the task to get
87 * @return the task key or null if it does not exist
89 public AxArtifactKey getTaskKey(final String taskName) {
90 if (taskName == null) {
94 return ModelService.getModel(AxTasks.class).get(taskName).getKey();
98 * Check if a task is defined for a given task name on a state and, if so, return its key.
100 * @return unmodifiable list of names of tasks available
102 public List<String> getTaskNames() {
103 final Set<AxArtifactKey> tasks = state.getTaskReferences().keySet();
104 final List<String> ret = new ArrayList<>(tasks.size());
105 for (final AxArtifactKey task : tasks) {
106 ret.add(task.getName());
108 return Collections.unmodifiableList(ret);