diff options
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/vrf')
3 files changed, 326 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.actions.ts new file mode 100644 index 000000000..a95a266c1 --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.actions.ts @@ -0,0 +1,84 @@ +import {Action, ActionCreator} from "redux"; + +export enum VrfActions { + CREATE_VRF_INSTANCE = "CREATE_VRF_INSTANCE", + EDIT_VRF_INSTANCE = "EDIT_VRF_INSTANCE", + DELETE_VRF_INSTANCE = "DELETE_VRF_INSTANCE", + VRF_ASSOCIATE_MEMBER = "VRF_ASSOCIATE_MEMBER", + CLAER_ASSOCIATE__VRF_MEMBERS = "CLAER_ASSOCIATE__VRF_MEMBERS", + DELETE_ACTION_VRF_INSTANCE = "DELETE_ACTION_VRF_INSTANCE", + UNDO_DELETE_ACTION_VRF_INSTANCE = "UNDO_DELETE_ACTION_VRF_INSTANCE" +} + + +export interface CreateVRFInstanceAction extends Action { + vrfModel : any; + serviceModelId : string; + vrfStoreKey : string; +} + +export interface AssociateVRFMemberInstanceAction extends Action { + vrfStoreKey : string; + serviceModelId : string; + memberType : string; + member : any; +} + +export interface ClearAssociateVRFMemberInstanceAction extends Action { + vrfStoreKey : string; + serviceModelId : string; + memberType : string; +} + +export interface DeleteActionVrfInstanceAction extends Action { + vrfStoreKey : string; + serviceId : string; +} + +export interface UndoDeleteActionVrfInstanceAction extends Action { + vrfStoreKey: string; + serviceId?: string; +} + +export const createVrfInstance: ActionCreator<CreateVRFInstanceAction> = (vrfModel, serviceModelId, vrfStoreKey) => ({ + type: VrfActions.CREATE_VRF_INSTANCE, + vrfModel : vrfModel, + serviceModelId : serviceModelId, + vrfStoreKey : vrfStoreKey +}); + + +export const associateVRFMember: ActionCreator<AssociateVRFMemberInstanceAction> = (vrfStoreKey, serviceModelId, member, memberType) => ({ + type: VrfActions.VRF_ASSOCIATE_MEMBER, + vrfStoreKey : vrfStoreKey, + serviceModelId : serviceModelId, + member : member, + memberType : memberType +}); + +export const clearAssociateVRFMemberInstance: ActionCreator<ClearAssociateVRFMemberInstanceAction> = (vrfStoreKey, serviceModelId, memberType) => ({ + type: VrfActions.CLAER_ASSOCIATE__VRF_MEMBERS, + vrfStoreKey : vrfStoreKey, + serviceModelId : serviceModelId, + memberType : memberType +}); + +export const deleteActionVrfInstance: ActionCreator<DeleteActionVrfInstanceAction> = (vrfStoreKey, serviceId) => ({ + type: VrfActions.DELETE_ACTION_VRF_INSTANCE, + vrfStoreKey : vrfStoreKey, + serviceId : serviceId +}); + +export const undoDeleteActionVrfInstance: ActionCreator<UndoDeleteActionVrfInstanceAction> = (vrfStoreKey, serviceId) => ({ + type: VrfActions.UNDO_DELETE_ACTION_VRF_INSTANCE, + vrfStoreKey: vrfStoreKey, + serviceId: serviceId +}); + + + + + + + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.spec.ts new file mode 100644 index 000000000..607fa057d --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.spec.ts @@ -0,0 +1,152 @@ +import {vrfReducer} from "./vrf.reducer"; +import { + AssociateVRFMemberInstanceAction, + ClearAssociateVRFMemberInstanceAction, + CreateVRFInstanceAction, DeleteActionVrfInstanceAction, UndoDeleteActionVrfInstanceAction, + VrfActions +} from "./vrf.actions"; +import {vnfReducer} from "../vnf/vnf.reducers"; +import {DeleteActionVnfInstanceAction, UndoDeleteActionVnfInstanceAction, VNFActions} from "../vnf/vnf.actions"; +import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; + + +describe('vrfReducer', () => { + test('#VRF_ASSOCIATE_MEMBER ', () => { + + const serviceModelId: string = 'serviceModelID'; + const vrfStoreKey : string = 'vrfStoreKey'; + const memberType : string = 'networks'; + const member = {a : 1 , b : 2}; + let vrfState = vrfReducer(<any>{ + serviceInstance : { + [serviceModelId] : { + vrfs : { + [vrfStoreKey] : { + [memberType] : { + + } + } + + } + } + }}, + <AssociateVRFMemberInstanceAction>{ + type: VrfActions.VRF_ASSOCIATE_MEMBER, + vrfStoreKey : vrfStoreKey, + serviceModelId : serviceModelId, + memberType : memberType, + member : member + }); + + expect(vrfState).toBeDefined(); + expect(vrfState.serviceInstance[serviceModelId].vrfs[vrfStoreKey][memberType][`${vrfStoreKey} ${memberType} 1`]).toBeDefined(); + expect(vrfState.serviceInstance[serviceModelId].vrfs[vrfStoreKey][memberType][`${vrfStoreKey} ${memberType} 1`]).toEqual(member); + }); + + test('#CLAER_ASSOCIATE__VRF_MEMBERS ', () => { + + const serviceModelId: string = 'serviceModelID'; + const vrfStoreKey : string = 'vrfStoreKey'; + const memberType : string = 'networks'; + let vrfState = vrfReducer(<any>{ + serviceInstance : { + [serviceModelId] : { + vrfs : { + [vrfStoreKey] : { + [memberType] : { + a : 1, + b : 2 + } + } + + } + } + }}, + <ClearAssociateVRFMemberInstanceAction>{ + type: VrfActions.CLAER_ASSOCIATE__VRF_MEMBERS, + vrfStoreKey : vrfStoreKey, + serviceModelId : serviceModelId, + memberType : memberType + }).serviceInstance[serviceModelId].vrfs[vrfStoreKey]; + + expect(vrfState).toBeDefined(); + expect(vrfState[memberType]).toBeDefined(); + expect(vrfState[memberType]).toEqual({}); + }); + + test('#CREATE_VRF_INSTANCE ', () => { + + const serviceModelId: string = 'serviceModelID'; + const vrfStoreKey : string = 'vrfStoreKey'; + const vrfModelName : string = 'vrfModelName'; + const memberType : string = 'networks'; + let vrfState = vrfReducer(<any>{ + serviceInstance : { + [serviceModelId] : { + vrfs : { + [vrfStoreKey] : { + [memberType] : { + + } + } + + } + } + }}, + <CreateVRFInstanceAction>{ + type: VrfActions.CREATE_VRF_INSTANCE, + vrfModel : { + name : vrfModelName + }, + serviceModelId : serviceModelId, + vrfStoreKey : vrfStoreKey + }).serviceInstance[serviceModelId].vrfs; + + expect(vrfState).toBeDefined(); + expect(vrfState[vrfModelName]).toBeDefined(); + }); + + test('#DELETE_ACTION_VRF_INSTANCE', () => { + let vnfState = vrfReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vrfs : { + 'vrfStoreKey' : { + isMissingData : true, + action : 'None' + } + } + } + }}, + <DeleteActionVrfInstanceAction>{ + type: VrfActions.DELETE_ACTION_VRF_INSTANCE, + vrfStoreKey: 'vrfStoreKey', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].vrfs['vrfStoreKey']; + + expect(vnfState).toBeDefined(); + expect(vnfState.action).toEqual(ServiceInstanceActions.None_Delete); + }); + + test('#UNDO_DELETE_ACTION_VRF_INSTANCE', () => { + let vnfState = vrfReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vrfs : { + 'vrfStoreKey' : { + isMissingData : true, + action : 'Update_Delete' + } + } + } + }}, + <UndoDeleteActionVrfInstanceAction>{ + type: VrfActions.UNDO_DELETE_ACTION_VRF_INSTANCE, + vrfStoreKey: 'vrfStoreKey', + serviceId: 'serviceModelId' + }).serviceInstance['serviceModelId'].vrfs['vrfStoreKey']; + + expect(vnfState).toBeDefined(); + expect(vnfState.action).toEqual(ServiceInstanceActions.Update); + }); +}); + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.ts new file mode 100644 index 000000000..f3d81209e --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/vrf/vrf.reducer.ts @@ -0,0 +1,90 @@ +import {ServiceState} from "../main.reducer"; +import {Action} from "redux"; +import * as _ from "lodash"; +import { + AssociateVRFMemberInstanceAction, + ClearAssociateVRFMemberInstanceAction, + CreateVRFInstanceAction, DeleteActionVrfInstanceAction, UndoDeleteActionVrfInstanceAction, + VrfActions +} from "./vrf.actions"; +import {calculateNextUniqueModelName} from "../vnf/vnf.reducers"; +import {ServiceInstanceActions} from "../../../models/serviceInstanceActions"; + +export function vrfReducer(state: ServiceState, action: Action): ServiceState { + switch (action.type) { + case VrfActions.CREATE_VRF_INSTANCE: { + const createVRFInstanceAction = <CreateVRFInstanceAction>action; + const serviceUuid = createVRFInstanceAction.serviceModelId; + + let newState = _.cloneDeep(state); + + const vrfModelName = calculateNextUniqueModelName(createVRFInstanceAction.vrfModel['name'], serviceUuid, newState, 'vrfs'); + newState.serviceInstance[serviceUuid].vrfs[vrfModelName] = <any>{ + ...createVRFInstanceAction.vrfModel + }; + return newState; + } + case VrfActions.VRF_ASSOCIATE_MEMBER: { + const associateVRFMemberInstanceAction = <AssociateVRFMemberInstanceAction>action; + const serviceUuid = associateVRFMemberInstanceAction.serviceModelId; + const member = associateVRFMemberInstanceAction.member; + const vrfStoreKey = associateVRFMemberInstanceAction.vrfStoreKey; + const memberType = associateVRFMemberInstanceAction.memberType; + + let newState = _.cloneDeep(state); + + if(_.isNil(newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType])){ + newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType] = {}; + } + + const numberOfKeys = Object.keys(newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType]).length; + newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType][`${vrfStoreKey} ${memberType} ${numberOfKeys+1}`] = member; + + return newState; + } + case VrfActions.VRF_ASSOCIATE_MEMBER: { + const associateVRFMemberInstanceAction = <AssociateVRFMemberInstanceAction>action; + const serviceUuid = associateVRFMemberInstanceAction.serviceModelId; + const member = associateVRFMemberInstanceAction.member; + const vrfStoreKey = associateVRFMemberInstanceAction.vrfStoreKey; + const memberType = associateVRFMemberInstanceAction.memberType; + + let newState = _.cloneDeep(state); + + if(_.isNil(newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType])){ + newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType] = {}; + } + + const numberOfKeys = Object.keys(newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType]).length; + newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType][`${vrfStoreKey} ${memberType} ${numberOfKeys+1}`] = member; + + return newState; + } + case VrfActions.CLAER_ASSOCIATE__VRF_MEMBERS: { + const clearAssociateVRFMemberInstanceAction = <ClearAssociateVRFMemberInstanceAction>action; + const serviceUuid = clearAssociateVRFMemberInstanceAction.serviceModelId; + const vrfStoreKey = clearAssociateVRFMemberInstanceAction.vrfStoreKey; + const memberType = clearAssociateVRFMemberInstanceAction.memberType; + + let newState = _.cloneDeep(state); + newState.serviceInstance[serviceUuid].vrfs[vrfStoreKey][memberType] = {}; + return newState; + } + case VrfActions.DELETE_ACTION_VRF_INSTANCE : { + let newState = _.cloneDeep(state); + let vrf = newState.serviceInstance[(<DeleteActionVrfInstanceAction>action).serviceId].vrfs[(<DeleteActionVrfInstanceAction>action).vrfStoreKey]; + let oldAction = vrf.action; + if(oldAction === ServiceInstanceActions.None_Delete || oldAction === ServiceInstanceActions.Update_Delete) return newState; + newState.serviceInstance[(<DeleteActionVrfInstanceAction>action).serviceId].vrfs[(<DeleteActionVrfInstanceAction>action).vrfStoreKey].action = (oldAction + '_Delete') as ServiceInstanceActions; + return newState; + } + + case VrfActions.UNDO_DELETE_ACTION_VRF_INSTANCE : { + let newState = _.cloneDeep(state); + let vnf = newState.serviceInstance[(<UndoDeleteActionVrfInstanceAction>action).serviceId].vrfs[(<UndoDeleteActionVrfInstanceAction>action).vrfStoreKey]; + let oldState = vnf.action; + newState.serviceInstance[(<UndoDeleteActionVrfInstanceAction>action).serviceId].vrfs[(<UndoDeleteActionVrfInstanceAction>action).vrfStoreKey].action = (oldState.split('_')[0]) as ServiceInstanceActions; + return newState; + } + } +} |