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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
19 import { requestRest } from '../../../../framework/src/services/restService';
21 import { CoreModelNetworkElement, NameValue } from '../models/coreModel';
22 import { ViewSpecification } from '../models/uiModels';
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;
29 class ConfigurationService {
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;
38 public async getViewData(path: string): Promise<{} | null> {
39 const viewData = await requestRest<{}>(path, { method: "GET" });
40 return viewData || null;
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;
52 export const configurationService = new ConfigurationService();
53 export default configurationService;