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, SetMediatorServerReachable } 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[];
36 const mediatorServerInit: MediatorServerState = {
42 mediatorVersion: null,
49 export const mediatorServerHandler: IActionHandler<MediatorServerState> = (state = mediatorServerInit, action) => {
50 if (action instanceof SetMediatorServerBusy) {
55 } else if (action instanceof SetMediatorServerInfo) {
62 } else if (action instanceof SetMediatorServerVersion) {
65 serverVersion: action.versionInfo && action.versionInfo.server,
66 mediatorVersion: action.versionInfo && action.versionInfo.mediator,
67 nexmls: action.versionInfo && [...action.versionInfo.nexmls] || [],
69 } else if (action instanceof SetAllMediatorServerConfigurations) {
72 configurations: action.allConfigurations && action.allConfigurations.map(config => ({ ...config, busy: false })) || [],
74 } else if (action instanceof SetMediatorServerSupportedDevices) {
77 supportedDevices: action.devices || [],
79 } else if (action instanceof SetMediatorBusyByName) {
80 const index = state.configurations.findIndex(config => config.Name === action.name);
81 if (index > -1) state = {
84 ...state.configurations.slice(0, index),
85 { ...state.configurations[index], [BusySymbol]: action.isBusy },
86 ...state.configurations.slice(index + 1)
89 } else if (action instanceof AddMediatorConfig) {
93 ...state.configurations,
97 } else if (action instanceof UpdateMediatorConfig) {
98 const index = state.configurations.findIndex(config => config.Name === action.name);
99 if (index > -1) state = {
102 ...state.configurations.slice(0, index),
103 { ...action.mediatorConfig, [BusySymbol]: state.configurations[index][BusySymbol] },
104 ...state.configurations.slice(index + 1)
107 } else if (action instanceof RemoveMediatorConfig) {
108 const index = state.configurations.findIndex(config => config.Name === action.name);
109 if (index > -1) state = {
112 ...state.configurations.slice(0, index),
113 ...state.configurations.slice(index + 1)
116 } else if( action instanceof SetMediatorServerReachable){
117 state = {...state, isReachable: action.isReachable}