Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import { |
| 2 | CloudConfiguration, |
| 3 | LineOfBusiness, |
| 4 | ModelInfo, |
| 5 | Platform, |
| 6 | RelatedInstanceList, |
| 7 | RequestDetails, |
| 8 | RequestInfo |
| 9 | } from "./models/requestDetails.model"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 10 | import * as _ from "lodash"; |
| 11 | |
| 12 | function extractModelInfoFromNodeTemplate(node: any, type: string) { |
| 13 | let modelInfo: ModelInfo = <ModelInfo>{}; |
| 14 | if (node["customizationUuid"] !== undefined) { |
| 15 | modelInfo.modelCustomizationId = node["customizationUuid"]; |
| 16 | } |
| 17 | if (node["modelCustomizationName"] !== undefined) { |
| 18 | modelInfo.modelCustomizationName = node["modelCustomizationName"]; |
| 19 | } |
| 20 | modelInfo.modelVersionId = node["uuid"]; |
| 21 | modelInfo.modelName = node["name"]; |
| 22 | modelInfo.modelInvariantId = node["invariantUuid"]; |
| 23 | modelInfo.modelType = type; |
| 24 | modelInfo.modelVersion = node["version"]; |
| 25 | return modelInfo; |
| 26 | } |
| 27 | |
| 28 | function extractRequestInfo(userInputs: any, userId: string): RequestInfo { |
| 29 | let requestInfo: RequestInfo = <RequestInfo>{}; |
| 30 | if (userInputs["instanceName"] !== undefined) requestInfo.instanceName = userInputs["instanceName"]; |
| 31 | requestInfo.productFamilyId = userInputs["productFamily"]; |
| 32 | requestInfo.source = "VID"; |
| 33 | requestInfo.suppressRollback = userInputs["rollback"] === "false"; |
| 34 | requestInfo.requestorId = userId; |
| 35 | return requestInfo; |
| 36 | } |
| 37 | |
| 38 | function extractPlatform(userInputs: any): Platform { |
| 39 | let platform: Platform = <Platform>{}; |
| 40 | platform.platformName = userInputs["platformName"]; |
| 41 | return platform; |
| 42 | } |
| 43 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 44 | function extractLineOfBusiness(userInputs: any) { |
| 45 | let lob: LineOfBusiness = <LineOfBusiness>{}; |
| 46 | lob.lineOfBusinessName = userInputs["lineOfBusiness"]; |
| 47 | return lob; |
| 48 | } |
| 49 | |
| 50 | function extractCloudConfiguration(userInputs: any) { |
| 51 | let cloudConfig: CloudConfiguration = <CloudConfiguration>{}; |
| 52 | cloudConfig.lcpCloudRegionId = userInputs["lcpRegion"]; |
| 53 | cloudConfig.tenantId = userInputs["tenantId"]; |
| 54 | return cloudConfig; |
| 55 | } |
| 56 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 57 | function extractModelInfoFromVfcNode(): ModelInfo { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 58 | let modelinfo: ModelInfo = <ModelInfo>{}; |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 59 | modelinfo.modelType = "networkInstanceGroup"; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 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) { |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 80 | let networkInstanceGroup: RelatedInstanceList = { |
| 81 | relatedInstance: { |
| 82 | instanceId: group["instance-group"].id, |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 83 | modelInfo: extractModelInfoFromVfcNode() |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 84 | } |
| 85 | }; |
| 86 | request.relatedInstanceList.push(networkInstanceGroup); |
| 87 | }); |
| 88 | |
| 89 | return request; |
| 90 | } |