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 { Action } from '../../../../framework/src/flux/action';
19 import { Dispatch } from '../../../../framework/src/flux/store';
21 import { MediatorServerVersionInfo, MediatorConfig, MediatorConfigResponse, MediatorServerDevice } from '../models/mediatorServer';
22 import mediatorService from '../services/mediatorService';
23 import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions';
24 import { NavigateToApplication } from '../../../../framework/src/actions/navigationActions';
25 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
27 /** Represents the base action. */
28 export class BaseAction extends Action { }
30 export class SetMediatorServerBusy extends BaseAction {
31 constructor(public isBusy: boolean) {
36 export class SetMediatorServerInfo extends BaseAction {
38 * Initializes a new instance of this class.
40 constructor(public id: string | null, public name: string | null, public url: string | null) {
46 export class SetMediatorServerVersion extends BaseAction {
48 * Initializes a new instance of this class.
50 constructor(public versionInfo: MediatorServerVersionInfo | null) {
56 export class SetAllMediatorServerConfigurations extends BaseAction {
58 * Initializes a new instance of this class.
60 constructor(public allConfigurations: MediatorConfigResponse[] | null) {
66 export class SetMediatorServerSupportedDevices extends BaseAction {
68 * Initializes a new instance of this class.
70 constructor(public devices: MediatorServerDevice[] | null) {
76 export class SetMediatorServerReachable extends BaseAction {
77 constructor(public isReachable: boolean) {
82 export const initializeMediatorServerAsyncActionCreator = (serverId: string) => (dispatch: Dispatch) => {
83 dispatch(new SetMediatorServerBusy(true));
84 mediatorService.getMediatorServerById(serverId).then(mediatorServer => {
85 if (!mediatorServer) {
86 dispatch(new SetMediatorServerBusy(false));
87 dispatch(new AddSnackbarNotification({ message: `Error loading mediator server [${serverId}]`, options: { variant: 'error' } }));
88 dispatch(new NavigateToApplication("mediator"));
92 dispatch(new SetMediatorServerInfo(mediatorServer.id, mediatorServer.name, mediatorServer.url));
95 mediatorService.getMediatorServerAllConfigs(mediatorServer.id),
96 mediatorService.getMediatorServerSupportedDevices(mediatorServer.id),
97 mediatorService.getMediatorServerVersion(mediatorServer.id)
98 ]).then(([configurations, supportedDevices, versionInfo]) => {
99 if (configurations === null && supportedDevices === null && versionInfo === null) {
100 dispatch(new SetMediatorServerReachable(false));
102 dispatch(new SetMediatorServerReachable(true));
104 dispatch(new SetAllMediatorServerConfigurations(configurations));
105 dispatch(new SetMediatorServerSupportedDevices(supportedDevices));
106 dispatch(new SetMediatorServerVersion(versionInfo));
107 dispatch(new SetMediatorServerBusy(false));
109 dispatch(new SetMediatorServerReachable(false));
110 dispatch(new SetMediatorServerBusy(false));