From da4fd6169717cfa04d644d0af0d23dd089a6e373 Mon Sep 17 00:00:00 2001 From: herbert Date: Sat, 14 Dec 2019 00:06:42 +0100 Subject: remove old version of devicemodel devicemanager oldux featureaggregator Issue-ID: SDNC-1004 Signed-off-by: herbert Change-Id: I5337643181e2398e5a8097e4ee14fa4ac96d0d4c --- .../odlux/framework/src/services/applicationApi.ts | 61 -------- .../framework/src/services/applicationManager.ts | 53 ------- .../src/services/authenticationService.ts | 53 ------- sdnr/wt/odlux/framework/src/services/index.ts | 21 --- .../framework/src/services/notificationService.ts | 154 --------------------- .../framework/src/services/restAccessorService.ts | 93 ------------- .../wt/odlux/framework/src/services/restService.ts | 67 --------- .../framework/src/services/snackbarService.ts | 22 --- 8 files changed, 524 deletions(-) delete mode 100644 sdnr/wt/odlux/framework/src/services/applicationApi.ts delete mode 100644 sdnr/wt/odlux/framework/src/services/applicationManager.ts delete mode 100644 sdnr/wt/odlux/framework/src/services/authenticationService.ts delete mode 100644 sdnr/wt/odlux/framework/src/services/index.ts delete mode 100644 sdnr/wt/odlux/framework/src/services/notificationService.ts delete mode 100644 sdnr/wt/odlux/framework/src/services/restAccessorService.ts delete mode 100644 sdnr/wt/odlux/framework/src/services/restService.ts delete mode 100644 sdnr/wt/odlux/framework/src/services/snackbarService.ts (limited to 'sdnr/wt/odlux/framework/src/services') diff --git a/sdnr/wt/odlux/framework/src/services/applicationApi.ts b/sdnr/wt/odlux/framework/src/services/applicationApi.ts deleted file mode 100644 index 77287f497..000000000 --- a/sdnr/wt/odlux/framework/src/services/applicationApi.ts +++ /dev/null @@ -1,61 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -import { Event } from '../common/event'; -import { ApplicationStore } from '../store/applicationStore'; - -let resolveApplicationStoreInitialized: (store: ApplicationStore) => void; -let applicationStore: ApplicationStore | null = null; -const applicationStoreInitialized: Promise = new Promise((resolve) => resolveApplicationStoreInitialized = resolve); - -const loginEvent = new Event(); -const logoutEvent = new Event(); - -export const onLogin = () => { - loginEvent.invoke(); -} - -export const onLogout = () => { - logoutEvent.invoke(); -} - -export const setApplicationStore = (store: ApplicationStore) => { - if (!applicationStore && store) { - applicationStore = store; - resolveApplicationStoreInitialized(store); - } -} - -export const applicationApi = { - get applicationStore(): ApplicationStore | null { - return applicationStore; - }, - - get applicationStoreInitialized(): Promise { - return applicationStoreInitialized; - }, - - get loginEvent() { - return loginEvent; - }, - - get logoutEvent() { - return logoutEvent; - } -}; - -export default applicationApi; \ No newline at end of file diff --git a/sdnr/wt/odlux/framework/src/services/applicationManager.ts b/sdnr/wt/odlux/framework/src/services/applicationManager.ts deleted file mode 100644 index 14e3ed0b2..000000000 --- a/sdnr/wt/odlux/framework/src/services/applicationManager.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -import { ApplicationInfo } from '../models/applicationInfo'; -import { Event } from '../common/event'; - -import { applicationApi } from './applicationApi'; - -/** Represents registry to manage all applications. */ -class ApplicationManager { - - /** Stores all registerd applications. */ - private _applications: { [key: string]: ApplicationInfo }; - - /** Initializes a new instance of this class. */ - constructor() { - this._applications = {}; - this.changed = new Event(); - } - - /** The chaged event will fire if the registration has changed. */ - public changed: Event; - - /** Registers a new application. */ - public registerApplication(applicationInfo: ApplicationInfo) { - this._applications[applicationInfo.name] = applicationInfo; - this.changed.invoke(); - return applicationApi; - } - - /** Gets all registered applications. */ - public get applications() { - return this._applications; - } -} - -/** A singleton instance of the application manager. */ -export const applicationManager = new ApplicationManager(); -export default applicationManager; \ No newline at end of file diff --git a/sdnr/wt/odlux/framework/src/services/authenticationService.ts b/sdnr/wt/odlux/framework/src/services/authenticationService.ts deleted file mode 100644 index d3d62c566..000000000 --- a/sdnr/wt/odlux/framework/src/services/authenticationService.ts +++ /dev/null @@ -1,53 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -import { requestRest, formEncode } from "./restService"; -import { AuthToken } from "../models/authentication"; - -type AuthTokenResponse = { - access_token: string; - token_type: string; - expires_in: number; -} - - -class AuthenticationService { - public async authenticateUser(email: string, password: string, scope: string): Promise { - const result = await requestRest(`oauth2/token`, { - method: "POST", - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - body: formEncode({ - grant_type: "password", - username: email, - password: password, - scope: scope - }) - }, false); - const resultObj: AuthTokenResponse| null = result && JSON.parse(result); - return resultObj && { - username: email, - access_token: resultObj.access_token, - token_type: resultObj.token_type, - expires: (new Date().valueOf()) + (resultObj.expires_in * 1000) - } || null; - } -} - -export const authenticationService = new AuthenticationService(); -export default authenticationService; \ No newline at end of file diff --git a/sdnr/wt/odlux/framework/src/services/index.ts b/sdnr/wt/odlux/framework/src/services/index.ts deleted file mode 100644 index c6071e7b8..000000000 --- a/sdnr/wt/odlux/framework/src/services/index.ts +++ /dev/null @@ -1,21 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -export { applicationManager } from './applicationManager'; -export { subscribe, unsubscribe } from './notificationService'; -export { requestRest } from './restService'; - diff --git a/sdnr/wt/odlux/framework/src/services/notificationService.ts b/sdnr/wt/odlux/framework/src/services/notificationService.ts deleted file mode 100644 index b12c19985..000000000 --- a/sdnr/wt/odlux/framework/src/services/notificationService.ts +++ /dev/null @@ -1,154 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -import * as X2JS from 'x2js'; - -const socketUrl = [location.protocol === 'https:' ? 'wss://' : 'ws://', 'admin', ':', 'admin', '@', location.hostname, ':', location.port, '/websocket'].join(''); -const subscriptions: { [scope: string]: SubscriptionCallback[] } = { }; - -export interface IFormatedMessage { - notifType: string | null; - time: string; -} - -export type SubscriptionCallback = (msg: TMessage) => void; - -function formatData(event: MessageEvent) : IFormatedMessage | undefined { - - var x2js = new X2JS(); - var jsonObj: { [key: string]: IFormatedMessage } = x2js.xml2js(event.data); - if (jsonObj && typeof (jsonObj) === 'object') { - - const notifType = Object.keys(jsonObj)[0]; - const formated = jsonObj[notifType]; - formated.notifType = notifType ; - formated.time = new Date().toISOString(); - return formated; - } - return undefined; - -} - -export function subscribe(scope: string | string[], callback: SubscriptionCallback): Promise { - return socketReady.then((notificationSocket) => { - const scopes = scope instanceof Array ? scope : [scope]; - - // send all new scopes to subscribe - const newScopesToSubscribe: string[] = scopes.reduce((acc: string[], cur: string) => { - const currentCallbacks = subscriptions[cur]; - if (currentCallbacks) { - if (!currentCallbacks.some(c => c === callback)) { - currentCallbacks.push(callback); - } - } else { - subscriptions[cur] = [callback]; - acc.push(cur); - } - return acc; - }, []); - - if (newScopesToSubscribe.length === 0) { - return true; - } - - // send a subscription to all active scopes - const scopesToSubscribe = Object.keys(subscriptions); - if (notificationSocket.readyState === notificationSocket.OPEN) { - const data = { - 'data': 'scopes', - 'scopes': scopesToSubscribe - }; - notificationSocket.send(JSON.stringify(data)); - return true; - } - return false; - }); -} - -export function unsubscribe(scope: string | string[], callback: SubscriptionCallback): Promise { - return socketReady.then((notificationSocket) => { - const scopes = scope instanceof Array ? scope : [scope]; - scopes.forEach(s => { - const callbacks = subscriptions[s]; - const index = callbacks && callbacks.indexOf(callback); - if (index > -1) { - callbacks.splice(index, 1); - } - if (callbacks.length === 0) { - subscriptions[s] === undefined; - } - }); - - // send a subscription to all active scopes - const scopesToSubscribe = Object.keys(subscriptions); - if (notificationSocket.readyState === notificationSocket.OPEN) { - const data = { - 'data': 'scopes', - 'scopes': scopesToSubscribe - }; - notificationSocket.send(JSON.stringify(data)); - return true; - } - return false; - }); -} - -const connect = (): Promise => { - return new Promise((resolve, reject) => { - const notificationSocket = new WebSocket(socketUrl); - - notificationSocket.onmessage = (event) => { - // process received event - if (typeof event.data === 'string') { - const formated = formatData(event); - if (formated && formated.notifType) { - const callbacks = subscriptions[formated.notifType]; - if (callbacks) { - callbacks.forEach(cb => { - // ensure all callbacks will be called - try { - return cb(formated); - } catch (reason) { - console.error(reason); - } - }); - } - } - } - }; - - notificationSocket.onerror = function (error) { - console.log("Socket error: " + error); - reject("Socket error: " + error); - }; - - notificationSocket.onopen = function (event) { - console.log("Socket connection opened."); - resolve(notificationSocket); - }; - - notificationSocket.onclose = function (event) { - socketReady = connect(); - }; - }); -} - -let socketReady = connect(); - - - - diff --git a/sdnr/wt/odlux/framework/src/services/restAccessorService.ts b/sdnr/wt/odlux/framework/src/services/restAccessorService.ts deleted file mode 100644 index ca95ebc1a..000000000 --- a/sdnr/wt/odlux/framework/src/services/restAccessorService.ts +++ /dev/null @@ -1,93 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -import * as $ from 'jquery'; -import { Action, IActionHandler } from '../flux/action'; -import { MiddlewareArg } from '../flux/middleware'; -import { Dispatch } from '../flux/store'; - -import { IApplicationStoreState } from '../store/applicationStore'; -import { AddErrorInfoAction, ErrorInfo } from '../actions/errorActions'; -import { PlainObject, AjaxParameter } from 'models/restService'; - -export const absoluteUri = /^(https?:\/\/|blob:)/i; -export const baseUrl = `${ window.location.origin }${ window.location.pathname }`; - -class RestBaseAction extends Action { } - -export const createRestApiAccessor = (urlOrPath: string, initialValue: TResult) => { - const isLocalRequest = !absoluteUri.test(urlOrPath); - const uri = isLocalRequest ? `${ baseUrl }/${ urlOrPath }`.replace(/\/{2,}/, '/') : urlOrPath ; - - class RestRequestAction extends RestBaseAction { constructor(public settings?: AjaxParameter) { super(); } } - - class RestResponseAction extends RestBaseAction { constructor(public result: TResult) { super(); } } - - class RestErrorAction extends RestBaseAction { constructor(public error?: Error | string) { super(); } } - - type RestAction = RestRequestAction | RestResponseAction | RestErrorAction; - - /** Represents our middleware to handle rest backend requests */ - const restMiddleware = (api: MiddlewareArg) => - (next: Dispatch) => (action: RestAction): RestAction => { - - // pass all actions through by default - next(action); - // handle the RestRequestAction - if (action instanceof RestRequestAction) { - const state = api.getState(); - const authHeader = isLocalRequest && state && state.framework.authenticationState.user && state.framework.authenticationState.user.token - ? { "Authentication": "Bearer " + state.framework.authenticationState.user.token } : { }; - $.ajax({ - url: uri, - method: (action.settings && action.settings.method) || "GET", - headers: { ...authHeader, ...action.settings && action.settings.headers ? action.settings.headers : { } }, - }).then((data: TResult) => { - next(new RestResponseAction(data)); - }).catch((err: any) => { - next(new RestErrorAction()); - next(new AddErrorInfoAction((err instanceof Error) ? { error: err } : { message: err.toString() })); - }); - } - // allways return action - return action; - }; - - /** Represents our action handler to handle our actions */ - const restActionHandler: IActionHandler = (state = initialValue, action) => { - if (action instanceof RestRequestAction) { - return { - ...(state as any), - busy: true - }; - } else if (action instanceof RestResponseAction) { - return action.result; - } else if (action instanceof RestErrorAction) { - return initialValue; - } - return state; - }; - - return { - requestAction: RestRequestAction, - actionHandler: restActionHandler, - middleware: restMiddleware, - }; -} - - - diff --git a/sdnr/wt/odlux/framework/src/services/restService.ts b/sdnr/wt/odlux/framework/src/services/restService.ts deleted file mode 100644 index c25deda84..000000000 --- a/sdnr/wt/odlux/framework/src/services/restService.ts +++ /dev/null @@ -1,67 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -import { ApplicationStore } from "../store/applicationStore"; -import { ReplaceAction } from "../actions/navigationActions"; - -const baseUri = `${ window.location.origin }`; -const absUrlPattern = /^https?:\/\//; -let applicationStore: ApplicationStore | null = null; - -export const startRestService = (store: ApplicationStore) => { - applicationStore = store; -}; - -export const formEncode = (params: { [key: string]: string | number }) => Object.keys(params).map((key) => { - return encodeURIComponent(key) + '=' + encodeURIComponent(params[key].toString()); -}).join('&'); - -export async function requestRest(path: string = '', init: RequestInit = {}, authenticate: boolean = true, isResource: boolean = false): Promise { - const isAbsUrl = absUrlPattern.test(path); - const uri = isAbsUrl ? path : isResource ? path.replace(/\/{2,}/i, '/') : (baseUri) + ('/' + path).replace(/\/{2,}/i, '/'); - init.headers = { - 'method': 'GET', - 'Content-Type': 'application/json', - 'Accept': 'application/json', - ...init.headers - }; - if (!isAbsUrl && authenticate && applicationStore) { - const { state: { framework: { authenticationState: { user } } } } = applicationStore; - // do not request if the user is not valid - if (!user || !user.isValid) { - return null; - } - (init.headers = { - ...init.headers, - 'Authorization': `${user.tokenType} ${user.token}` - //'Authorization': 'Basic YWRtaW46YWRtaW4=' - }); - } - const result = await fetch(uri, init); - if (result.status === 401 || result.status === 403) { - applicationStore && applicationStore.dispatch(new ReplaceAction(`/login?returnTo=${applicationStore.state.framework.navigationState.pathname}`)); - return null; - } - const contentType = result.headers.get("Content-Type") || result.headers.get("content-type"); - const isJson = contentType && contentType.toLowerCase().startsWith("application/json"); - try { - const data = result.ok && (isJson ? await result.json() : await result.text()) as TData ; - return data; - } catch { - return null; - } -} \ No newline at end of file diff --git a/sdnr/wt/odlux/framework/src/services/snackbarService.ts b/sdnr/wt/odlux/framework/src/services/snackbarService.ts deleted file mode 100644 index 50e279c67..000000000 --- a/sdnr/wt/odlux/framework/src/services/snackbarService.ts +++ /dev/null @@ -1,22 +0,0 @@ -/** - * ============LICENSE_START======================================================================== - * ONAP : ccsdk feature sdnr wt odlux - * ================================================================================================= - * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved. - * ================================================================================================= - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * ============LICENSE_END========================================================================== - */ -import { OptionsObject } from "notistack"; - -export const snackbarService = { - enqueueSnackbar: (message: string, options?: OptionsObject) =>{ } -} \ No newline at end of file -- cgit 1.2.3-korg