Adding option for configurable header
[aai/sparky-fe.git] / src / app / personlaization / PersonalizationActions.js
1 /*\r
2  * ============LICENSE_START=======================================================\r
3  * org.onap.aai\r
4  * ================================================================================\r
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
6  * Copyright © 2017-2018 Amdocs\r
7  * ================================================================================\r
8  * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * you may not use this file except in compliance with the License.\r
10  * You may obtain a copy of the License at\r
11  *\r
12  *       http://www.apache.org/licenses/LICENSE-2.0\r
13  *\r
14  * Unless required by applicable law or agreed to in writing, software\r
15  * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * See the License for the specific language governing permissions and\r
18  * limitations under the License.\r
19  * ============LICENSE_END=========================================================\r
20  */\r
21 \r
22  import {\r
23     GET\r
24   } from 'app/networking/NetworkConstants.js';\r
25 import networkCall from 'app/networking/NetworkCalls.js';\r
26 import {\r
27   GET_PERSONALIZED_VALUES_URL, \r
28   PERSONALIZATION_FAILED_MESSAGE,\r
29   personalizationActionTypes\r
30 } from 'app/personlaization/PersonalizationConstans.js';\r
31 import {\r
32   getSetGlobalMessageEvent\r
33 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js';\r
34 \r
35 import {  \r
36   STATUS_CODE_5XX_SERVER_ERROR,\r
37   MESSAGE_LEVEL_WARNING\r
38 } from 'utils/GlobalConstants.js';\r
39 \r
40 \r
41 function createPersonalizedValuesEvent(payload) {\r
42 \r
43   let event = {\r
44     type: personalizationActionTypes.PERSONALIZATION_PAYLOAD_FOUND,\r
45     data: payload\r
46   };\r
47   return event;\r
48 }\r
49 \r
50 function fetchPersonalizedValues(fetchRequestCallback) {\r
51   return dispatch => {\r
52     return fetchRequestCallback().then(\r
53       (response) => {\r
54         if (response.status >= STATUS_CODE_5XX_SERVER_ERROR) {\r
55           dispatch(getSetGlobalMessageEvent(PERSONALIZATION_FAILED_MESSAGE , MESSAGE_LEVEL_WARNING));\r
56         } else {\r
57           // assume 200 status\r
58           return response.json();\r
59         }\r
60       }\r
61     ).then(\r
62       (results)=> {\r
63         dispatch(createPersonalizedValuesEvent(results));\r
64       }\r
65     ).catch(\r
66       () => {\r
67         dispatch(getSetGlobalMessageEvent(PERSONALIZATION_FAILED_MESSAGE , MESSAGE_LEVEL_WARNING));\r
68       }\r
69     );\r
70   };\r
71 }\r
72 \r
73 export function getPersonalizationDetails(){\r
74   let personalizationFetchRequest =\r
75     () => networkCall.getRequest(GET_PERSONALIZED_VALUES_URL, GET);\r
76     \r
77   return dispatch => {\r
78     dispatch(fetchPersonalizedValues(personalizationFetchRequest));\r
79   };\r
80 }