summaryrefslogtreecommitdiffstats
path: root/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup
diff options
context:
space:
mode:
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup')
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.actions.ts82
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.spec.ts140
-rw-r--r--vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts108
3 files changed, 330 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.actions.ts
new file mode 100644
index 000000000..4ed377b7d
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.actions.ts
@@ -0,0 +1,82 @@
+import {Action, ActionCreator} from "redux";
+import {VnfGroupInstance} from "../../../models/vnfGroupInstance";
+import {VnfMember} from "../../../models/VnfMember";
+
+export enum VnfGroupActions {
+ CREATE_VNF_GROUP_INSTANCE = "CREATE_VNF_GROUP_INSTANCE",
+ UPDATE_VNF_GROUP_INSTANCE = "UPDATE_VNF_GROUP_INSTANCE",
+ DELETE_ACTION_VNF_GROUP_INSTANCE = "DELETE_VNF_GROUP_INSTANCE",
+ UNDO_DELETE_ACTION_VNF_GROUP_INSTANCE = "UNDO_DELETE_VNF_GROUP_INSTANCE",
+ SET_OPTIONAL_MEMBERS_VNF_GROUP_INSTANCE = "SET_OPTIONAL_MEMBERS_VNF_GROUP_INSTANCE"
+}
+
+
+export interface CreateVnfGroupInstanceAction extends Action {
+ vnfGroupInstance?: VnfGroupInstance;
+ vnfGroupModelName?: string;
+ serviceUuid?: string;
+ vnfGroupStoreKey?:string;
+}
+
+export interface UpdateVnfGroupInstanceAction extends Action {
+ vnfGroupInstance?: VnfGroupInstance;
+ vnfGroupModelName?: string;
+ serviceUuid?: string;
+ vnfGroupStoreKey?:string;
+}
+
+export interface DeleteActionVnfGroupInstanceAction extends Action {
+ vnfGroupStoreKey: string;
+ serviceId?: string;
+}
+
+export interface UndoDeleteActionVnfGroupInstanceAction extends Action {
+ vnfGroupStoreKey: string;
+ serviceId?: string;
+}
+
+export interface SetOptionalMembersVnfGroupInstanceAction extends Action{
+ path?: string;
+ serviceId?: string;
+ vnfMembers?: VnfMember[]
+}
+
+export const createVnfGroupInstance: ActionCreator<CreateVnfGroupInstanceAction> = (vnfGroupInstance, vnfGroupModelName, serviceUuid, vnfGroupStoreKey) => ({
+ type: VnfGroupActions.CREATE_VNF_GROUP_INSTANCE,
+ vnfGroupInstance: vnfGroupInstance,
+ vnfGroupModelName: vnfGroupModelName,
+ serviceUuid: serviceUuid,
+ vnfGroupStoreKey : vnfGroupStoreKey
+});
+
+
+export const updateVnfGroupInstance: ActionCreator<UpdateVnfGroupInstanceAction> = (vnfGroupInstance, vnfGroupModelName, serviceUuid, vnfGroupStoreKey) => ({
+ type: VnfGroupActions.UPDATE_VNF_GROUP_INSTANCE,
+ vnfGroupInstance: vnfGroupInstance,
+ vnfGroupModelName: vnfGroupModelName,
+ serviceUuid: serviceUuid,
+ vnfGroupStoreKey : vnfGroupStoreKey
+});
+
+export const deleteActionVnfGroupInstance: ActionCreator<DeleteActionVnfGroupInstanceAction> = (vnfGroupStoreKey, serviceId) => ({
+ type: VnfGroupActions.DELETE_ACTION_VNF_GROUP_INSTANCE,
+ vnfGroupStoreKey: vnfGroupStoreKey,
+ serviceId: serviceId
+});
+
+export const undoDeleteActionVnfGroupInstance: ActionCreator<UndoDeleteActionVnfGroupInstanceAction> = (vnfGroupStoreKey, serviceId) => ({
+ type: VnfGroupActions.UNDO_DELETE_ACTION_VNF_GROUP_INSTANCE,
+ vnfGroupStoreKey: vnfGroupStoreKey,
+ serviceId: serviceId
+});
+
+export const setOptionalMembersVnfGroupInstance: ActionCreator<SetOptionalMembersVnfGroupInstanceAction> = ( serviceId: string, path: string, vnfMembers: VnfMember[]) => ({
+ type: VnfGroupActions.SET_OPTIONAL_MEMBERS_VNF_GROUP_INSTANCE,
+ path: path,
+ serviceId: serviceId,
+ vnfMembers: vnfMembers
+});
+
+
+
+
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.spec.ts
new file mode 100644
index 000000000..16c1c45cd
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.spec.ts
@@ -0,0 +1,140 @@
+import {VnfGroupInstance} from "../../../models/vnfGroupInstance";
+import {
+ CreateVnfGroupInstanceAction,
+ DeleteActionVnfGroupInstanceAction,
+ SetOptionalMembersVnfGroupInstanceAction,
+ UpdateVnfGroupInstanceAction,
+ VnfGroupActions
+} from "./vnfGroup.actions";
+import {vnfGroupReducer} from "./vnfGroup.reducers";
+import {ServiceInstanceActions} from "../../../models/serviceInstanceActions";
+import {VnfMember} from "../../../models/VnfMember";
+
+
+describe('vnfGroupReducer', () => {
+ test('#CREATE_VNF_GROUP_INSTANCE', () => {
+ let vnfGroupInstance: VnfGroupInstance = new VnfGroupInstance();
+ vnfGroupInstance.isMissingData = false;
+ vnfGroupInstance.instanceName = 'instanceName';
+ let vnfGroupState = vnfGroupReducer(<any>{serviceInstance : {
+ 'serviceModelId' : {
+ vnfGroups : {
+
+ }
+ }
+ }},
+ <CreateVnfGroupInstanceAction>{
+ type: VnfGroupActions.CREATE_VNF_GROUP_INSTANCE,
+ vnfGroupInstance : vnfGroupInstance,
+ vnfGroupStoreKey : null,
+ vnfGroupModelName : 'vnfGroupModelName',
+ serviceUuid : 'serviceModelId'
+ }).serviceInstance['serviceModelId'].vnfGroups['vnfGroupModelName'];
+
+ expect(vnfGroupState).toBeDefined();
+ expect(vnfGroupState.isMissingData).toBeFalsy();
+ });
+
+ test('#UPDATE_VNF_GROUP_INSTANCE', () => {
+ let vnfGroupInstance: VnfGroupInstance = new VnfGroupInstance();
+ vnfGroupInstance.isMissingData = false;
+ vnfGroupInstance.instanceName = 'instanceName';
+ let vnfGroupState = vnfGroupReducer(<any>{serviceInstance : {
+ 'serviceModelId' : {
+ vnfGroups : {
+ 'vnfGroupStoreKey' : {
+ isMissingData : true
+ }
+ }
+ }
+ }},
+ <UpdateVnfGroupInstanceAction>{
+ type: VnfGroupActions.UPDATE_VNF_GROUP_INSTANCE,
+ vnfGroupInstance : new VnfGroupInstance(),
+ vnfGroupStoreKey : 'vnfGroupStoreKey',
+ vnfGroupModelName : 'vnfGroupModelName',
+ serviceUuid : 'serviceModelId'
+ }).serviceInstance['serviceModelId'].vnfGroups['vnfGroupStoreKey'];
+
+ expect(vnfGroupState).toBeDefined();
+ expect(vnfGroupState.isMissingData).toBeFalsy();
+ });
+
+ test('#DELETE_ACTION_VNF_GROUP_INSTANCE', () => {
+ let vnfGroupInstance: VnfGroupInstance = new VnfGroupInstance();
+ vnfGroupInstance.isMissingData = false;
+ vnfGroupInstance.instanceName = 'instanceName';
+ vnfGroupInstance.action = ServiceInstanceActions.None;
+ let vnfGroupState = vnfGroupReducer(<any>{serviceInstance : {
+ 'serviceModelId' : {
+ vnfGroups : {
+ 'vnfGroupStoreKey' : {
+ isMissingData : true,
+ action : 'None'
+ }
+ }
+ }
+ }},
+ <DeleteActionVnfGroupInstanceAction>{
+ type: VnfGroupActions.DELETE_ACTION_VNF_GROUP_INSTANCE,
+ vnfGroupStoreKey: 'vnfGroupStoreKey',
+ serviceId: 'serviceModelId'
+ }).serviceInstance['serviceModelId'].vnfGroups['vnfGroupStoreKey'];
+
+ expect(vnfGroupState).toBeDefined();
+ expect(vnfGroupState.action).toEqual(ServiceInstanceActions.None_Delete);
+ });
+
+ test('#UNDO_DELETE_ACTION_VNF_GROUP_INSTANCE', () => {
+ let vnfGroupInstance: VnfGroupInstance = new VnfGroupInstance();
+ vnfGroupInstance.isMissingData = false;
+ vnfGroupInstance.instanceName = 'instanceName';
+ vnfGroupInstance.action = ServiceInstanceActions.None_Delete;
+ let vnfGroupState = vnfGroupReducer(<any>{serviceInstance : {
+ 'serviceModelId' : {
+ vnfGroups : {
+ 'vnfGroupStoreKey' : {
+ isMissingData : true,
+ action : 'None_Delete'
+ }
+ }
+ }
+ }},
+ <DeleteActionVnfGroupInstanceAction>{
+ type: VnfGroupActions.UNDO_DELETE_ACTION_VNF_GROUP_INSTANCE,
+ vnfGroupStoreKey: 'vnfGroupStoreKey',
+ serviceId: 'serviceModelId'
+ }).serviceInstance['serviceModelId'].vnfGroups['vnfGroupStoreKey'];
+
+ expect(vnfGroupState).toBeDefined();
+ expect(vnfGroupState.action).toEqual(ServiceInstanceActions.None);
+ });
+
+ test('#SET_OPTIONAL_MEMBERS_VNF_GROUP_INSTANCE', () => {
+ let vnf1: VnfMember = new VnfMember();
+ vnf1.serviceInstanceId = 'aa';
+ vnf1.instanceId = 'aaa';
+ let vnf2: VnfMember = new VnfMember();
+ vnf2.serviceInstanceId = 'bb';
+ vnf2.instanceId = 'bbb';
+ let optionalGroupMembersMap = vnfGroupReducer(<any>{
+ serviceInstance: {
+ 'serviceModelId': {
+ optionalGroupMembersMap : {}
+ }
+ }
+ },
+ <SetOptionalMembersVnfGroupInstanceAction>{
+ type: VnfGroupActions.SET_OPTIONAL_MEMBERS_VNF_GROUP_INSTANCE,
+ path: 'path1',
+ serviceId: 'serviceModelId',
+ vnfMembers: [vnf1, vnf2]
+ }).serviceInstance['serviceModelId'].optionalGroupMembersMap;
+
+ optionalGroupMembersMap['path1']= [vnf1, vnf2];
+ expect(optionalGroupMembersMap).toEqual({'path1':[vnf1, vnf2]});
+ });
+});
+
+
+
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts
new file mode 100644
index 000000000..2923c09b2
--- /dev/null
+++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vnfGroup/vnfGroup.reducers.ts
@@ -0,0 +1,108 @@
+import {Action} from "redux";
+import {VnfGroupInstance} from "../../../models/vnfGroupInstance";
+import * as _ from "lodash";
+import {ServiceInstance} from "../../../models/serviceInstance";
+import {ServiceState} from "../main.reducer";
+import {
+ CreateVnfGroupInstanceAction,
+ DeleteActionVnfGroupInstanceAction, SetOptionalMembersVnfGroupInstanceAction,
+ UpdateVnfGroupInstanceAction,
+ VnfGroupActions
+} from "./vnfGroup.actions";
+import {ServiceInstanceActions} from "../../../models/serviceInstanceActions";
+
+export function vnfGroupReducer(state: ServiceState, action: Action): ServiceState {
+ switch (action.type) {
+ case VnfGroupActions.CREATE_VNF_GROUP_INSTANCE: {
+ const updateVnfGroupInstanceAction = <CreateVnfGroupInstanceAction>action;
+ const serviceUuid = updateVnfGroupInstanceAction.serviceUuid;
+ let vnfGroupModelName = updateVnfGroupInstanceAction.vnfGroupModelName;
+ let newState = _.cloneDeep(state);
+
+ updateVnfGroupInstanceAction.vnfGroupInstance.originalName = vnfGroupModelName;
+ updateVnfGroupInstanceAction.vnfGroupModelName = calculateNextUniqueModelName(vnfGroupModelName, serviceUuid, newState, 'vnfGroups');
+
+ let vnfGroupInstance: VnfGroupInstance = newState.serviceInstance[serviceUuid].vnfGroups[vnfGroupModelName];
+ vnfGroupInstance = new VnfGroupInstance();
+ updateVnfGroupInstanceAction.vnfGroupInstance.vnfGroupStoreKey = updateVnfGroupInstanceAction.vnfGroupModelName;
+ updateVnfGroupInstanceAction.vnfGroupInstance.originalName = vnfGroupModelName;
+ vnfGroupInstance.originalName = updateVnfGroupInstanceAction.vnfGroupInstance.originalName;
+ vnfGroupInstance.vnfGroupStoreKey = updateVnfGroupInstanceAction.vnfGroupInstance.vnfGroupStoreKey;
+ updateServiceValidationCounter(newState, vnfGroupInstance['isMissingData'], updateVnfGroupInstanceAction.vnfGroupInstance['isMissingData'], serviceUuid);
+
+ newState.serviceInstance[serviceUuid].vnfGroups[updateVnfGroupInstanceAction.vnfGroupModelName] = Object.assign(vnfGroupInstance, updateVnfGroupInstanceAction.vnfGroupInstance);
+ return newState;
+ }
+ case VnfGroupActions.UPDATE_VNF_GROUP_INSTANCE: {
+ const updateVnfInstanceAction = <UpdateVnfGroupInstanceAction>action;
+ const serviceUuid = updateVnfInstanceAction.serviceUuid;
+ let vnfGroupStoreKey = updateVnfInstanceAction.vnfGroupStoreKey;
+
+
+ let newState = _.cloneDeep(state);
+ let vnfGroupInstance: VnfGroupInstance = newState.serviceInstance[serviceUuid].vnfGroups[vnfGroupStoreKey];
+ updateUniqueNames(vnfGroupInstance ? vnfGroupInstance.instanceName : null, updateVnfInstanceAction.vnfGroupInstance.instanceName, newState.serviceInstance[serviceUuid]);
+
+ vnfGroupInstance = vnfGroupInstance || new VnfGroupInstance();
+ updateServiceValidationCounter(newState, vnfGroupInstance['isMissingData'], updateVnfInstanceAction.vnfGroupInstance['isMissingData'], serviceUuid);
+
+ newState.serviceInstance[serviceUuid].vnfGroups[vnfGroupStoreKey] = Object.assign(vnfGroupInstance, updateVnfInstanceAction.vnfGroupInstance);
+ return newState;
+ }
+ case VnfGroupActions.DELETE_ACTION_VNF_GROUP_INSTANCE : {
+ let newState = _.cloneDeep(state);
+ let oldAction = newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action;
+ if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState;
+ newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action = (oldAction + '_Delete') as ServiceInstanceActions;
+ return newState;
+ }
+ case VnfGroupActions.UNDO_DELETE_ACTION_VNF_GROUP_INSTANCE : {
+ let newState = _.cloneDeep(state);
+ let oldState = newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action;
+ newState.serviceInstance[(<DeleteActionVnfGroupInstanceAction>action).serviceId].vnfGroups[(<DeleteActionVnfGroupInstanceAction>action).vnfGroupStoreKey].action = (oldState.split('_')[0]) as ServiceInstanceActions;
+ return newState;
+ }
+ case VnfGroupActions.SET_OPTIONAL_MEMBERS_VNF_GROUP_INSTANCE:{
+ let newState = _.cloneDeep(state);
+ newState.serviceInstance[(<SetOptionalMembersVnfGroupInstanceAction>action).serviceId].optionalGroupMembersMap[(<SetOptionalMembersVnfGroupInstanceAction>action).path] = (<SetOptionalMembersVnfGroupInstanceAction>action).vnfMembers;
+ return newState;
+ }
+ }
+}
+
+const updateServiceValidationCounter = (newState: any, oldValidationState: boolean, newValidationState: boolean, serviceUuid: string) => {
+ if (oldValidationState && !newValidationState) {
+ newState.serviceInstance[serviceUuid].validationCounter--;
+ } else if (!oldValidationState && newValidationState) {
+ newState.serviceInstance[serviceUuid].validationCounter++;
+ }
+};
+
+
+const updateUniqueNames = (oldName: string, newName: string, serviceInstance: ServiceInstance): void => {
+ let existingNames = serviceInstance.existingNames;
+ if (!_.isNil(oldName) && oldName.toLowerCase() in existingNames) {
+ delete existingNames[oldName.toLowerCase()];
+ }
+ if (!_.isNil(newName)) {
+ existingNames[newName.toLowerCase()] = "";
+ }
+};
+
+
+export const calculateNextUniqueModelName = (vnfGroupModelName: string, serviceId: string, state: any, levelName: string): string => {
+ let counter: number = null;
+ while (true) {
+ let pattern = !_.isNil(counter) ? ("_" + counter) : "";
+ if (!_.isNil(state.serviceInstance[serviceId][levelName][vnfGroupModelName + pattern])) {
+ counter = counter ? (counter + 1) : 1;
+ } else {
+ return vnfGroupModelName + pattern;
+ }
+ }
+};
+
+
+
+
+