summaryrefslogtreecommitdiffstats
path: root/openecomp-ui/src/sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-ui/src/sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js')
-rw-r--r--openecomp-ui/src/sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js88
1 files changed, 83 insertions, 5 deletions
diff --git a/openecomp-ui/src/sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js b/openecomp-ui/src/sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js
index dd2a5c6003..f5017f6d7a 100644
--- a/openecomp-ui/src/sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js
+++ b/openecomp-ui/src/sdc-app/onboarding/licenseModel/licenseKeyGroups/LicenseKeyGroupsActionHelper.js
@@ -17,6 +17,8 @@ import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
import Configuration from 'sdc-app/config/Configuration.js';
import {actionTypes as licenseKeyGroupsConstants} from './LicenseKeyGroupsConstants.js';
import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
+import {actionTypes as limitEditorActions} from 'sdc-app/onboarding/licenseModel/limits/LimitEditorConstants.js';
+import getValue from 'nfvo-utils/getValue.js';
function baseUrl(licenseModelId, version) {
const restPrefix = Configuration.get('restPrefix');
@@ -36,8 +38,13 @@ function postLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) {
return RestAPIUtil.post(baseUrl(licenseModelId, version), {
name: licenseKeyGroup.name,
description: licenseKeyGroup.description,
- operationalScope: licenseKeyGroup.operationalScope,
- type: licenseKeyGroup.type
+ operationalScope: getValue(licenseKeyGroup.operationalScope),
+ type: licenseKeyGroup.type,
+ increments: licenseKeyGroup.increments,
+ thresholdValue: licenseKeyGroup.thresholdValue,
+ thresholdUnits: getValue(licenseKeyGroup.thresholdUnits),
+ startDate: licenseKeyGroup.startDate,
+ expiryDate: licenseKeyGroup.expiryDate
});
}
@@ -45,11 +52,50 @@ function putLicenseKeyGroup(licenseModelId, licenseKeyGroup, version) {
return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${licenseKeyGroup.id}`, {
name: licenseKeyGroup.name,
description: licenseKeyGroup.description,
- operationalScope: licenseKeyGroup.operationalScope,
- type: licenseKeyGroup.type
+ operationalScope: getValue(licenseKeyGroup.operationalScope),
+ type: licenseKeyGroup.type,
+ increments: licenseKeyGroup.increments,
+ thresholdValue: licenseKeyGroup.thresholdValue,
+ thresholdUnits: getValue(licenseKeyGroup.thresholdUnits),
+ startDate: licenseKeyGroup.startDate,
+ expiryDate: licenseKeyGroup.expiryDate
});
}
+function fetchLimitsList(licenseModelId, licenseKeyGroupId, version) {
+ return RestAPIUtil.fetch(`${baseUrl(licenseModelId, version)}/${licenseKeyGroupId}/limits`);
+}
+
+function deleteLimit(licenseModelId, licenseKeyGroupId, version, limitId) {
+ return RestAPIUtil.destroy(`${baseUrl(licenseModelId, version)}/${licenseKeyGroupId}/limits/${limitId}`);
+}
+
+function postLimit(licenseModelId, licenseKeyGroupId, version, limit) {
+ return RestAPIUtil.post(`${baseUrl(licenseModelId, version)}/${licenseKeyGroupId}/limits`, {
+ name: limit.name,
+ type: limit.type,
+ description: limit.description,
+ metric: limit.metric,
+ value: limit.value,
+ unit: limit.unit,
+ aggregationFunction: getValue(limit.aggregationFunction),
+ time: getValue(limit.time)
+ });
+}
+
+function putLimit(licenseModelId, licenseKeyGroupId, version, limit) {
+
+ return RestAPIUtil.put(`${baseUrl(licenseModelId, version)}/${licenseKeyGroupId}/limits/${limit.id}`, {
+ name: limit.name,
+ type: limit.type,
+ description: limit.description,
+ metric: limit.metric,
+ value: limit.value,
+ unit: limit.unit,
+ aggregationFunction: getValue(limit.aggregationFunction),
+ time: getValue(limit.time)
+ });
+}
export default {
fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version}) {
@@ -59,7 +105,10 @@ export default {
}));
},
- openLicenseKeyGroupsEditor(dispatch, {licenseKeyGroup} = {}) {
+ openLicenseKeyGroupsEditor(dispatch, {licenseKeyGroup, licenseModelId, version} = {}) {
+ if (licenseModelId && version) {
+ this.fetchLimits(dispatch, {licenseModelId, version, licenseKeyGroup});
+ }
dispatch({
type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.OPEN,
licenseKeyGroup
@@ -124,5 +173,34 @@ export default {
LicenseModelActionHelper.fetchLicenseModelById(dispatch, {licenseModelId, version}).then(() => {
this.fetchLicenseKeyGroupsList(dispatch, {licenseModelId, version});
});
+ },
+
+
+ fetchLimits(dispatch, {licenseModelId, version, licenseKeyGroup}) {
+ return fetchLimitsList(licenseModelId, licenseKeyGroup.id, version).then(response => {
+ dispatch({
+ type: licenseKeyGroupsConstants.licenseKeyGroupsEditor.LIMITS_LIST_LOADED,
+ response
+ });
+ });
+ },
+
+ submitLimit(dispatch, {licenseModelId, version, licenseKeyGroup, limit}) {
+ const promise = limit.id ? putLimit(licenseModelId,licenseKeyGroup.id, version, limit) :
+ postLimit(licenseModelId,licenseKeyGroup.id, version, limit);
+ return promise.then(() => {
+ dispatch({
+ type: limitEditorActions.CLOSE
+ });
+ this.fetchLimits(dispatch, {licenseModelId, version, licenseKeyGroup});
+ });
+ },
+
+ deleteLimit(dispatch, {licenseModelId, version, licenseKeyGroup, limit}) {
+ return deleteLimit(licenseModelId,licenseKeyGroup.id, version, limit.id).then(() => {
+ this.fetchLimits(dispatch, {licenseModelId, version, licenseKeyGroup});
+ });
}
+
+
};