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