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';
21 } from './SoftwareProductDependenciesConstants.js';
23 function baseUrl(softwareProductId, version) {
24 const versionId = version.id;
25 const restPrefix = Configuration.get('restPrefix');
26 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/component-dependencies`;
29 function fetchDependencies(softwareProductId, version) {
30 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
33 function addDepencency(softwareProductId, version, item) {
34 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {
35 sourceId: item.sourceId,
36 targetId: item.targetId,
37 relationType: item.relationType
41 function updateDepencency(softwareProductId, version, item) {
42 return RestAPIUtil.put(
43 `${baseUrl(softwareProductId, version)}/${item.id}`,
45 sourceId: item.sourceId,
46 targetId: item.targetId,
47 relationType: item.relationType
52 function removeDependency(softwareProductId, version, item) {
53 return RestAPIUtil.destroy(
54 `${baseUrl(softwareProductId, version)}/${item.id}`
58 const SoftwareProductDependenciesActionHelper = {
59 updateDependency(dispatch, { softwareProductId, version, item }) {
60 // if change was made on existing item - we will update the server and refresh the list
61 // if change was made on the 'new' row - we will only fire the event
62 if (item.id !== NEW_RULE_TEMP_ID) {
63 return updateDepencency(softwareProductId, version, item).then(
65 return this.fetchDependencies(dispatch, {
73 type: actionTypes.UPDATE_NEW_SOFTWARE_PRODUCT_DEPENDENCY,
79 createDependency(dispatch, { softwareProductId, version, item }) {
80 // removing the temp id
82 // creating the new dependency
83 return addDepencency(softwareProductId, version, item).then(() => {
85 type: actionTypes.ADD_SOFTWARE_PRODUCT_DEPENDENCY
87 return this.fetchDependencies(dispatch, {
94 removeDependency(dispatch, { softwareProductId, version, item }) {
95 return removeDependency(softwareProductId, version, item).then(() => {
96 return this.fetchDependencies(dispatch, {
103 fetchDependencies(dispatch, { softwareProductId, version }) {
104 return fetchDependencies(softwareProductId, version).then(response => {
106 type: actionTypes.SOFTWARE_PRODUCT_DEPENDENCIES_LIST_UPDATE,
107 dependenciesList: response.results
113 export default SoftwareProductDependenciesActionHelper;