Handling new BE subscription payload 83/28583/1
authorricharv <richard.vondadelszen@amdocs.com>
Thu, 18 Jan 2018 21:03:12 +0000 (16:03 -0500)
committerricharv <richard.vondadelszen@amdocs.com>
Thu, 18 Jan 2018 21:04:20 +0000 (16:04 -0500)
Issue-ID: AAI-676
Change-Id: I5c6307f43b20487068bc4ba3b6d9fee5b25e2027
Signed-off-by: richarv <richard.vondadelszen@amdocs.com>
src/app/MainScreenHeader.jsx
src/app/MainScreenWrapperReducer.js
src/app/contextHandler/ContextHandlerActions.js
src/app/contextHandler/ContextHandlerConstants.js
src/app/networking/NetworkCalls.js

index 49952f7..912a5ad 100644 (file)
@@ -135,6 +135,7 @@ class MainScreenHeader extends Component {
       return false;
     }
   }
+  
   isValidExternalURL(url) {
     if(decodeURIComponent(url).indexOf('&') > 0 ) {
       return true;
@@ -142,6 +143,7 @@ class MainScreenHeader extends Component {
       return false;
     }
   }
+
   componentWillMount() {
     this.props.onGetSubscriptionPayload();
     if(this.props.match.params.externalUrl !== undefined &&
@@ -149,6 +151,7 @@ class MainScreenHeader extends Component {
       this.props.onExternalUrlRequest(this.props.match.params.externalUrl);
     }
   }
+
   componentWillReceiveProps(nextProps) {
     if (this.props.location &&
       this.props.location.pathname !==
index 6dd7dbf..79bb05d 100644 (file)
@@ -71,7 +71,7 @@ export default (state = {}, action) => {
     case contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_FOUND:
       return {
         ...state,
-        subscriptionPayload: action.data,
+        subscriptionPayload: action.data.subscriptionDetails,
         subscriptionEnabled: true
       };
     case contextHandlerActionTypes.SUBSCRIPTION_PAYLOAD_EMPTY:
index 889020a..0fe43ff 100644 (file)
@@ -65,17 +65,22 @@ 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) {
@@ -86,26 +91,21 @@ function fetchSubscriptionPayload(fetchRequestCallback) {
           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);
@@ -113,6 +113,7 @@ export function getSubscriptionPayload() {
     dispatch(fetchSubscriptionPayload(externalfetchRequest));
   };
 }
+
 function validateExternalParams(externalURLParams) {
   if(externalURLParams.view && externalURLParams.entityId && externalURLParams.entityType) {
     return true;
@@ -121,7 +122,6 @@ function validateExternalParams(externalURLParams) {
 
 }
 
-
 function createSuggestionFoundEvent(suggestion) {
   return {
     type: contextHandlerActionTypes.SINGLE_SUGGESTION_FOUND,
index 6229968..9abbb31 100644 (file)
@@ -39,7 +39,7 @@ 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';
+export const SUBSCRIPTION_PAYLOAD_URL = BASE_URL + '/rest/subscription/getsubscription';
 
 
 
index b6c96b7..003e69d 100644 (file)
@@ -21,9 +21,6 @@
  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 
-function EmptyResponseException(){
-  this.name = 'EmptyResponseException';
-}
 function fetchRequest(URL, POST, POST_HEADER, BODY) {
   return fetch(URL, {
     credentials: 'same-origin',
@@ -44,27 +41,13 @@ function fetchRequestObj(URL, POST, POST_HEADER, BODY) {
   });
 }
 
-function processResponse(response){
-  if(response.status === 204){
-    throw new EmptyResponseException();
-  }
-  return response.json();
-}
 function getRequest(URL, GET) {
   return fetch(URL, {
     credentials: 'same-origin',
     method: GET
-  }).then(
-    (response) => {
-      try{
-        response.json();
-      } catch (e){
-        response.isValidJson = false;
-      }
-      return processResponse(response);
-    }
-  );
+  });
 }
+
 module.exports = {
   fetchRequest: fetchRequest,
   fetchRequestObj: fetchRequestObj,