c4fd6d6f4f59c32d33dd4b8f5137d65268fa8d9a
[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 // TODO: Auto-generated Javadoc
27 /**
28  * This interface defines the methods that a REST handler must implement to handle REST editor commands.
29  *
30  */
31 public interface RestCommandHandler {
32
33     /**
34      * Process a REST command.
35      *
36      * @param session the Apex editor session
37      * @param commandType the type of REST command to execute
38      * @param command the REST command to execute
39      * @return the apex api result the result of the execution
40      */
41     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
42                     final RestCommand command);
43
44     /**
45      * Process a REST command.
46      *
47      * @param session the Apex editor session
48      * @param commandType the type of REST command to execute
49      * @param command the REST command to execute
50      * @param jsonString the json string to use to execute the command
51      * @return the apex api result the result of the execution
52      */
53     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
54                     final RestCommand command, final String jsonString);
55
56     /**
57      * Process a REST command.
58      *
59      * @param session the Apex editor session
60      * @param commandType the type of REST command to execute
61      * @param command the REST command to execute
62      * @param name the concept name on which to execute
63      * @param version the concept version the version on which to execute
64      * @return the apex api result the result of the execution
65      */
66     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
67                     final RestCommand command, final String name, final String version);
68
69     /**
70      * Get an unsupported command result message.
71      *
72      * @param session the Apex editor session
73      * @param commandType the type of REST command to execute
74      * @param command the REST command to execute
75      */
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");
80     }
81     
82     /**
83      * Convert blank incoming fields to nulls.
84      * 
85      * @param incomingField the field to check
86      * @return null if the field is blank, otherwise, the field trimmed
87      */
88     public default String blank2Null(final String incomingField) {
89         if (incomingField == null) {
90             return null;
91         }
92         
93         String trimmedField = incomingField.trim();
94         
95         if (trimmedField.isEmpty()) {
96             return null;
97         }
98         else {
99             return trimmedField;
100         }
101     }
102 }