YANG Model update for A1 Adapter
[ccsdk/features.git] / sdnr / wt / odlux / apps / configurationApp / src / services / configurationService.ts
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. 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 distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 import { requestRest } from '../../../../framework/src/services/restService';
20
21 import { CoreModelNetworkElement, NameValue } from '../models/coreModel';
22 import { ViewSpecification } from '../models/uiModels';
23
24 export const getValueByName = (name: string, nameValuePairs: NameValue[], defaultValue: string | null = null): string | null => {
25   const entry = nameValuePairs.find(p => p["value-name"] === name);
26   return entry && entry.value || defaultValue;
27 };
28
29 class ConfigurationService {
30
31   /** Gets the core model for a network element by its mountId. */
32   public async getCoreModelByNodeId(nodeId: string): Promise<CoreModelNetworkElement | null> {
33     const path = `restconf/config/network-topology:network-topology/topology/topology-netconf/node/${nodeId}/yang-ext:mount/core-model:network-element`;
34     const ne = await requestRest<{ "network-element": CoreModelNetworkElement }>(path, { method: "GET" });
35     return ne && ne["network-element"] || null;
36   }
37
38   public async getViewData(path: string): Promise<{} | null> {
39     const viewData = await requestRest<{}>(path, { method: "GET" });
40     return viewData || null;
41   }
42
43   /** Gets the UI description object for a capability of a network element. */
44   public async getUIDescriptionByCapability(capability: string, revision: string | null): Promise<ViewSpecification[] | null> {
45     const capFile = capability && revision && `${capability}@${revision}.json`;
46     const coreModelResponse = capFile && await requestRest<{ views: ViewSpecification[] }>(`assets/${capFile}`, { method: "GET" }, false, true);
47     return coreModelResponse && coreModelResponse.views || null;
48   }
49
50 }
51
52 export const configurationService = new ConfigurationService();
53 export default configurationService;