Adding option for configurable header
[aai/sparky-fe.git] / src / app / personlaization / PersonalizationActions.js
diff --git a/src/app/personlaization/PersonalizationActions.js b/src/app/personlaization/PersonalizationActions.js
new file mode 100644 (file)
index 0000000..0d188fd
--- /dev/null
@@ -0,0 +1,80 @@
+/*\r
+ * ============LICENSE_START=======================================================\r
+ * org.onap.aai\r
+ * ================================================================================\r
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
+ * Copyright © 2017-2018 Amdocs\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *       http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+ import {\r
+    GET\r
+  } from 'app/networking/NetworkConstants.js';\r
+import networkCall from 'app/networking/NetworkCalls.js';\r
+import {\r
+  GET_PERSONALIZED_VALUES_URL, \r
+  PERSONALIZATION_FAILED_MESSAGE,\r
+  personalizationActionTypes\r
+} from 'app/personlaization/PersonalizationConstans.js';\r
+import {\r
+  getSetGlobalMessageEvent\r
+} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';\r
+\r
+import {  \r
+  STATUS_CODE_5XX_SERVER_ERROR,\r
+  MESSAGE_LEVEL_WARNING\r
+} from 'utils/GlobalConstants.js';\r
+\r
+\r
+function createPersonalizedValuesEvent(payload) {\r
+\r
+  let event = {\r
+    type: personalizationActionTypes.PERSONALIZATION_PAYLOAD_FOUND,\r
+    data: payload\r
+  };\r
+  return event;\r
+}\r
+\r
+function fetchPersonalizedValues(fetchRequestCallback) {\r
+  return dispatch => {\r
+    return fetchRequestCallback().then(\r
+      (response) => {\r
+        if (response.status >= STATUS_CODE_5XX_SERVER_ERROR) {\r
+          dispatch(getSetGlobalMessageEvent(PERSONALIZATION_FAILED_MESSAGE , MESSAGE_LEVEL_WARNING));\r
+        } else {\r
+          // assume 200 status\r
+          return response.json();\r
+        }\r
+      }\r
+    ).then(\r
+      (results)=> {\r
+        dispatch(createPersonalizedValuesEvent(results));\r
+      }\r
+    ).catch(\r
+      () => {\r
+        dispatch(getSetGlobalMessageEvent(PERSONALIZATION_FAILED_MESSAGE , MESSAGE_LEVEL_WARNING));\r
+      }\r
+    );\r
+  };\r
+}\r
+\r
+export function getPersonalizationDetails(){\r
+  let personalizationFetchRequest =\r
+    () => networkCall.getRequest(GET_PERSONALIZED_VALUES_URL, GET);\r
+    \r
+  return dispatch => {\r
+    dispatch(fetchPersonalizedValues(personalizationFetchRequest));\r
+  };\r
+}
\ No newline at end of file