[AAI] Remove Robby Maharajh & Harish Kajur as committers
[aai/sparky-fe.git] / src / app / contextHandler / ContextHandlerActions.js
index 889020a..35091b5 100644 (file)
@@ -2,8 +2,8 @@
  * ============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,
@@ -65,54 +62,52 @@ function getExternalParamValues(urlParams) {
 }
 
 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;
@@ -121,7 +116,6 @@ function validateExternalParams(externalURLParams) {
 
 }
 
-
 function createSuggestionFoundEvent(suggestion) {
   return {
     type: contextHandlerActionTypes.SINGLE_SUGGESTION_FOUND,
@@ -131,8 +125,8 @@ function createSuggestionFoundEvent(suggestion) {
 
 
 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));
@@ -160,7 +154,6 @@ function fetchDataForExternalRequest(fetchRequestCallback) {
         dispatch(getSetGlobalMessageEvent(FAILED_REQUEST , MESSAGE_LEVEL_DANGER));
       }
     );
-  };
 }
 
 function validateAndFetchExternalParams(externalParams) {
@@ -174,17 +167,12 @@ 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 => {