2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
29 } from 'app/networking/NetworkConstants.js';
30 import networkCall from 'app/networking/NetworkCalls.js';
31 import {EXTERNAL_REQ_ENTITY_SEARCH_URL,
32 WRONG_EXTERNAL_REQUEST_MESSAGE,
34 } from 'app/contextHandler/ContextHandlerConstants';
36 getSetGlobalMessageEvent,
37 getClearGlobalMessageEvent
38 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';
40 import { STATUS_CODE_204_NO_CONTENT,
41 STATUS_CODE_3XX_REDIRECTION,
43 } from 'utils/GlobalConstants.js';
47 contextHandlerActionTypes
48 } from 'app/contextHandler/ContextHandlerConstants.js';
50 function getExternalParamValues(urlParams) {
51 var pairs = decodeURIComponent(urlParams).replace('?','').replace(/\r\n|\n/,'').split('&');
53 var externalparamObject = {};
54 pairs.forEach(function(pair) {
55 pair = pair.split('=');
56 externalparamObject[pair[0]] = pair[1] || '';
58 return externalparamObject;
62 function validateExternalParams(externalURLParams) {
63 if(externalURLParams.view && externalURLParams.entityId && externalURLParams.entityType) {
71 function createSuggestionFoundEvent(suggestion) {
73 type: contextHandlerActionTypes.SINGLE_SUGGESTION_FOUND,
79 function fetchDataForExternalRequest(fetchRequestCallback) {
81 return fetchRequestCallback().then(
83 if (response.status === STATUS_CODE_204_NO_CONTENT || response.status >= STATUS_CODE_3XX_REDIRECTION) {
84 return Promise.reject(new Error(response.status));
87 return response.json();
92 if (results.suggestions !== undefined && results.suggestions.length === 1) {
93 dispatch(getClearGlobalMessageEvent());
94 dispatch(createSuggestionFoundEvent({suggestion: results.suggestions[0]}));
96 dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER));
101 dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER));
107 function validateAndFetchExternalParams(externalParams) {
108 if(!validateExternalParams(externalParams)) {
111 getSetGlobalMessageEvent(WRONG_EXTERNAL_REQUEST_MESSAGE, MESSAGE_LEVEL_DANGER));
114 let postBody = JSON.stringify(externalParams);
115 let externalfetchRequest =
116 () => networkCall.fetchRequestObj(EXTERNAL_REQ_ENTITY_SEARCH_URL, POST,
117 POST_HEADER, postBody);
119 dispatch(fetchDataForExternalRequest(externalfetchRequest));
123 export function externalUrlRequest(urlParams) {
124 let externalURLParams = getExternalParamValues(urlParams);
127 validateAndFetchExternalParams(externalURLParams));
130 export function externalMessageRequest(jsonParams) {
133 validateAndFetchExternalParams(jsonParams));