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==========================================================================
18 import { requestRest } from '../../../../framework/src/services/restService';
19 import { Result, HitEntry, PostResponse, DeleteResponse } from '../../../../framework/src/models/elasticSearch';
21 import { MaintenenceEntry } from '../models/maintenenceEntryType';
22 import { convertToLocaleString, convertToGMTString, convertToISODateString } from '../utils/timeUtils';
23 import { convertPropertyNames, replaceUpperCase } from '../../../../framework/src/utilities/yangHelper';
26 export const maintenenceEntryDatabasePath = "mwtn/maintenancemode";
29 * Represents a web api accessor service for all maintenence entries related actions.
31 class MaintenenceService {
34 * Adds or updates one maintenence entry to the backend.
36 public async writeMaintenenceEntry(maintenenceEntry: MaintenenceEntry): Promise<PostResponse | null> {
37 const path = `/restconf/operations/data-provider:create-maintenance`;
40 "id": maintenenceEntry._id,
41 "node-id": maintenenceEntry.nodeId,
42 "active": maintenenceEntry.active,
43 "description": maintenenceEntry.description,
44 "end": convertToISODateString(maintenenceEntry.end),
45 "start": convertToISODateString(maintenenceEntry.start)
48 const result = await requestRest<PostResponse>(path, { method: "POST", body: JSON.stringify(convertPropertyNames({ input: query }, replaceUpperCase)) });
49 return result || null;
53 * Deletes one maintenence entry by its mountId from the backend.
55 public async deleteMaintenenceEntry(maintenenceEntry: MaintenenceEntry): Promise<(DeleteResponse) | null> {
56 const path = `/restconf/operations/data-provider:delete-maintenance`;
59 "id": maintenenceEntry._id,
60 "node-id": maintenenceEntry.nodeId,
61 "active": maintenenceEntry.active,
62 "description": maintenenceEntry.description,
63 "end": convertToISODateString(maintenenceEntry.end),
64 "start": convertToISODateString(maintenenceEntry.start)
66 const result = await requestRest<DeleteResponse>(path, { method: "POST", body: JSON.stringify(convertPropertyNames({ input: query }, replaceUpperCase)) });
67 return result || null;
71 export const maintenenceService = new MaintenenceService();
72 export default maintenenceService;