diff options
Diffstat (limited to 'vid-webpack-master/src/app/shared/storeUtil/utils/general')
4 files changed, 830 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.action.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.action.spec.ts new file mode 100644 index 000000000..a65249a3b --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.action.spec.ts @@ -0,0 +1,157 @@ +import { + GeneralActions, UpdateAicZonesAction, + UpdateLcpRegionsAndTenantsAction, + UpdateProductFamiliesAction, + UpdateSubscribersAction, UpdateUserIdAction +} from "./general.actions"; +import {SelectOption} from "../../../models/selectOption"; + + +describe('general actions', () => { + test('#UPDATE_LCP_REGIONS_AND_TENANTS : action', () => { + const action: UpdateLcpRegionsAndTenantsAction = <UpdateLcpRegionsAndTenantsAction>{ + type: GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS, + lcpRegionsAndTenants: { + "lcpRegionList": [], + "lcpRegionsTenantsMap": {} + } + }; + + expect(action.type).toEqual(GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS); + expect(action.lcpRegionsAndTenants.lcpRegionList).toEqual([]); + expect(action.lcpRegionsAndTenants.lcpRegionsTenantsMap).toEqual({}); + }); + + test('#UPDATE_SUBSCRIBERS : action', () => { + const action: UpdateSubscribersAction = <UpdateSubscribersAction>{ + type: GeneralActions.UPDATE_SUBSCRIBERS, + subscribers: [ + { + "id": "ERICA5779-Subscriber-2", + "name": "ERICA5779-Subscriber-2", + "isPermitted": false + }, + { + "id": "ERICA5779-Subscriber-3", + "name": "ERICA5779-Subscriber-3", + "isPermitted": false + }, + { + "id": "ERICA5779-Subscriber-4", + "name": "ERICA5779-Subscriber-5", + "isPermitted": false + }, + { + "id": "ERICA5779-TestSub-PWT-101", + "name": "ERICA5779-TestSub-PWT-101", + "isPermitted": false + }, + { + "id": "ERICA5779-TestSub-PWT-102", + "name": "ERICA5779-TestSub-PWT-102", + "isPermitted": false + }, + { + "id": "ERICA5779-TestSub-PWT-103", + "name": "ERICA5779-TestSub-PWT-103", + "isPermitted": false + }, + { + "id": "31739f3e-526b-11e6-beb8-9e71128cae77", + "name": "CRAIG/ROBERTS", + "isPermitted": false + }, + { + "id": "DHV1707-TestSubscriber-2", + "name": "DALE BRIDGES", + "isPermitted": false + }, + { + "id": "jimmy-example", + "name": "JimmyExampleCust-20161102", + "isPermitted": false + }, + { + "id": "jimmy-example2", + "name": "JimmyExampleCust-20161103", + "isPermitted": false + }, + { + "id": "CAR_2020_ER", + "name": "CAR_2020_ER", + "isPermitted": true + }, + { + "id": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "name": "Emanuel", + "isPermitted": false + }, + { + "id": "21014aa2-526b-11e6-beb8-9e71128cae77", + "name": "JULIO ERICKSON", + "isPermitted": false + }, + { + "id": "DHV1707-TestSubscriber-1", + "name": "LLOYD BRIDGES", + "isPermitted": false + }, + { + "id": "e433710f-9217-458d-a79d-1c7aff376d89", + "name": "SILVIA ROBBINS", + "isPermitted": true + } + ] + }; + + expect(action.type).toEqual(GeneralActions.UPDATE_SUBSCRIBERS); + expect(action.subscribers).toHaveLength(15); + }); + + test('#UPDATE_PRODUCT_FAMILIES : action', () => { + const action: UpdateProductFamiliesAction = <UpdateProductFamiliesAction>{ + type: GeneralActions.UPDATE_PRODUCT_FAMILIES, + productFamilies: [ + new SelectOption({ + id : 'id', + name : 'name', + isPermitted : false + }) + ] + }; + + expect(action.type).toEqual(GeneralActions.UPDATE_PRODUCT_FAMILIES); + expect(action.productFamilies).toHaveLength(1); + }); + + + test('#UpdateAicZonesAction : action', () => { + const action: UpdateAicZonesAction = <UpdateAicZonesAction>{ + type: GeneralActions.UPDATE_AIC_ZONES, + aicZones: [ + new SelectOption({ + id : 'id', + name : 'name', + isPermitted : false + }) + ] + }; + + expect(action.type).toEqual(GeneralActions.UPDATE_AIC_ZONES); + expect(action.aicZones).toHaveLength(1); + }); + + test('#UpdateUserIdAction : action', () => { + const action: UpdateUserIdAction = <UpdateUserIdAction>{ + type: GeneralActions.UPDATE_USER_ID, + userId: "userId" + }; + + expect(action.type).toEqual(GeneralActions.UPDATE_USER_ID); + expect(action.userId).toBe("userId"); + }); + +}); + + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts new file mode 100644 index 000000000..7a10eba0a --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.actions.ts @@ -0,0 +1,150 @@ +import {Action, ActionCreator} from "redux"; +import {LcpRegionsAndTenants} from "../../../models/lcpRegionsAndTenants"; +import {SelectOptionInterface} from "../../../models/selectOption"; +import {ServiceType} from "../../../models/serviceType"; +import {ITreeNode} from "angular-tree-component/dist/defs/api"; + +export enum GeneralActions { + UPDATE_LCP_REGIONS_AND_TENANTS = "UPDATE_LCP_REGIONS_AND_TENANTS", + UPDATE_SUBSCRIBERS = "UPDATE_SUBSCRIBERS", + UPDATE_PRODUCT_FAMILIES = "UPDATE_PRODUCT_FAMILIES", + UPDATE_SERVICE_TYPES = "UPDATE_SERVICE_TYPES", + UPDATE_AIC_ZONES = "UPDATE_AIC_ZONES", + UPDATE_USER_ID = "UPDATE_USER_ID", + UPDATE_NETWORK_FUNCTION = "UPDATE_NETWORK_FUNCTION", + UPDATE_CATEGORY_PARAMETERS = "UPDATE_CATEGORY_PARAMETERS", + REMOVE_INSTANCE = 'REMOVE_INSTANCE', + CHANGE_INSTANCE_COUNTER = 'CHANGE_INSTANCE_COUNTER', + DUPLICATE_BULK_INSTANCES = 'DUPLICATE_BULK_INSTANCES' +} +export interface UpdateLcpRegionsAndTenantsAction extends Action { + lcpRegionsAndTenants?: LcpRegionsAndTenants; +} + +export interface RemoveInstanceAction extends Action { + modelName?: string; + serviceModelId: string; + storeKey : string; + node : ITreeNode; +} + +export interface UpdateSubscribersAction extends Action { + subscribers?: SelectOptionInterface[]; +} + +export interface UpdateProductFamiliesAction extends Action { + productFamilies?: SelectOptionInterface[]; +} + +export interface UpdateAicZonesAction extends Action { + aicZones?: SelectOptionInterface[]; +} + +export interface UpdateServiceTypesAction extends Action { + serviceTypes?: ServiceType[]; + subscriberId: string; +} +export interface UpdateUserIdAction extends Action { + userId: string; +} + +export interface UpdateNetworkCollectionFunction extends Action { + networksAccordingToNetworkCollection: any; + network_function: any; +} + +export interface UpdateCategoryParametersAction extends Action { + categoryParameters?: Object; +} + +export interface ChangeInstanceCounterAction extends Action{ + serviceUUID : string; + UUID : string; + changeBy : number; + node : ITreeNode; +} + +export interface DuplicateBulkInstancesAction extends Action { + serviceId?: string; + modelName?: string; + originalName? : string; + objects? : {}; + existingNames: {[key: string] : any}; + node : ITreeNode; +} + +export interface UpdateServiceTypesAction extends Action { + serviceTypes?: ServiceType[]; + subscriberId: string; +} + +export const updateLcpRegionsAndTenants: ActionCreator<UpdateLcpRegionsAndTenantsAction> = lcpRegionsAndTenants => ({ + type: GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS, + lcpRegionsAndTenants: lcpRegionsAndTenants +}); + +export const updateSubscribers: ActionCreator<UpdateSubscribersAction> = subscribers => ({ + type: GeneralActions.UPDATE_SUBSCRIBERS, + subscribers: subscribers +}); + +export const updateProductFamilies: ActionCreator<UpdateProductFamiliesAction> = productFamilies => ({ + type: GeneralActions.UPDATE_PRODUCT_FAMILIES, + productFamilies: productFamilies +}); + +export const updateAicZones: ActionCreator<UpdateAicZonesAction> = aicZones => ({ + type: GeneralActions.UPDATE_AIC_ZONES, + aicZones: aicZones +}); + +export const updateUserId: ActionCreator<UpdateUserIdAction> = userId => ({ + type: GeneralActions.UPDATE_USER_ID, + userId: userId +}); + +export const updateNetworkCollectionFunction: ActionCreator<UpdateNetworkCollectionFunction> = (ncf, networksAccordingToNetworkCollection) => ({ + type: GeneralActions.UPDATE_NETWORK_FUNCTION, + networksAccordingToNetworkCollection: networksAccordingToNetworkCollection["results"], + network_function: ncf +}); + +export const updateCategoryParameters: ActionCreator<UpdateCategoryParametersAction> = categoryParameters => ({ + type: GeneralActions.UPDATE_CATEGORY_PARAMETERS, + categoryParameters: categoryParameters +}); + +export const removeInstance: ActionCreator<RemoveInstanceAction> = (modelName, serviceModelId, storeKey, node : ITreeNode) => ({ + type: GeneralActions.REMOVE_INSTANCE, + modelName: modelName, + serviceModelId: serviceModelId, + storeKey: storeKey, + node : node +}); + + +export const changeInstanceCounter: ActionCreator<ChangeInstanceCounterAction> = (UUID, serviceUUID , changeBy, node) => ({ + type: GeneralActions.CHANGE_INSTANCE_COUNTER, + UUID: UUID, + serviceUUID: serviceUUID, + changeBy : changeBy || 1, + node : node +}); + + +export const duplicateBulkInstances: ActionCreator<DuplicateBulkInstancesAction> = (serviceId, objects, existingNames, node) => ({ + type: GeneralActions.DUPLICATE_BULK_INSTANCES, + serviceId: serviceId, + objects : objects, + existingNames: existingNames, + node : node +}); + + +export const updateServiceTypes: ActionCreator<UpdateServiceTypesAction> = (serviceTypes, subscriberId) => ({ + type: GeneralActions.UPDATE_SERVICE_TYPES, + serviceTypes: serviceTypes, + subscriberId: subscriberId +}); + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts new file mode 100644 index 000000000..ed456314e --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.spec.ts @@ -0,0 +1,376 @@ +import {LcpRegion} from "../../../models/lcpRegion"; +import {Tenant} from "../../../models/tenant"; +import {generalReducer} from "./general.reducers"; +import { + ChangeInstanceCounterAction, + RemoveInstanceAction, + DuplicateBulkInstancesAction, + GeneralActions, + UpdateAicZonesAction, + UpdateCategoryParametersAction, + UpdateProductFamiliesAction, + UpdateServiceTypesAction, + UpdateSubscribersAction, + UpdateUserIdAction, UpdateNetworkCollectionFunction, +} from "./general.actions"; +import {SelectOption} from "../../../models/selectOption"; +import {ServiceType} from "../../../models/serviceType"; +import {ITreeNode} from "angular-tree-component/dist/defs/api"; +import {VnfInstance} from "../../../models/vnfInstance"; + +describe('generalReducer', () => { + test('#UPDATE_LCP_REGIONS_AND_TENANTS : should update lcp region and tenants', () => { + let lcpRegionsAndTenantsObj = [ + { + lcpRegionList : [ + new LcpRegion( + 'cloudRegionID', + 'cloudRegionID (cloudOwner)', + true, + 'cloudOwner' + ) + ], + lcpRegionsTenantsMap : { + "lcpRegion" : [new Tenant({ + "tenantID" : "tenantID", + "tenantName" : "tenantName", + "is-permitted" : true + })] + } + } + ]; + let lcpRegionsAndTenantsState = generalReducer(<any>{serviceInstance : {}}, + <any>{ + type: GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS, + lcpRegionsAndTenants : lcpRegionsAndTenantsObj + })['lcpRegionsAndTenants']; + + expect(lcpRegionsAndTenantsState).toBeDefined(); + }); + + test('#UPDATE_SUBSCRIBERS : should update subscribers', () => { + let subscribersList = [ + new SelectOption({ + id : 'id', + name : 'name', + isPermitted : false + }) + ]; + let subscribersState = generalReducer(<any> + { + serviceInstance : {} + }, + <UpdateSubscribersAction>{ + type: GeneralActions.UPDATE_SUBSCRIBERS, + subscribers : subscribersList + })['subscribers']; + + expect(subscribersState).toBeDefined(); + expect(subscribersState[0].id).toEqual(subscribersList[0].id); + expect(subscribersState[0].isPermitted).toEqual(subscribersList[0].isPermitted); + expect(subscribersState[0].name).toEqual(subscribersList[0].name); + }); + + test('#UPDATE_PRODUCT_FAMILIES : should update product families', () => { + let productFamiliesObj = [ + new SelectOption({ + id : 'id', + name : 'name', + isPermitted : false + }) + ]; + let productFamiliesState = generalReducer(<any>{serviceInstance : {}}, + <UpdateProductFamiliesAction>{ + type: GeneralActions.UPDATE_PRODUCT_FAMILIES, + productFamilies : productFamiliesObj + })['productFamilies']; + + expect(productFamiliesState).toBeDefined(); + expect(productFamiliesState[0].id).toEqual(productFamiliesObj[0].id); + expect(productFamiliesState[0].isPermitted).toEqual(productFamiliesObj[0].isPermitted); + expect(productFamiliesState[0].name).toEqual(productFamiliesObj[0].name); + }); + + test('#UPDATE_AIC_ZONES : should update aic zones', () => { + let aicZonesObj = [ + new SelectOption({ + id : 'id', + name : 'name', + isPermitted : false + }) + ]; + let aicZonesState = generalReducer(<any>{serviceInstance : {}}, + <UpdateAicZonesAction>{ + type: GeneralActions.UPDATE_AIC_ZONES, + aicZones : aicZonesObj + })['aicZones']; + + expect(aicZonesState).toBeDefined(); + expect(aicZonesState[0].id).toEqual(aicZonesObj[0].id); + expect(aicZonesState[0].isPermitted).toEqual(aicZonesObj[0].isPermitted); + expect(aicZonesState[0].name).toEqual(aicZonesObj[0].name); + }); + + test('#UPDATE_SERVICE_TYPES : should update service types', () => { + const subscriberId = 'subscriberId'; + let serviceTypesList : ServiceType[] = [ + new ServiceType('id',{ + 'service-type' : 'name', + 'is-permitted' : true + }) + ]; + let serviceTypesState = generalReducer(<any> + { + serviceTypes : { + } + }, + <UpdateServiceTypesAction>{ + type: GeneralActions.UPDATE_SERVICE_TYPES, + subscriberId : subscriberId, + serviceTypes : serviceTypesList + })['serviceTypes'][subscriberId]; + + expect(serviceTypesState).toBeDefined(); + expect(serviceTypesState[0].id).toEqual(serviceTypesList[0].id); + expect(serviceTypesState[0].isPermitted).toEqual(serviceTypesList[0].isPermitted); + expect(serviceTypesState[0].name).toEqual(serviceTypesList[0].name); + }); + + test('#UPDATE_CATEGORY_PARAMETERS : should update category parameters', () => { + let list = [ + new SelectOption({ + id : 'id', + name : 'name', + isPermitted : false + }) + ]; + + const categoryParametersObj = { + owningEntityList : list, + projectList : list, + lineOfBusinessList : list, + platformList : list + }; + + let categoryParametersState = generalReducer(<any>{serviceInstance : {}}, + <UpdateCategoryParametersAction>{ + type: GeneralActions.UPDATE_CATEGORY_PARAMETERS, + categoryParameters : categoryParametersObj + })['categoryParameters']; + + expect(categoryParametersState).toBeDefined(); + expect(categoryParametersState['owningEntityList'][0].id).toEqual(list[0].id); + expect(categoryParametersState['owningEntityList'][0].isPermitted).toEqual(list[0].isPermitted); + expect(categoryParametersState['owningEntityList'][0].name).toEqual(list[0].name); + + expect(categoryParametersState['projectList'][0].id).toEqual(list[0].id); + expect(categoryParametersState['projectList'][0].isPermitted).toEqual(list[0].isPermitted); + expect(categoryParametersState['projectList'][0].name).toEqual(list[0].name); + + expect(categoryParametersState['lineOfBusinessList'][0].id).toEqual(list[0].id); + expect(categoryParametersState['lineOfBusinessList'][0].isPermitted).toEqual(list[0].isPermitted); + expect(categoryParametersState['lineOfBusinessList'][0].name).toEqual(list[0].name); + + expect(categoryParametersState['platformList'][0].id).toEqual(list[0].id); + expect(categoryParametersState['platformList'][0].isPermitted).toEqual(list[0].isPermitted); + expect(categoryParametersState['platformList'][0].name).toEqual(list[0].name); + }); + + test('#UPDATE_USER_ID : should update user id', () => { + const userId = 'userId'; + let userState = generalReducer(<any>{serviceInstance : {}}, + <UpdateUserIdAction>{ + type: GeneralActions.UPDATE_USER_ID, + userId : userId + })['userId']; + + expect(userState).toBeDefined(); + expect(userState).toEqual(userId); + }); + + test('#DELETE_VNF_INSTANCE : should delete existing vnf', () => { + let state = generalReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + 'modelName' : {} + } + } + }}, + <RemoveInstanceAction>{ + type: GeneralActions.REMOVE_INSTANCE, + modelName : 'modelName', + serviceModelId : 'serviceModelId', + storeKey : 'modelName', + node : { + data : { + type : 'VF' + } + } + }); + + expect(state).toBeDefined(); + expect(state.serviceInstance[ 'serviceModelId'].vnfs['modelName']).not.toBeDefined(); + }); + + test('#DELETE_VNF_INSTANCE : should delete existing network', () => { + let state = generalReducer(<any>{serviceInstance : { + 'serviceModelId' : { + 'networks' : { + 'modelName' : {} + } + } + }}, + <RemoveInstanceAction>{ + type: GeneralActions.REMOVE_INSTANCE, + modelName : 'modelName', + serviceModelId : 'serviceModelId', + storeKey : 'modelName', + node : { + data : { + type : 'VL' + } + } + }); + + expect(state).toBeDefined(); + expect(state.serviceInstance['serviceModelId'].networks['modelName']).not.toBeDefined(); + }); + + test('#CHANGE_VNF_INSTANCE_COUNTER : should init existingVNFCounterMap to 1', () => { + let state = generalReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + 'vnfName' : { } + }, + existingVNFCounterMap : { + + } + } + }}, + <ChangeInstanceCounterAction>{ + type: GeneralActions.CHANGE_INSTANCE_COUNTER, + serviceUUID : 'serviceModelId', + node : {data : {type : 'VF'}}, + UUID : 'vnfUUID', + changeBy : 1 + }); + + expect(state).toBeDefined(); + expect(state.serviceInstance['serviceModelId'].existingVNFCounterMap['vnfUUID']).toEqual(1); + }); + + test('#CHANGE_VNF_INSTANCE_COUNTER : should increase existingVNFCounterMap to 2 if VNF exist', () => { + let state = generalReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + 'vnfName' : { } + }, + existingVNFCounterMap : { + 'vnfUUID' : 1 + } + } + }}, + <ChangeInstanceCounterAction>{ + type: GeneralActions.CHANGE_INSTANCE_COUNTER, + serviceUUID : 'serviceModelId', + UUID : 'vnfUUID', + node : {data : {type : 'VF'}}, + changeBy : 1 + }); + + expect(state).toBeDefined(); + expect(state.serviceInstance['serviceModelId'].existingVNFCounterMap['vnfUUID']).toEqual(2); + }); + + test('#CHANGE_VNF_INSTANCE_COUNTER : should remove existingVNFCounterMap to 0 remove VNF', () => { + + let state = generalReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + 'vnfName' : { } + }, + existingVNFCounterMap : { + 'vnfUUID' : 1 + } + } + }}, + <ChangeInstanceCounterAction>{ + type: GeneralActions.CHANGE_INSTANCE_COUNTER, + serviceUUID : 'serviceModelId', + UUID : 'vnfUUID', + node : {data : {type : 'VF'}}, + changeBy : -1 + }); + + expect(state).toBeDefined(); + expect(state.serviceInstance['serviceModelId'].existingVNFCounterMap['vnfUUID']).toEqual(0); + }); + + test('#DUPLICATE_BULK_INSTANCES : should duplicate existing VNF/Network', ()=>{ + let existingNames = { + 'vnfOriginalName' : 1 + }; + + let vnfInstance: VnfInstance = new VnfInstance(); + vnfInstance.originalName = 'vnfOriginalName'; + vnfInstance.vnfStoreKey = 'vnfStoreKey'; + + let cloneObjects = { + 'vnfOriginalName' : vnfInstance, + 'vnfOriginalName:0001' : vnfInstance, + 'vnfOriginalName:0002' : vnfInstance, + 'vnfOriginalName:0003' : vnfInstance + }; + + let node : ITreeNode = <any>{ + data : { + serviceId : 'serviceModelId', + vnfStoreKey : 'vnfStoreKey', + type : 'VF' + } + }; + + let vnfsState = generalReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + }, + existingVNFCounterMap : {} + } + }}, + <DuplicateBulkInstancesAction>{ + type: GeneralActions.DUPLICATE_BULK_INSTANCES, + serviceId: 'serviceModelId', + modelName: 'modelName', + originalName : 'modelName', + objects : cloneObjects, + existingNames: existingNames, + node : node + }).serviceInstance['serviceModelId'].vnfs; + + expect(vnfsState).toBeDefined(); + expect(Object.keys(vnfsState).length).toEqual(4); + }); + + test('#UPDATE_NETWORK_FUNCTION : should update network functions', ()=>{ + let state = generalReducer(<any>{serviceInstance : { + 'serviceModelId' : { + vnfs : { + }, + existingVNFCounterMap : {} + } + }}, + <UpdateNetworkCollectionFunction>{ + type: GeneralActions.UPDATE_NETWORK_FUNCTION, + network_function : { + results : [] + }, + networksAccordingToNetworkCollection : "networksAccordingToNetworkCollection" + }); + + expect(state).toBeDefined(); + expect(state['networkFunctions']).toBeDefined(); + }); +}); + + + diff --git a/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts new file mode 100644 index 000000000..8ee47331f --- /dev/null +++ b/vid-webpack-master/src/app/shared/storeUtil/utils/general/general.reducers.ts @@ -0,0 +1,147 @@ +import {Action} from "redux"; +import { + ChangeInstanceCounterAction, RemoveInstanceAction, DuplicateBulkInstancesAction, + GeneralActions, + UpdateAicZonesAction, UpdateCategoryParametersAction, + UpdateLcpRegionsAndTenantsAction, UpdateNetworkCollectionFunction, + UpdateProductFamiliesAction, UpdateServiceTypesAction, + UpdateSubscribersAction, UpdateUserIdAction +} from "./general.actions"; +import {TypeNodeInformation} from "../../../../drawingBoard/service-planning/typeNodeInformation.model"; +import * as _ from "lodash"; +import {ITreeNode} from "angular-tree-component/dist/defs/api"; +import {ServiceInstance} from "../../../models/serviceInstance"; +import {ServiceState} from "../main.reducer"; + +export function generalReducer(state: ServiceState, action: Action) : ServiceState { + switch (action.type) { + case GeneralActions.UPDATE_LCP_REGIONS_AND_TENANTS: { + Object.assign(state, (<UpdateLcpRegionsAndTenantsAction>action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_SUBSCRIBERS: { + Object.assign(state, (<UpdateSubscribersAction>action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_AIC_ZONES: { + Object.assign(state, (<UpdateAicZonesAction>action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_PRODUCT_FAMILIES: { + Object.assign(state, (<UpdateProductFamiliesAction>action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_NETWORK_FUNCTION: { + const networkFunctionReduxObj = state['networkFunctions'] == undefined ? {} : state['networkFunctions']; + networkFunctionReduxObj[(<UpdateNetworkCollectionFunction>action).network_function] = (<UpdateNetworkCollectionFunction>action).networksAccordingToNetworkCollection; + Object.assign(state, {'networkFunctions': networkFunctionReduxObj}); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_SERVICE_TYPES: { + state.serviceTypes[(<UpdateServiceTypesAction>action).subscriberId] = (<UpdateServiceTypesAction>action).serviceTypes; + return Object.assign({}, state); + } + case GeneralActions.UPDATE_CATEGORY_PARAMETERS: { + Object.assign(state, (<UpdateCategoryParametersAction>action)); + return Object.assign({}, state); + } + case GeneralActions.UPDATE_USER_ID: { + const updateUserId: UpdateUserIdAction = <UpdateUserIdAction>action; + let newState = _.cloneDeep(state); + newState['userId'] = updateUserId.userId; + return newState; + } + case GeneralActions.REMOVE_INSTANCE: { + const actionData = (<RemoveInstanceAction>action); + if (state.serviceInstance[actionData.serviceModelId]) { + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(actionData.node); + updateIsMissingDataOnDelete(state, actionData.serviceModelId, actionData.storeKey, actionData.node); + updateUniqueNames(state.serviceInstance[actionData.serviceModelId][typeNodeInformation.hierarchyName][actionData.storeKey].instanceName, null, state.serviceInstance[actionData.serviceModelId]); + if(actionData.node.data.type === 'VF'){ + _.forOwn(state.serviceInstance[actionData.serviceModelId][typeNodeInformation.hierarchyName][actionData.storeKey].vfModules, (vfModuleMap) => { + _.forOwn(vfModuleMap, (vfModuleInstance) => { + updateUniqueNames(vfModuleInstance.instanceName, null, state.serviceInstance[actionData.serviceModelId]); + }) + }); + } + delete state.serviceInstance[actionData.serviceModelId][typeNodeInformation.hierarchyName][actionData.storeKey]; + } + return Object.assign({}, state); + } + + case GeneralActions.CHANGE_INSTANCE_COUNTER : { + const changeInstanceCounterAction = <ChangeInstanceCounterAction>action; + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(changeInstanceCounterAction.node); + let newState = _.cloneDeep(state); + + let existing: number = getExistingCounter(newState, changeInstanceCounterAction.serviceUUID, changeInstanceCounterAction.UUID, typeNodeInformation); + newState.serviceInstance[changeInstanceCounterAction.serviceUUID][typeNodeInformation.existingMappingCounterName][changeInstanceCounterAction.UUID] = existing ? existing + changeInstanceCounterAction.changeBy : changeInstanceCounterAction.changeBy; + return newState; + } + + case GeneralActions.DUPLICATE_BULK_INSTANCES : { + const createInstanceAction = <DuplicateBulkInstancesAction>action; + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(createInstanceAction.node); + const serviceId = createInstanceAction.serviceId; + const objects = createInstanceAction.objects; + + let newState = _.cloneDeep(state); + newState.serviceInstance[serviceId].existingNames = createInstanceAction.existingNames; + newState.serviceInstance[serviceId][typeNodeInformation.hierarchyName] = Object.assign({}, newState.serviceInstance[serviceId][typeNodeInformation.hierarchyName], objects); + return newState; + } + } +} + +const getExistingCounter = (state: any, serviceModelId: string, modelId: string, typeNodeInformation : TypeNodeInformation ) : number => { + const serviceExistingCounterMap = state.serviceInstance[serviceModelId][typeNodeInformation.existingMappingCounterName]; + if(serviceExistingCounterMap && !_.isNil(serviceExistingCounterMap[modelId])){ + return serviceExistingCounterMap[modelId]; + }else { + return null; + } +}; + +const updateIsMissingDataOnDelete = (state: any, serviceModelId: string, storeKey: string, node: ITreeNode): void => { + const typeNodeInformation : TypeNodeInformation = new TypeNodeInformation(node); + let vnf = state.serviceInstance[serviceModelId][typeNodeInformation.hierarchyName][storeKey]; + if(node.children){ + _.forOwn(vnf.vfModules, (vfModules, vfModulesKey) => { + updateIsMissingDataOnDeleteVFModule(state, serviceModelId, storeKey, vfModulesKey); + }); + } + + + let isMissingData: boolean = state.serviceInstance[serviceModelId][typeNodeInformation.hierarchyName][storeKey].isMissingData; + updateServiceValidationCounter(state, isMissingData, false, serviceModelId); +}; + +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()] = ""; + } +}; + +const updateIsMissingDataOnDeleteVFModule = (state: any, serviceModelId: string, vnfStoreKey: string, vfModuleName): void => { + const vfModules = state.serviceInstance[serviceModelId].vnfs[vnfStoreKey].vfModules[vfModuleName]; + + _.forOwn(vfModules, (vfModuleInstance) => { + let isMissingData: boolean = vfModuleInstance.isMissingData; + updateServiceValidationCounter(state, isMissingData, false, serviceModelId); + }); +}; + +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++; + } +}; + + + |