blob: ebca834123eb64a3dffac1aa43d886b1bdf4845e [file] [log] [blame]
Ittay Stern6f900cc2018-08-29 17:01:32 +03001import {
2 CloudConfiguration,
3 LineOfBusiness,
4 ModelInfo,
5 Platform,
6 RelatedInstanceList,
7 RequestDetails,
8 RequestInfo
9} from "./models/requestDetails.model";
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030010import * as _ from "lodash";
11
12function 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
28function 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
38function extractPlatform(userInputs: any): Platform {
39 let platform: Platform = <Platform>{};
40 platform.platformName = userInputs["platformName"];
41 return platform;
42}
43
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030044function extractLineOfBusiness(userInputs: any) {
45 let lob: LineOfBusiness = <LineOfBusiness>{};
46 lob.lineOfBusinessName = userInputs["lineOfBusiness"];
47 return lob;
48}
49
50function extractCloudConfiguration(userInputs: any) {
51 let cloudConfig: CloudConfiguration = <CloudConfiguration>{};
52 cloudConfig.lcpCloudRegionId = userInputs["lcpRegion"];
53 cloudConfig.tenantId = userInputs["tenantId"];
54 return cloudConfig;
55}
56
Ittay Stern6f900cc2018-08-29 17:01:32 +030057function extractModelInfoFromVfcNode(): ModelInfo {
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030058 let modelinfo: ModelInfo = <ModelInfo>{};
Ittay Stern6f900cc2018-08-29 17:01:32 +030059 modelinfo.modelType = "networkInstanceGroup";
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030060 return modelinfo;
61}
62
63export 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)ff76b5e2018-07-10 15:57:37 +030080 let networkInstanceGroup: RelatedInstanceList = {
81 relatedInstance: {
82 instanceId: group["instance-group"].id,
Ittay Stern6f900cc2018-08-29 17:01:32 +030083 modelInfo: extractModelInfoFromVfcNode()
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030084 }
85 };
86 request.relatedInstanceList.push(networkInstanceGroup);
87 });
88
89 return request;
90}