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 { XmlFileInfo, MediatorConfig, BusySymbol, MediatorConfigResponse, MediatorServerDevice } from "../models/mediatorServer";
19 import { IActionHandler } from "../../../../framework/src/flux/action";
20 import { SetMediatorServerVersion, SetMediatorServerInfo, SetAllMediatorServerConfigurations, SetMediatorServerBusy, SetMediatorServerSupportedDevices } from "../actions/mediatorServerActions";
21 import { SetMediatorBusyByName, UpdateMediatorConfig, AddMediatorConfig, RemoveMediatorConfig } from "../actions/mediatorConfigActions";
23 export type MediatorServerState = {
28 serverVersion: string | null;
29 mediatorVersion: string | null;
30 nexmls: XmlFileInfo[];
31 configurations: MediatorConfigResponse[];
32 supportedDevices: MediatorServerDevice[];
35 const mediatorServerInit: MediatorServerState = {
41 mediatorVersion: null,
47 export const mediatorServerHandler: IActionHandler<MediatorServerState> = (state = mediatorServerInit, action) => {
48 if (action instanceof SetMediatorServerBusy) {
53 } else if (action instanceof SetMediatorServerInfo) {
60 } else if (action instanceof SetMediatorServerVersion) {
63 serverVersion: action.versionInfo && action.versionInfo.server,
64 mediatorVersion: action.versionInfo && action.versionInfo.mediator,
65 nexmls: action.versionInfo && [...action.versionInfo.nexmls] || [],
67 } else if (action instanceof SetAllMediatorServerConfigurations) {
70 configurations: action.allConfigurations && action.allConfigurations.map(config => ({ ...config, busy: false })) || [],
72 } else if (action instanceof SetMediatorServerSupportedDevices) {
75 supportedDevices: action.devices || [],
77 } else if (action instanceof SetMediatorBusyByName) {
78 const index = state.configurations.findIndex(config => config.Name === action.name);
79 if (index > -1) state = {
82 ...state.configurations.slice(0, index),
83 { ...state.configurations[index], [BusySymbol]: action.isBusy },
84 ...state.configurations.slice(index + 1)
87 } else if (action instanceof AddMediatorConfig) {
91 ...state.configurations,
95 } else if (action instanceof UpdateMediatorConfig) {
96 const index = state.configurations.findIndex(config => config.Name === action.name);
97 if (index > -1) state = {
100 ...state.configurations.slice(0, index),
101 { ...action.mediatorConfig, [BusySymbol]: state.configurations[index][BusySymbol] },
102 ...state.configurations.slice(index + 1)
105 } else if (action instanceof RemoveMediatorConfig) {
106 const index = state.configurations.findIndex(config => config.Name === action.name);
107 if (index > -1) state = {
110 ...state.configurations.slice(0, index),
111 ...state.configurations.slice(index + 1)