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
75 public default ApexApiResult getUnsupportedCommandResultMessage(final RestSession session,
76 final RestCommandType commandType, final RestCommand command) {
77 return new ApexApiResult(Result.FAILED, "session " + session.getSessionId() + ", command type " + commandType
78 + ", command" + command + " invalid");
82 * Convert blank incoming fields to nulls.
84 * @param incomingField the field to check
85 * @return null if the field is blank, otherwise, the field trimmed
87 public default String blank2Null(final String incomingField) {
88 if (incomingField == null) {
92 String trimmedField = incomingField.trim();
94 if (trimmedField.isEmpty()) {