2 * ============LICENSE_START=======================================================
3 * Copyright (C) 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.client.editor.rest.handling;
23 import org.onap.policy.apex.model.modelapi.ApexApiResult;
24 import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
27 * This interface defines the methods that a REST handler must implement to handle REST editor commands.
30 public interface RestCommandHandler {
33 * Process a REST command.
35 * @param session the Apex editor session
36 * @param commandType the type of REST command to execute
37 * @param command the REST command to execute
38 * @return the apex api result the result of the execution
40 public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
41 final RestCommand command);
44 * Process a REST command.
46 * @param session the Apex editor session
47 * @param commandType the type of REST command to execute
48 * @param command the REST command to execute
49 * @param jsonString the json string to use to execute the command
50 * @return the apex api result the result of the execution
52 public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
53 final RestCommand command, final String jsonString);
56 * Process a REST command.
58 * @param session the Apex editor session
59 * @param commandType the type of REST command to execute
60 * @param command the REST command to execute
61 * @param name the concept name on which to execute
62 * @param version the concept version the version on which to execute
63 * @return the apex api result the result of the execution
65 public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
66 final RestCommand command, final String name, final String version);
69 * Get an unsupported command result message.
71 * @param session the Apex editor session
72 * @param commandType the type of REST command to execute
73 * @param command the REST command to execute
74 * @return the apex api result the result of the execution
76 public default ApexApiResult getUnsupportedCommandResultMessage(final RestSession session,
77 final RestCommandType commandType, final RestCommand command) {
78 return new ApexApiResult(Result.FAILED, "session " + session.getSessionId() + ", command type " + commandType
79 + ", command" + command + " invalid");
83 * Convert blank incoming fields to nulls.
85 * @param incomingField the field to check
86 * @return null if the field is blank, otherwise, the field trimmed
88 public default String blank2Null(final String incomingField) {
89 if (incomingField == null) {
93 final String trimmedField = incomingField.trim();
95 if (trimmedField.isEmpty()) {