@@ -44,11 +44,6 @@ public LDAiClient(LDClientInterface client) {
44
44
/**
45
45
* Method to convert the JSON variable into the AiConfig object
46
46
*
47
- * Currently, I am doing this in a mutable way, just to verify the logic convert
48
- * LDValue into AiConfig.
49
- * It is possible we need a builder to create immutable version of this for ease
50
- * of use in a later PR.
51
- *
52
47
* @param value
53
48
* @param key
54
49
*/
@@ -67,13 +62,12 @@ protected AiConfig parseAiConfig(LDValue value, String key) {
67
62
throw new AiConfigParseException ("_ldMeta must be a JSON object" );
68
63
}
69
64
70
- Meta meta = new Meta ();
71
- // TODO: Do we expect customer calling this to build default value?
72
- // If we do, then some of the values would be null
73
- meta .setEnabled (ldValueNullCheck (valueMeta .get ("enabled" )).booleanValue ());
74
- meta .setVariationKey (ldValueNullCheck (valueMeta .get ("variationKey" )).stringValue ());
75
- Optional <Integer > version = Optional .of (valueMeta .get ("version" ).intValue ());
76
- meta .setVersion (version );
65
+ // Create Meta using constructor
66
+ Meta meta = new Meta (
67
+ ldValueNullCheck (valueMeta .get ("variationKey" )).stringValue (),
68
+ Optional .of (valueMeta .get ("version" ).intValue ()),
69
+ ldValueNullCheck (valueMeta .get ("enabled" )).booleanValue ()
70
+ );
77
71
result .setMeta (meta );
78
72
79
73
// Convert the optional messages from an JSON array of JSON objects into Message
@@ -97,25 +91,21 @@ protected AiConfig parseAiConfig(LDValue value, String key) {
97
91
throw new AiConfigParseException ("model must be a JSON object" );
98
92
}
99
93
100
- Model model = new Model ();
101
- model .setName (ldValueNullCheck (valueModel .get ("name" )).stringValue ());
94
+ // Prepare parameters and custom maps for Model
95
+ String modelName = ldValueNullCheck (valueModel .get ("name" )).stringValue ();
96
+ HashMap <String , LDValue > parameters = null ;
97
+ HashMap <String , LDValue > custom = null ;
102
98
103
99
LDValue valueParameters = valueModel .get ("parameters" );
104
100
if (valueParameters .getType () != LDValueType .NULL ) {
105
101
if (valueParameters .getType () != LDValueType .OBJECT ) {
106
102
throw new AiConfigParseException ("non-null parameters must be a JSON object" );
107
103
}
108
104
109
- HashMap < String , LDValue > parameters = new HashMap <>();
105
+ parameters = new HashMap <>();
110
106
for (String k : valueParameters .keys ()) {
111
107
parameters .put (k , valueParameters .get (k ));
112
108
}
113
- model .setParameters (parameters );
114
- } else {
115
- // Parameters is optional - so we can just set null and proceed
116
-
117
- // TODO: Mustash validation somewhere
118
- model .setParameters (null );
119
109
}
120
110
121
111
LDValue valueCustom = valueModel .get ("custom" );
@@ -124,15 +114,14 @@ protected AiConfig parseAiConfig(LDValue value, String key) {
124
114
throw new AiConfigParseException ("non-null custom must be a JSON object" );
125
115
}
126
116
127
- HashMap < String , LDValue > custom = new HashMap <>();
117
+ custom = new HashMap <>();
128
118
for (String k : valueCustom .keys ()) {
129
119
custom .put (k , valueCustom .get (k ));
130
120
}
131
- model .setCustom (custom );
132
- } else {
133
- // Custom is optional - we can just set null and proceed
134
- model .setCustom (null );
135
121
}
122
+
123
+ // Create Model using constructor
124
+ Model model = new Model (modelName , parameters , custom );
136
125
result .setModel (model );
137
126
138
127
// Convert the optional provider from an JSON object of with name into Provider
0 commit comments