Adding filter bar
[aai/sparky-fe.git] / src / editAttributes / EditAttributeActions.js
1 /*
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 import NetworkCalls from './networking/NetworkCalls.js';
27 import {
28   POST,
29   BACKEND_POST_HEADER,
30   CREDENTIALS
31 } from './networking/NetworkConstants.js';
32 import {
33   createEditEntityAttributeRequestObject
34 } from './networking/NetworkUtils.js';
35 import {
36   setAttributesActionTypes,
37   EDIT_ENTITY_ATTRIBUTES_URL,
38   RESPONSE_CODE_SUCCESS,
39   RESPONSE_CODE_NOT_AUTHORIZED,
40   RESPONSE_MESSAGE_SUCCESS,
41   RESPONSE_MESSAGE_NOT_AUTHORIZED,
42   RESPONSE_MESSAGE_FAILURE,
43   RESPONSE_MESSAGE_NETWORK_ERROR
44 } from './EditAttributeConstants.js';
45
46 function errorReturnedEvent(errorMsg) {
47   return {
48     type: setAttributesActionTypes.SET_ATTRIBUTE_ERROR,
49     data: {errorMsg: errorMsg}
50   };
51 }
52
53 function successReturnedEvent() {
54   return {
55     type: setAttributesActionTypes.SET_ATTRIBUTE_SUCCESS,
56     data: {successMsg: RESPONSE_MESSAGE_SUCCESS}
57   };
58 }
59
60 function clearFeedbackMessageEvent() {
61   return {
62     type: setAttributesActionTypes.CLEAR_FEEDBACK_MESSAGE,
63     data: {}
64   };
65 }
66
67 export function clearFeebackMessage() {
68   return dispatch => {
69     dispatch(clearFeedbackMessageEvent());
70   };
71 }
72
73 export function requestEditEntityAttributes(entityURI, entityAttributes) {
74
75   let postBody = JSON.stringify(
76     createEditEntityAttributeRequestObject(entityURI, entityAttributes));
77   return dispatch => {
78     return NetworkCalls.fetchRequest(EDIT_ENTITY_ATTRIBUTES_URL,
79         CREDENTIALS, POST, BACKEND_POST_HEADER, postBody).then(
80       (responseJson) => {
81         if (responseJson) {
82           if (responseJson.resultCode === RESPONSE_CODE_SUCCESS) {
83             dispatch(successReturnedEvent());
84           } else if (responseJson.resultCode === RESPONSE_CODE_NOT_AUTHORIZED) {
85             dispatch(errorReturnedEvent(RESPONSE_MESSAGE_NOT_AUTHORIZED));
86           } else {
87             dispatch(errorReturnedEvent(RESPONSE_MESSAGE_FAILURE));
88           }
89         }
90       }
91     ).catch(
92       () => {
93         dispatch(errorReturnedEvent(RESPONSE_MESSAGE_NETWORK_ERROR));
94       }
95     );
96   };
97 }