|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | + |
| 3 | +package mpr |
| 4 | + |
| 5 | +import ( |
| 6 | + "github.com/mendixlabs/mxcli/mdl/types" |
| 7 | + "github.com/mendixlabs/mxcli/model" |
| 8 | + "github.com/mendixlabs/mxcli/sdk/javaactions" |
| 9 | +) |
| 10 | + |
| 11 | +// systemJavaParamDef defines a parameter of a System Java action. |
| 12 | +type systemJavaParamDef struct { |
| 13 | + Name string |
| 14 | + Type string // "String", "Boolean", "Integer", "Long", "Decimal", "DateTime" |
| 15 | +} |
| 16 | + |
| 17 | +// systemJavaActionDef defines a Java action in the System module. |
| 18 | +type systemJavaActionDef struct { |
| 19 | + Name string |
| 20 | + Documentation string |
| 21 | + ReturnType string // "Boolean", "String", "Integer", "Long", "Decimal", "DateTime", "Void" |
| 22 | + Parameters []systemJavaParamDef |
| 23 | +} |
| 24 | + |
| 25 | +// systemJavaActions lists all Java actions in the System module. |
| 26 | +// Extracted from Mendix Studio Pro 11.9.0 via mx dump-mpr --module-names=System --unit-type=JavaActions$JavaAction. |
| 27 | +var systemJavaActions = []systemJavaActionDef{ |
| 28 | + { |
| 29 | + Name: "VerifyPassword", |
| 30 | + Documentation: "Verifies that the specified user name/password combination is valid.", |
| 31 | + ReturnType: "Boolean", |
| 32 | + Parameters: []systemJavaParamDef{ |
| 33 | + {Name: "userName", Type: "String"}, |
| 34 | + {Name: "password", Type: "String"}, |
| 35 | + }, |
| 36 | + }, |
| 37 | +} |
| 38 | + |
| 39 | +// BuildSystemJavaActions returns lightweight types.JavaAction entries for the System module. |
| 40 | +// These are built-in Java actions not stored in the MPR SQLite database. |
| 41 | +// Used by ListJavaActions() for executor reference validation. |
| 42 | +func BuildSystemJavaActions() []*types.JavaAction { |
| 43 | + result := make([]*types.JavaAction, 0, len(systemJavaActions)) |
| 44 | + for _, def := range systemJavaActions { |
| 45 | + ja := &types.JavaAction{ |
| 46 | + ContainerID: model.ID(SystemModuleID), |
| 47 | + Name: def.Name, |
| 48 | + Documentation: def.Documentation, |
| 49 | + } |
| 50 | + ja.ID = model.ID(GenerateDeterministicID("System." + def.Name)) |
| 51 | + result = append(result, ja) |
| 52 | + } |
| 53 | + return result |
| 54 | +} |
| 55 | + |
| 56 | +// BuildSystemJavaActionsFull returns fully-typed javaactions.JavaAction entries for the System module. |
| 57 | +// These are built-in Java actions not stored in the MPR SQLite database. |
| 58 | +// Used by ListJavaActionsFull() for catalog insertion. |
| 59 | +func BuildSystemJavaActionsFull() []*javaactions.JavaAction { |
| 60 | + result := make([]*javaactions.JavaAction, 0, len(systemJavaActions)) |
| 61 | + for _, def := range systemJavaActions { |
| 62 | + ja := &javaactions.JavaAction{ |
| 63 | + ContainerID: model.ID(SystemModuleID), |
| 64 | + Name: def.Name, |
| 65 | + Documentation: def.Documentation, |
| 66 | + ExportLevel: "Hidden", |
| 67 | + } |
| 68 | + ja.ID = model.ID(GenerateDeterministicID("System." + def.Name)) |
| 69 | + ja.ReturnType = buildSystemReturnType(def.ReturnType) |
| 70 | + for _, p := range def.Parameters { |
| 71 | + param := &javaactions.JavaActionParameter{ |
| 72 | + Name: p.Name, |
| 73 | + IsRequired: true, |
| 74 | + } |
| 75 | + param.ID = model.ID(GenerateDeterministicID("System." + def.Name + "." + p.Name)) |
| 76 | + param.ParameterType = buildSystemParamType(p.Type) |
| 77 | + ja.Parameters = append(ja.Parameters, param) |
| 78 | + } |
| 79 | + result = append(result, ja) |
| 80 | + } |
| 81 | + return result |
| 82 | +} |
| 83 | + |
| 84 | +func buildSystemReturnType(t string) javaactions.CodeActionReturnType { |
| 85 | + switch t { |
| 86 | + case "Boolean": |
| 87 | + return &javaactions.BooleanType{} |
| 88 | + case "String": |
| 89 | + return &javaactions.StringType{} |
| 90 | + case "Integer": |
| 91 | + return &javaactions.IntegerType{} |
| 92 | + case "Long": |
| 93 | + return &javaactions.LongType{} |
| 94 | + case "Decimal": |
| 95 | + return &javaactions.DecimalType{} |
| 96 | + case "DateTime": |
| 97 | + return &javaactions.DateTimeType{} |
| 98 | + default: |
| 99 | + return &javaactions.VoidType{} |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +func buildSystemParamType(t string) javaactions.CodeActionParameterType { |
| 104 | + switch t { |
| 105 | + case "Boolean": |
| 106 | + return &javaactions.BooleanType{} |
| 107 | + case "Integer": |
| 108 | + return &javaactions.IntegerType{} |
| 109 | + case "Long": |
| 110 | + return &javaactions.LongType{} |
| 111 | + case "Decimal": |
| 112 | + return &javaactions.DecimalType{} |
| 113 | + case "DateTime": |
| 114 | + return &javaactions.DateTimeType{} |
| 115 | + default: |
| 116 | + return &javaactions.StringType{} |
| 117 | + } |
| 118 | +} |
0 commit comments