2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
26 } from 'app/networking/NetworkConstants.js';
27 import networkCall from 'app/networking/NetworkCalls.js';
28 import {EXTERNAL_REQ_ENTITY_SEARCH_URL,
29 WRONG_EXTERNAL_REQUEST_MESSAGE,
31 } from 'app/contextHandler/ContextHandlerConstants';
33 getSetGlobalMessageEvent,
34 getClearGlobalMessageEvent
35 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';
37 import { STATUS_CODE_204_NO_CONTENT,
38 STATUS_CODE_3XX_REDIRECTION,
40 } from 'utils/GlobalConstants.js';
44 contextHandlerActionTypes
45 } from 'app/contextHandler/ContextHandlerConstants.js';
47 function getExternalParamValues(urlParams) {
48 var pairs = decodeURIComponent(urlParams).replace('?','').replace(/\r\n|\n/,'').split('&');
50 var externalparamObject = {};
51 pairs.forEach(function(pair) {
52 pair = pair.split('=');
53 externalparamObject[pair[0]] = pair[1] || '';
55 return externalparamObject;
59 function validateExternalParams(externalURLParams) {
60 if(externalURLParams.view && externalURLParams.entityId && externalURLParams.entityType) {
68 function createSuggestionFoundEvent(suggestion) {
70 type: contextHandlerActionTypes.SINGLE_SUGGESTION_FOUND,
76 function fetchDataForExternalRequest(fetchRequestCallback) {
78 return fetchRequestCallback().then(
80 if (response.status === STATUS_CODE_204_NO_CONTENT || response.status >= STATUS_CODE_3XX_REDIRECTION) {
81 return Promise.reject(new Error(response.status));
84 return response.json();
89 if (results.suggestions !== undefined && results.suggestions.length === 1) {
90 dispatch(getClearGlobalMessageEvent());
91 dispatch(createSuggestionFoundEvent({suggestion: results.suggestions[0]}));
93 dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER));
98 dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER));
104 function validateAndFetchExternalParams(externalParams) {
105 if(!validateExternalParams(externalParams)) {
108 getSetGlobalMessageEvent(WRONG_EXTERNAL_REQUEST_MESSAGE, MESSAGE_LEVEL_DANGER));
111 let postBody = JSON.stringify(externalParams);
112 let externalfetchRequest =
113 () => networkCall.fetchRequestObj(EXTERNAL_REQ_ENTITY_SEARCH_URL, POST,
114 POST_HEADER, postBody);
116 dispatch(fetchDataForExternalRequest(externalfetchRequest));
120 export function externalUrlRequest(urlParams) {
121 let externalURLParams = getExternalParamValues(urlParams);
124 validateAndFetchExternalParams(externalURLParams));
127 export function externalMessageRequest(jsonParams) {
130 validateAndFetchExternalParams(jsonParams));