2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17 import Configuration from 'sdc-app/config/Configuration.js';
18 import {actionTypes, NEW_RULE_TEMP_ID} from './SoftwareProductDependenciesConstants.js';
20 function baseUrl(softwareProductId, version) {
21 const versionId = version.id;
22 const restPrefix = Configuration.get('restPrefix');
23 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/component-dependencies`;
26 function fetchDependencies(softwareProductId, version) {
27 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
30 function addDepencency(softwareProductId, version, item) {
31 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
32 sourceId: item.sourceId,
33 targetId: item.targetId,
34 relationType: item.relationType
39 function updateDepencency(softwareProductId, version, item) {
40 return RestAPIUtil.put(`${baseUrl(softwareProductId, version)}/${item.id}`,
42 sourceId: item.sourceId,
43 targetId: item.targetId,
44 relationType: item.relationType
48 function removeDependency(softwareProductId, version, item) {
49 return RestAPIUtil.destroy(`${baseUrl(softwareProductId, version)}/${item.id}`);
53 const SoftwareProductDependenciesActionHelper = {
54 updateDependency(dispatch, {softwareProductId, version, item}) {
55 // if change was made on existing item - we will update the server and refresh the list
56 // if change was made on the 'new' row - we will only fire the event
57 if (item.id !== NEW_RULE_TEMP_ID) {
58 return updateDepencency(softwareProductId, version, item).then(() => {
59 return this.fetchDependencies(dispatch, {softwareProductId, version});
63 type: actionTypes.UPDATE_NEW_SOFTWARE_PRODUCT_DEPENDENCY,
69 createDependency(dispatch, {softwareProductId, version, item}) {
70 // removing the temp id
72 // creating the new dependency
73 return addDepencency(softwareProductId, version, item).then(() => {
75 type: actionTypes.ADD_SOFTWARE_PRODUCT_DEPENDENCY
77 return this.fetchDependencies(dispatch, {softwareProductId, version});
81 removeDependency(dispatch, {softwareProductId, version, item}) {
82 return removeDependency(softwareProductId, version, item).then( () => {
83 return this.fetchDependencies(dispatch, {softwareProductId, version});
87 fetchDependencies(dispatch, {softwareProductId, version}) {
88 return fetchDependencies(softwareProductId, version).then( response => {
90 type: actionTypes.SOFTWARE_PRODUCT_DEPENDENCIES_LIST_UPDATE,
91 dependenciesList : response.results
97 export default SoftwareProductDependenciesActionHelper;