5921c89605635005cdde5153e094e728fb7f5c62
[policy/apex-pdp.git] /
1 /*-
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
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.client.editor.rest.handling;
22
23 import org.onap.policy.apex.model.modelapi.ApexApiResult;
24 import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
25
26 /**
27  * This interface defines the methods that a REST handler must implement to handle REST editor commands.
28  *
29  */
30 public interface RestCommandHandler {
31
32     /**
33      * Process a REST command.
34      *
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
39      */
40     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
41                     final RestCommand command);
42
43     /**
44      * Process a REST command.
45      *
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
51      */
52     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
53                     final RestCommand command, final String jsonString);
54
55     /**
56      * Process a REST command.
57      *
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
64      */
65     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
66                     final RestCommand command, final String name, final String version);
67
68     /**
69      * Get an unsupported command result message.
70      *
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      */
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");
79     }
80     
81     /**
82      * Convert blank incoming fields to nulls.
83      * 
84      * @param incomingField the field to check
85      * @return null if the field is blank, otherwise, the field trimmed
86      */
87     public default String blank2Null(final String incomingField) {
88         if (incomingField == null) {
89             return null;
90         }
91         
92         String trimmedField = incomingField.trim();
93         
94         if (trimmedField.isEmpty()) {
95             return null;
96         }
97         else {
98             return trimmedField;
99         }
100     }
101 }