Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame^] | 1 | import { RequestInfo, RequestDetails, ModelInfo, CloudConfiguration, LineOfBusiness, Platform, RelatedInstanceList, VfcModel } from "./models/requestDetails.model"; |
| 2 | import * as _ from "lodash"; |
| 3 | |
| 4 | function extractModelInfoFromNodeTemplate(node: any, type: string) { |
| 5 | let modelInfo: ModelInfo = <ModelInfo>{}; |
| 6 | if (node["customizationUuid"] !== undefined) { |
| 7 | modelInfo.modelCustomizationId = node["customizationUuid"]; |
| 8 | } |
| 9 | if (node["modelCustomizationName"] !== undefined) { |
| 10 | modelInfo.modelCustomizationName = node["modelCustomizationName"]; |
| 11 | } |
| 12 | modelInfo.modelVersionId = node["uuid"]; |
| 13 | modelInfo.modelName = node["name"]; |
| 14 | modelInfo.modelInvariantId = node["invariantUuid"]; |
| 15 | modelInfo.modelType = type; |
| 16 | modelInfo.modelVersion = node["version"]; |
| 17 | return modelInfo; |
| 18 | } |
| 19 | |
| 20 | function extractRequestInfo(userInputs: any, userId: string): RequestInfo { |
| 21 | let requestInfo: RequestInfo = <RequestInfo>{}; |
| 22 | if (userInputs["instanceName"] !== undefined) requestInfo.instanceName = userInputs["instanceName"]; |
| 23 | requestInfo.productFamilyId = userInputs["productFamily"]; |
| 24 | requestInfo.source = "VID"; |
| 25 | requestInfo.suppressRollback = userInputs["rollback"] === "false"; |
| 26 | requestInfo.requestorId = userId; |
| 27 | return requestInfo; |
| 28 | } |
| 29 | |
| 30 | function extractPlatform(userInputs: any): Platform { |
| 31 | let platform: Platform = <Platform>{}; |
| 32 | platform.platformName = userInputs["platformName"]; |
| 33 | return platform; |
| 34 | } |
| 35 | |
| 36 | function extractVfcGroupModelAccordingToUuid(vnfModel: any, vfcUuid: string) { |
| 37 | return _.find(vnfModel.vfcInstanceGroups, { uuid: vfcUuid }); |
| 38 | } |
| 39 | |
| 40 | function extractLineOfBusiness(userInputs: any) { |
| 41 | let lob: LineOfBusiness = <LineOfBusiness>{}; |
| 42 | lob.lineOfBusinessName = userInputs["lineOfBusiness"]; |
| 43 | return lob; |
| 44 | } |
| 45 | |
| 46 | function extractCloudConfiguration(userInputs: any) { |
| 47 | let cloudConfig: CloudConfiguration = <CloudConfiguration>{}; |
| 48 | cloudConfig.lcpCloudRegionId = userInputs["lcpRegion"]; |
| 49 | cloudConfig.tenantId = userInputs["tenantId"]; |
| 50 | return cloudConfig; |
| 51 | } |
| 52 | |
| 53 | function extractModelInfoFromVfcNode(vfcModel: VfcModel): ModelInfo { |
| 54 | let modelinfo: ModelInfo = <ModelInfo>{}; |
| 55 | modelinfo.modelName = vfcModel.name; |
| 56 | modelinfo.modelType = "networkCollection"; |
| 57 | modelinfo.modelVersion = vfcModel.version; |
| 58 | modelinfo.modelVersionId = vfcModel.uuid; |
| 59 | modelinfo.modelInvariantId = vfcModel.invariantUuid; |
| 60 | return modelinfo; |
| 61 | } |
| 62 | |
| 63 | export function createRequest(userId: string, userInputs: any, service: any, serviceInstanceId: string, networkInstanceGroups: any, vnfCustomizationName: string, vnfCustomizationId: string) { |
| 64 | let request: RequestDetails = <RequestDetails>{}; |
| 65 | request.requestInfo = extractRequestInfo(userInputs, userId); |
| 66 | request.lineOfBusiness = extractLineOfBusiness(userInputs); |
| 67 | request.cloudConfiguration = extractCloudConfiguration(userInputs); |
| 68 | request.platform = extractPlatform(userInputs); |
| 69 | request.modelInfo = extractModelInfoFromNodeTemplate(service.vnfs[vnfCustomizationName], "vnf"); |
| 70 | request.requestParameters = { userParams: [], testApi: sessionStorage.getItem("msoRequestParametersTestApiValue")}; |
| 71 | request.relatedInstanceList = []; |
| 72 | let serviceRelatedInstance: RelatedInstanceList = { |
| 73 | relatedInstance: { |
| 74 | instanceId: serviceInstanceId, |
| 75 | modelInfo: extractModelInfoFromNodeTemplate(service.service, "service") |
| 76 | } |
| 77 | }; |
| 78 | request.relatedInstanceList.push(serviceRelatedInstance); |
| 79 | _.forOwn(networkInstanceGroups, function(group) { |
| 80 | let modelUuid = group["instance-group"]["model-version-id"]; |
| 81 | let vfcModel = extractVfcGroupModelAccordingToUuid(service.vnfs[vnfCustomizationName], modelUuid); |
| 82 | let networkInstanceGroup: RelatedInstanceList = { |
| 83 | relatedInstance: { |
| 84 | instanceId: group["instance-group"].id, |
| 85 | modelInfo: extractModelInfoFromVfcNode(vfcModel) |
| 86 | } |
| 87 | }; |
| 88 | request.relatedInstanceList.push(networkInstanceGroup); |
| 89 | }); |
| 90 | |
| 91 | return request; |
| 92 | } |