diff options
Diffstat (limited to 'src/app/contextHandler')
-rw-r--r-- | src/app/contextHandler/ContextHandlerActions.js | 78 | ||||
-rw-r--r-- | src/app/contextHandler/ContextHandlerConstants.js | 15 |
2 files changed, 82 insertions, 11 deletions
diff --git a/src/app/contextHandler/ContextHandlerActions.js b/src/app/contextHandler/ContextHandlerActions.js index 5738f2a..889020a 100644 --- a/src/app/contextHandler/ContextHandlerActions.js +++ b/src/app/contextHandler/ContextHandlerActions.js @@ -20,14 +20,21 @@ * * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + import { POST, - POST_HEADER + POST_HEADER, + GET } from 'app/networking/NetworkConstants.js'; import networkCall from 'app/networking/NetworkCalls.js'; import {EXTERNAL_REQ_ENTITY_SEARCH_URL, WRONG_EXTERNAL_REQUEST_MESSAGE, - WRONG_RESULT + WRONG_RESULT, + ZERO_RESULT, + MULTIPLE_RESULT, + FAILED_REQUEST, + SUBSCRIPTION_FAILED_MESSAGE, + SUBSCRIPTION_PAYLOAD_URL } from 'app/contextHandler/ContextHandlerConstants'; import { getSetGlobalMessageEvent, @@ -36,7 +43,8 @@ import { import { STATUS_CODE_204_NO_CONTENT, STATUS_CODE_3XX_REDIRECTION, - MESSAGE_LEVEL_DANGER + MESSAGE_LEVEL_DANGER, + MESSAGE_LEVEL_WARNING } from 'utils/GlobalConstants.js'; @@ -56,6 +64,55 @@ function getExternalParamValues(urlParams) { } +function createSubscriptionPayloadEvent(payload) { + return { + type: contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_FOUND, + data: payload + }; +} + +function createSubscriptionIsEmptyEvent() { + return { + type: contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_EMPTY, + data: {} + }; +} + +function fetchSubscriptionPayload(fetchRequestCallback) { + return dispatch => { + return fetchRequestCallback().then( + (response) => { + if (response.status >= STATUS_CODE_3XX_REDIRECTION) { + return Promise.reject(new Error(response.status)); + } else { + // assume 200 status + return response; + } + } + ).then( + (results)=> { + dispatch(createSubscriptionPayloadEvent(results)); + + } + ).catch( + (e) => { + if(e.name === 'EmptyResponseException'){ + dispatch(getClearGlobalMessageEvent()); + dispatch(createSubscriptionIsEmptyEvent()); + } else{ + dispatch(getSetGlobalMessageEvent(SUBSCRIPTION_FAILED_MESSAGE , MESSAGE_LEVEL_WARNING)); + } + } + ); + }; +} +export function getSubscriptionPayload() { + let externalfetchRequest = + () => networkCall.getRequest(SUBSCRIPTION_PAYLOAD_URL, GET); + return dispatch => { + dispatch(fetchSubscriptionPayload(externalfetchRequest)); + }; +} function validateExternalParams(externalURLParams) { if(externalURLParams.view && externalURLParams.entityId && externalURLParams.entityType) { return true; @@ -86,16 +143,21 @@ function fetchDataForExternalRequest(fetchRequestCallback) { } ).then( (results)=> { - if (results.suggestions !== undefined && results.suggestions.length === 1) { - dispatch(getClearGlobalMessageEvent()); - dispatch(createSuggestionFoundEvent({suggestion: results.suggestions[0]})); + if (results.suggestions !== undefined) { + if( results.suggestions.length === 1) { + dispatch(getClearGlobalMessageEvent()); + dispatch(createSuggestionFoundEvent({suggestion: results.suggestions[0]})); + } else if(results.totalFound === 0 ) { + dispatch(getSetGlobalMessageEvent(ZERO_RESULT, MESSAGE_LEVEL_DANGER)); + } else { + dispatch(getSetGlobalMessageEvent(MULTIPLE_RESULT, MESSAGE_LEVEL_DANGER)); } } else { - dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER)); + dispatch(getSetGlobalMessageEvent(WRONG_RESULT, MESSAGE_LEVEL_DANGER)); } } ).catch( () => { - dispatch(getSetGlobalMessageEvent(WRONG_RESULT , MESSAGE_LEVEL_DANGER)); + dispatch(getSetGlobalMessageEvent(FAILED_REQUEST , MESSAGE_LEVEL_DANGER)); } ); }; diff --git a/src/app/contextHandler/ContextHandlerConstants.js b/src/app/contextHandler/ContextHandlerConstants.js index 809d05c..6229968 100644 --- a/src/app/contextHandler/ContextHandlerConstants.js +++ b/src/app/contextHandler/ContextHandlerConstants.js @@ -21,17 +21,26 @@ * ECOMP is a trademark and service mark 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 + INVALID_SUGGESTION_FOUND: null, + SUBSCRIPTION_PAYLOAD_EMPTY: null, + SUBSCRIPTION_PAYLOAD_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.'; +export const WRONG_EXTERNAL_REQUEST_MESSAGE = 'A parameter in the request is incorrect'; +export const WRONG_RESULT = 'Invalid result for the request.'; +export const FAILED_REQUEST = 'Failed to pull result for the request.'; +export const ZERO_RESULT = 'No result has been found for this request.'; +export const MULTIPLE_RESULT = 'Multiple results were found for this request so none got selected.'; +export const SUBSCRIPTION_FAILED_MESSAGE = 'Failed to fetch subscription payload.'; +export const SUBSCRIPTION_PAYLOAD_URL = BASE_URL + '/subscription/getsubscription'; + |