Add new code new version
[sdc.git] / openecomp-ui / src / sdc-app / onboarding / softwareProduct / creation / SoftwareProductCreationActionHelper.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
22 import Configuration from 'sdc-app/config/Configuration.js';
23
24 import SoftwareProductActionHelper from 'sdc-app/onboarding/softwareProduct/SoftwareProductActionHelper.js';
25 import {actionTypes} from './SoftwareProductCreationConstants.js';
26
27
28 function baseUrl() {
29         const restPrefix = Configuration.get('restPrefix');
30         return `${restPrefix}/v1.0/vendor-software-products/`;
31 }
32
33 function createSoftwareProduct(softwareProduct) {
34         return RestAPIUtil.create(baseUrl(), {
35                 ...softwareProduct,
36                 icon: 'icon',
37                 licensingData: {}
38         });
39 }
40
41 const SoftwareProductCreationActionHelper = {
42
43         open(dispatch) {
44                 SoftwareProductActionHelper.loadSoftwareProductAssociatedData(dispatch);
45                 dispatch({
46                         type: actionTypes.OPEN
47                 });
48         },
49
50         resetData(dispatch) {
51                 dispatch({
52                         type: actionTypes.RESET_DATA
53                 });
54         },
55
56         changeData(dispatch, {deltaData}) {
57                 dispatch({
58                         type: actionTypes.DATA_CHANGED,
59                         deltaData
60                 });
61         },
62
63         createSoftwareProduct(dispatch, {softwareProduct}) {
64                 return createSoftwareProduct(softwareProduct).then(response => {
65                         SoftwareProductActionHelper.addSoftwareProduct(dispatch, {
66                                 softwareProduct: {
67                                         ...softwareProduct,
68                                         id: response.vspId
69                                 }
70                         });
71                         return response.vspId;
72                 });
73         }
74
75 };
76
77 export default SoftwareProductCreationActionHelper;