|
3 | 3 | package mpr |
4 | 4 |
|
5 | 5 | import ( |
| 6 | + "strings" |
| 7 | + |
6 | 8 | "github.com/mendixlabs/mxcli/model" |
7 | 9 | "github.com/mendixlabs/mxcli/sdk/microflows" |
8 | 10 |
|
@@ -701,48 +703,98 @@ func serializeWebServiceCallAction(a *microflows.WebServiceCallAction) bson.D { |
701 | 703 | } |
702 | 704 | } |
703 | 705 |
|
| 706 | + // ServiceName: use the local part of the qualified name (after the last dot). |
| 707 | + serviceName := string(a.ServiceID) |
| 708 | + if idx := strings.LastIndex(serviceName, "."); idx >= 0 { |
| 709 | + serviceName = serviceName[idx+1:] |
| 710 | + } |
| 711 | + |
704 | 712 | doc := bson.D{ |
705 | 713 | {Key: "$ID", Value: idToBsonBinary(string(a.ID))}, |
706 | 714 | {Key: "$Type", Value: "Microflows$CallWebServiceAction"}, |
707 | 715 | {Key: "ErrorHandlingType", Value: stringOrDefault(string(a.ErrorHandlingType), "Rollback")}, |
| 716 | + {Key: "HttpConfiguration", Value: bson.D{ |
| 717 | + {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
| 718 | + {Key: "$Type", Value: "Microflows$HttpConfiguration"}, |
| 719 | + {Key: "ClientCertificate", Value: ""}, |
| 720 | + {Key: "CustomLocation", Value: ""}, |
| 721 | + {Key: "CustomLocationTemplate", Value: nil}, |
| 722 | + {Key: "HttpAuthenticationPassword", Value: ""}, |
| 723 | + {Key: "HttpAuthenticationUserName", Value: ""}, |
| 724 | + {Key: "HttpHeaderEntries", Value: bson.A{int32(3)}}, |
| 725 | + {Key: "HttpMethod", Value: "Post"}, |
| 726 | + {Key: "OverrideLocation", Value: false}, |
| 727 | + {Key: "UseHttpAuthentication", Value: false}, |
| 728 | + }}, |
| 729 | + // ImportedService is a BY_NAME_REFERENCE qualified name string, not a binary UUID. |
708 | 730 | {Key: "ImportedService", Value: string(a.ServiceID)}, |
709 | | - {Key: "OperationName", Value: a.OperationName}, |
710 | | - {Key: "TimeOutExpression", Value: a.TimeoutExpression}, |
711 | | - {Key: "UseRequestTimeOut", Value: a.TimeoutExpression != ""}, |
| 731 | + {Key: "IsValidationRequired", Value: false}, |
712 | 732 | } |
713 | | - if a.SendMappingID != "" { |
714 | | - doc = append(doc, bson.E{Key: "RequestHandling", Value: bson.D{ |
| 733 | + |
| 734 | + // NewResultHandling uses Microflows$ResultHandling (same type as REST result handling). |
| 735 | + bind := a.OutputVariable != "" |
| 736 | + resultHandling := bson.D{ |
| 737 | + {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
| 738 | + {Key: "$Type", Value: "Microflows$ResultHandling"}, |
| 739 | + {Key: "Bind", Value: bind}, |
| 740 | + } |
| 741 | + if a.ReceiveMappingID != "" { |
| 742 | + // ReturnValueMapping is a BY_NAME_REFERENCE string, not a binary UUID. |
| 743 | + resultHandling = append(resultHandling, bson.E{Key: "ImportMappingCall", Value: bson.D{ |
715 | 744 | {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
716 | | - {Key: "$Type", Value: "Microflows$WebServiceOperationAdvancedRequestHandling"}, |
717 | | - {Key: "ExportMappingCall", Value: bson.D{ |
| 745 | + {Key: "$Type", Value: "Microflows$ImportMappingCall"}, |
| 746 | + {Key: "Commit", Value: "YesWithoutEvents"}, |
| 747 | + {Key: "ContentType", Value: "Json"}, |
| 748 | + {Key: "ForceSingleOccurrence", Value: false}, |
| 749 | + {Key: "ObjectHandlingBackup", Value: "Create"}, |
| 750 | + {Key: "ParameterVariableName", Value: ""}, |
| 751 | + {Key: "Range", Value: bson.D{ |
718 | 752 | {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
719 | | - {Key: "$Type", Value: "Microflows$ExportMappingCall"}, |
720 | | - {Key: "Mapping", Value: string(a.SendMappingID)}, |
721 | | - // Mendix storage lists encode their first element as a |
722 | | - // constant storage-list-type marker (`2` for object lists), |
723 | | - // NOT the element count. The empty ExportMappingCall shape |
724 | | - // used by other writers in this file follows the same |
725 | | - // convention; see #338 / #374 for prior fixes that aligned |
726 | | - // other writers on this marker. |
727 | | - {Key: "ParameterMappings", Value: bson.A{int32(2)}}, |
| 753 | + {Key: "$Type", Value: "Microflows$ConstantRange"}, |
| 754 | + {Key: "SingleObject", Value: true}, |
728 | 755 | }}, |
| 756 | + {Key: "ReturnValueMapping", Value: string(a.ReceiveMappingID)}, |
729 | 757 | }}) |
| 758 | + } else { |
| 759 | + resultHandling = append(resultHandling, bson.E{Key: "ImportMappingCall", Value: nil}) |
730 | 760 | } |
731 | | - if a.OutputVariable != "" || a.ReceiveMappingID != "" { |
732 | | - resultHandling := bson.D{ |
| 761 | + resultHandling = append(resultHandling, |
| 762 | + bson.E{Key: "ResultVariableName", Value: a.OutputVariable}, |
| 763 | + bson.E{Key: "VariableType", Value: bson.D{ |
733 | 764 | {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
734 | | - {Key: "$Type", Value: "Microflows$WebServiceOperationResultHandling"}, |
735 | | - {Key: "ResultVariableName", Value: a.OutputVariable}, |
736 | | - } |
737 | | - if a.ReceiveMappingID != "" { |
738 | | - resultHandling = append(resultHandling, bson.E{Key: "ImportMappingCall", Value: bson.D{ |
739 | | - {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
740 | | - {Key: "$Type", Value: "Microflows$ImportMappingCall"}, |
741 | | - {Key: "ReturnValueMapping", Value: string(a.ReceiveMappingID)}, |
742 | | - }}) |
743 | | - } |
744 | | - doc = append(doc, bson.E{Key: "NewResultHandling", Value: resultHandling}) |
745 | | - } |
| 765 | + {Key: "$Type", Value: "DataTypes$VoidType"}, |
| 766 | + }}, |
| 767 | + ) |
| 768 | + doc = append(doc, bson.E{Key: "NewResultHandling", Value: resultHandling}) |
| 769 | + |
| 770 | + doc = append(doc, bson.E{Key: "OperationName", Value: a.OperationName}) |
| 771 | + doc = append(doc, bson.E{Key: "ProxyConfiguration", Value: nil}) |
| 772 | + |
| 773 | + // RequestBodyHandling: always SimpleRequestHandling. Mendix$AdvancedRequestHandling |
| 774 | + // (used when a send mapping is configured) requires a Studio Pro-generated example |
| 775 | + // to determine the correct type storage name; use the raw BSON escape hatch for |
| 776 | + // complex SOAP operations that need a send mapping until that is resolved. |
| 777 | + doc = append(doc, bson.E{Key: "RequestBodyHandling", Value: bson.D{ |
| 778 | + {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
| 779 | + {Key: "$Type", Value: "Microflows$SimpleRequestHandling"}, |
| 780 | + {Key: "NullValueOption", Value: "LeaveOutElement"}, |
| 781 | + {Key: "ParameterMappings", Value: bson.A{int32(2)}}, |
| 782 | + }}) |
| 783 | + |
| 784 | + // RequestHeaderHandling is always SimpleRequestHandling. |
| 785 | + doc = append(doc, bson.E{Key: "RequestHeaderHandling", Value: bson.D{ |
| 786 | + {Key: "$ID", Value: idToBsonBinary(GenerateID())}, |
| 787 | + {Key: "$Type", Value: "Microflows$SimpleRequestHandling"}, |
| 788 | + {Key: "NullValueOption", Value: "LeaveOutElement"}, |
| 789 | + {Key: "ParameterMappings", Value: bson.A{int32(2)}}, |
| 790 | + }}) |
| 791 | + |
| 792 | + doc = append(doc, bson.E{Key: "RequestProxyType", Value: "DefaultProxy"}) |
| 793 | + doc = append(doc, bson.E{Key: "ServiceName", Value: serviceName}) |
| 794 | + doc = append(doc, |
| 795 | + bson.E{Key: "TimeOutExpression", Value: stringOrDefault(a.TimeoutExpression, "300")}, |
| 796 | + bson.E{Key: "UseRequestTimeOut", Value: true}, |
| 797 | + ) |
746 | 798 | return doc |
747 | 799 | } |
748 | 800 |
|
|
0 commit comments