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} from './SoftwareProductDependenciesConstants.js';
19 import uuid from 'uuid-js';
21 function baseUrl(softwareProductId, version) {
22 const versionId = version.id;
23 const restPrefix = Configuration.get('restPrefix');
24 return `${restPrefix}/v1.0/vendor-software-products/${softwareProductId}/versions/${versionId}/component-dependency-model`;
27 function fetchDependency(softwareProductId, version) {
28 return RestAPIUtil.fetch(`${baseUrl(softwareProductId, version)}`);
31 function postDependency(softwareProductId, version, dependenciesList) {
32 let modifedDependencyList = dependenciesList ? dependenciesList.filter(item => item.sourceId && item.targetId)
33 .map(item => ({sourceId: item.sourceId, targetId: item.targetId, relationType: item.relationType})) : [];
34 return RestAPIUtil.post(`${baseUrl(softwareProductId, version)}`, {componentDependencyModels:modifedDependencyList});
37 const SoftwareProductDependenciesActionHelper = {
38 updateDependencyList(dispatch, {dependenciesList}) {
39 dispatch({type: actionTypes.SOFTWARE_PRODUCT_DEPENDENCIES_LIST_UPDATE, dependenciesList});
41 addDependency(dispatch) {
42 dispatch({type: actionTypes.ADD_SOFTWARE_PRODUCT_DEPENDENCY});
44 fetchDependencies(dispatch, {softwareProductId, version}) {
45 return fetchDependency(softwareProductId, version).then( response => {
46 const dependenciesList = response.results ? response.results.map(item => {return {...item, id: uuid.create().toString()};}) : [];
48 type: actionTypes.SOFTWARE_PRODUCT_DEPENDENCIES_LIST_UPDATE,
53 saveDependencies(dispatch, {softwareProductId, version, dependenciesList}) {
54 return postDependency(softwareProductId, version, dependenciesList);
58 export default SoftwareProductDependenciesActionHelper;