summaryrefslogtreecommitdiffstats
path: root/src/app/contextHandler
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/contextHandler')
-rw-r--r--src/app/contextHandler/ContextHandlerActions.js137
-rw-r--r--src/app/contextHandler/ContextHandlerConstants.js41
2 files changed, 178 insertions, 0 deletions
diff --git a/src/app/contextHandler/ContextHandlerActions.js b/src/app/contextHandler/ContextHandlerActions.js
new file mode 100644
index 0000000..3cd57f7
--- /dev/null
+++ b/src/app/contextHandler/ContextHandlerActions.js
@@ -0,0 +1,137 @@
+/*
+ * ============LICENSE_START===================================================
+ * SPARKY (AAI UI service)
+ * ============================================================================
+ * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 Amdocs
+ * 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=====================================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ */
+
+import {
+ POST,
+ POST_HEADER
+} from 'app/networking/NetworkConstants.js';
+import networkCall from 'app/networking/NetworkCalls.js';
+import {EXTERNAL_REQ_ENTITY_SEARCH_URL,
+WRONG_EXTERNAL_REQUEST_MESSAGE,
+ WRONG_RESULT
+} from 'app/contextHandler/ContextHandlerConstants';
+import {
+ getSetGlobalMessageEvent,
+ getClearGlobalMessageEvent
+} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';
+
+import { STATUS_CODE_204_NO_CONTENT,
+ STATUS_CODE_3XX_REDIRECTION,
+ MESSAGE_LEVEL_DANGER
+} from 'utils/GlobalConstants.js';
+
+
+import {
+ contextHandlerActionTypes
+} from 'app/contextHandler/ContextHandlerConstants.js';
+
+function getExternalParamValues(urlParams) {
+ var pairs = decodeURIComponent(urlParams).replace('?','').replace(/\r\n|\n/,'').split('&');
+
+ var externalparamObject = {};
+ pairs.forEach(function(pair) {
+ pair = pair.split('=');
+ externalparamObject[pair[0]] = pair[1] || '';
+ });
+ return externalparamObject;
+
+}
+
+function validateExternalParams(externalURLParams) {
+ if(externalURLParams.view && externalURLParams.entityId && externalURLParams.entityType) {
+ return true;
+ }
+ return false;
+
+}
+
+
+function createSuggestionFoundEvent(suggestion) {
+ return {
+ type: contextHandlerActionTypes.SINGLE_SUGGESTION_FOUND,
+ data: suggestion
+ };
+}
+
+
+function fetchDataForExternalRequest(fetchRequestCallback) {
+ return dispatch => {
+ return fetchRequestCallback().then(
+ (response) => {
+ if (response.status === STATUS_CODE_204_NO_CONTENT || response.status >= STATUS_CODE_3XX_REDIRECTION) {
+ return Promise.reject(new Error(response.status));
+ } else {
+ // assume 200 status
+ return response.json();
+ }
+ }
+ ).then(
+ (results)=> {
+ if (results.suggestions !== undefined && results.suggestions.length === 1) {
+ dispatch(getClearGlobalMessageEvent());
+ dispatch(createSuggestionFoundEvent({suggestion: results.suggestions[0]}));
+ } else {
+ dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER));
+ }
+ }
+ ).catch(
+ () => {
+ dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER));
+ }
+ );
+ };
+}
+
+function validateAndFetchExternalParams(externalParams) {
+ if(!validateExternalParams(externalParams)) {
+ return dispatch => {
+ dispatch(
+ getSetGlobalMessageEvent(WRONG_EXTERNAL_REQUEST_MESSAGE, MESSAGE_LEVEL_DANGER));
+ };
+ } else {
+ let postBody = JSON.stringify(externalParams);
+ let externalfetchRequest =
+ () => networkCall.fetchRequestObj(EXTERNAL_REQ_ENTITY_SEARCH_URL, POST,
+ POST_HEADER, postBody);
+ return dispatch => {
+ dispatch(fetchDataForExternalRequest(externalfetchRequest));
+ };
+ }
+}
+export function externalUrlRequest(urlParams) {
+ let externalURLParams = getExternalParamValues(urlParams);
+ return dispatch => {
+ dispatch(
+ validateAndFetchExternalParams(externalURLParams));
+ };
+}
+export function externalMessageRequest(jsonParams) {
+ return dispatch => {
+ dispatch(
+ validateAndFetchExternalParams(jsonParams));
+ };
+
+}
+
diff --git a/src/app/contextHandler/ContextHandlerConstants.js b/src/app/contextHandler/ContextHandlerConstants.js
new file mode 100644
index 0000000..4a0137f
--- /dev/null
+++ b/src/app/contextHandler/ContextHandlerConstants.js
@@ -0,0 +1,41 @@
+/*
+ * ============LICENSE_START===================================================
+ * SPARKY (AAI UI service)
+ * ============================================================================
+ * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 Amdocs
+ * 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=====================================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ */
+
+
+import keyMirror from 'utils/KeyMirror.js';
+import {BASE_URL} from 'app/networking/NetworkConstants.js';
+
+export const contextHandlerActionTypes = keyMirror({
+ SINGLE_SUGGESTION_FOUND: null,
+ INVALID_SUGGESTION_FOUND: null
+});
+
+export const EXTERNAL_REQ_ENTITY_SEARCH_URL = BASE_URL + '/rest/search/externalRequestEntitySearch';
+export const WRONG_EXTERNAL_REQUEST_MESSAGE = 'External parameter request is incorrect';
+export const WRONG_RESULT = 'Invalid result for the requested external params.';
+
+
+
+