Adding filter bar
[aai/sparky-fe.git] / src / editAttributes / EditAttributeActions.js
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 import NetworkCalls from './networking/NetworkCalls.js';
24 import {
25   POST,
26   BACKEND_POST_HEADER,
27   CREDENTIALS
28 } from './networking/NetworkConstants.js';
29 import {
30   createEditEntityAttributeRequestObject
31 } from './networking/NetworkUtils.js';
32 import {
33   setAttributesActionTypes,
34   EDIT_ENTITY_ATTRIBUTES_URL,
35   RESPONSE_CODE_SUCCESS,
36   RESPONSE_CODE_NOT_AUTHORIZED,
37   RESPONSE_MESSAGE_SUCCESS,
38   RESPONSE_MESSAGE_NOT_AUTHORIZED,
39   RESPONSE_MESSAGE_FAILURE,
40   RESPONSE_MESSAGE_NETWORK_ERROR
41 } from './EditAttributeConstants.js';
42
43 function errorReturnedEvent(errorMsg) {
44   return {
45     type: setAttributesActionTypes.SET_ATTRIBUTE_ERROR,
46     data: {errorMsg: errorMsg}
47   };
48 }
49
50 function successReturnedEvent() {
51   return {
52     type: setAttributesActionTypes.SET_ATTRIBUTE_SUCCESS,
53     data: {successMsg: RESPONSE_MESSAGE_SUCCESS}
54   };
55 }
56
57 function clearFeedbackMessageEvent() {
58   return {
59     type: setAttributesActionTypes.CLEAR_FEEDBACK_MESSAGE,
60     data: {}
61   };
62 }
63
64 export function clearFeebackMessage() {
65   return dispatch => {
66     dispatch(clearFeedbackMessageEvent());
67   };
68 }
69
70 export function requestEditEntityAttributes(entityURI, entityAttributes) {
71
72   let postBody = JSON.stringify(
73     createEditEntityAttributeRequestObject(entityURI, entityAttributes));
74   return dispatch => {
75     return NetworkCalls.fetchRequest(EDIT_ENTITY_ATTRIBUTES_URL,
76         CREDENTIALS, POST, BACKEND_POST_HEADER, postBody).then(
77       (responseJson) => {
78         if (responseJson) {
79           if (responseJson.resultCode === RESPONSE_CODE_SUCCESS) {
80             dispatch(successReturnedEvent());
81           } else if (responseJson.resultCode === RESPONSE_CODE_NOT_AUTHORIZED) {
82             dispatch(errorReturnedEvent(RESPONSE_MESSAGE_NOT_AUTHORIZED));
83           } else {
84             dispatch(errorReturnedEvent(RESPONSE_MESSAGE_FAILURE));
85           }
86         }
87       }
88     ).catch(
89       () => {
90         dispatch(errorReturnedEvent(RESPONSE_MESSAGE_NETWORK_ERROR));
91       }
92     );
93   };
94 }