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