eec8e6ccd1101c4e4f03179198767fc4e4017a1a
[policy/gui.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.gui.editors.apex.rest.handling;
23
24 import org.onap.policy.apex.model.modelapi.ApexApiResult;
25
26 /**
27  * This class handles commands on key information in Apex models.
28  */
29 public class KeyInfoHandler implements RestCommandHandler {
30     /**
31      * {@inheritDoc}.
32      */
33     @Override
34     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
35         final RestCommand command) {
36         return getUnsupportedCommandResultMessage(session, commandType, command);
37     }
38
39     /**
40      * {@inheritDoc}.
41      */
42     @Override
43     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
44         final RestCommand command, final String jsonString) {
45         return getUnsupportedCommandResultMessage(session, commandType, command);
46     }
47
48     /**
49      * {@inheritDoc}.
50      */
51     @Override
52     public ApexApiResult executeRestCommand(final RestSession session, final RestCommandType commandType,
53         final RestCommand command, final String name, final String version) {
54
55         if (RestCommandType.KEY_INFO.equals(commandType) && RestCommand.LIST.equals(command)) {
56             return listKeyInformation(session, name, version);
57         } else {
58             return getUnsupportedCommandResultMessage(session, commandType, command);
59         }
60     }
61
62     /**
63      * Get the key information for a concept with the given name and version.
64      *
65      * @param session the editor session containing the Apex model
66      * @param name    the name for the search
67      * @param version the version for the search
68      * @return the key information
69      */
70     private ApexApiResult listKeyInformation(final RestSession session, final String name, final String version) {
71         return session.getApexModel().listKeyInformation(blank2Null(name), blank2Null(version));
72     }
73 }