* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017 Amdocs
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-
import {
POST,
POST_HEADER,
}
function createSubscriptionPayloadEvent(payload) {
- return {
- type: contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_FOUND,
- data: payload
- };
-}
-function createSubscriptionIsEmptyEvent() {
- return {
- type: contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_EMPTY,
- data: {}
- };
+ let event = undefined;
+
+ if (payload.subscriptionEnabled) {
+ event = {
+ type: contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_FOUND,
+ data: payload
+ };
+ } else {
+ event = {
+ type: contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_EMPTY,
+ data: {}
+ };
+ }
+
+ return event;
}
function fetchSubscriptionPayload(fetchRequestCallback) {
- return dispatch => {
- return fetchRequestCallback().then(
+ return dispatch => fetchRequestCallback().then(
(response) => {
if (response.status >= STATUS_CODE_3XX_REDIRECTION) {
return Promise.reject(new Error(response.status));
} else {
// assume 200 status
- return response;
+ return response.json();
}
}
).then(
(results)=> {
dispatch(createSubscriptionPayloadEvent(results));
-
}
).catch(
- (e) => {
- if(e.name === 'EmptyResponseException'){
- dispatch(getClearGlobalMessageEvent());
- dispatch(createSubscriptionIsEmptyEvent());
- } else{
- dispatch(getSetGlobalMessageEvent(SUBSCRIPTION_FAILED_MESSAGE , MESSAGE_LEVEL_WARNING));
- }
+ () => {
+ dispatch(getSetGlobalMessageEvent(SUBSCRIPTION_FAILED_MESSAGE , MESSAGE_LEVEL_WARNING));
}
);
- };
}
+
export function getSubscriptionPayload() {
let externalfetchRequest =
- () => networkCall.getRequest(SUBSCRIPTION_PAYLOAD_URL, GET);
- return dispatch => {
- dispatch(fetchSubscriptionPayload(externalfetchRequest));
- };
+ () => networkCall.getRequest(SUBSCRIPTION_PAYLOAD_URL, GET);
+
+ return dispatch => dispatch(fetchSubscriptionPayload(externalfetchRequest));
}
+
function validateExternalParams(externalURLParams) {
if(externalURLParams.view && externalURLParams.entityId && externalURLParams.entityType) {
return true;
}
-
function createSuggestionFoundEvent(suggestion) {
return {
type: contextHandlerActionTypes.SINGLE_SUGGESTION_FOUND,
function fetchDataForExternalRequest(fetchRequestCallback) {
- return dispatch => {
- return fetchRequestCallback().then(
+ return dispatch =>
+ fetchRequestCallback().then(
(response) => {
if (response.status === STATUS_CODE_204_NO_CONTENT || response.status >= STATUS_CODE_3XX_REDIRECTION) {
return Promise.reject(new Error(response.status));
dispatch(getSetGlobalMessageEvent(FAILED_REQUEST , MESSAGE_LEVEL_DANGER));
}
);
- };
}
function validateAndFetchExternalParams(externalParams) {
let externalfetchRequest =
() => networkCall.fetchRequestObj(EXTERNAL_REQ_ENTITY_SEARCH_URL, POST,
POST_HEADER, postBody);
- return dispatch => {
- dispatch(fetchDataForExternalRequest(externalfetchRequest));
- };
+ return dispatch => dispatch(fetchDataForExternalRequest(externalfetchRequest));
}
}
export function externalUrlRequest(urlParams) {
let externalURLParams = getExternalParamValues(urlParams);
- return dispatch => {
- dispatch(
- validateAndFetchExternalParams(externalURLParams));
- };
+ return dispatch => dispatch(validateAndFetchExternalParams(externalURLParams));
}
export function externalMessageRequest(jsonParams) {
return dispatch => {