Skip to content

Commit d1281ae

Browse files
fix: update example apps, set sdkPlatform for OF context.
Signed-off-by: Jonathan Norris <jonathan@taplytics.com>
1 parent 5ea55ec commit d1281ae

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

src/examples/java/com/devcycle/examples/LocalExample.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.devcycle.examples;
22

33
import com.devcycle.sdk.server.common.logging.SimpleDevCycleLogger;
4+
import com.devcycle.sdk.server.common.model.DevCycleEvent;
45
import com.devcycle.sdk.server.common.model.DevCycleUser;
56
import com.devcycle.sdk.server.local.api.DevCycleLocalClient;
67
import com.devcycle.sdk.server.local.model.DevCycleLocalOptions;
@@ -24,9 +25,7 @@ public static void main(String[] args) throws InterruptedException {
2425
Boolean defaultValue = false;
2526

2627
DevCycleLocalOptions options = DevCycleLocalOptions.builder()
27-
.configPollingIntervalMS(60000)
2828
.customLogger(new SimpleDevCycleLogger(SimpleDevCycleLogger.Level.DEBUG))
29-
.enableBetaRealtimeUpdates(true)
3029
.build();
3130

3231
// Initialize DevCycle Client
@@ -50,6 +49,10 @@ public static void main(String[] args) throws InterruptedException {
5049
} else {
5150
System.out.println("feature is NOT enabled");
5251
}
53-
Thread.sleep(10000);
52+
53+
DevCycleEvent event = DevCycleEvent.builder().type("local-test").build();
54+
client.track(user, event);
55+
56+
Thread.sleep(20000);
5457
}
5558
}

src/examples/java/com/devcycle/examples/OpenFeatureExample.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.devcycle.examples;
22

3+
import com.devcycle.sdk.server.common.logging.SimpleDevCycleLogger;
34
import com.devcycle.sdk.server.local.api.DevCycleLocalClient;
45
import com.devcycle.sdk.server.local.model.DevCycleLocalOptions;
56
import dev.openfeature.sdk.*;
@@ -15,22 +16,16 @@ public static void main(String[] args) throws InterruptedException {
1516
System.exit(1);
1617
}
1718

18-
DevCycleLocalOptions options = DevCycleLocalOptions.builder().configPollingIntervalMS(60000)
19-
.disableAutomaticEventLogging(false).disableCustomEventLogging(false).build();
19+
DevCycleLocalOptions options = DevCycleLocalOptions.builder()
20+
.customLogger(new SimpleDevCycleLogger(SimpleDevCycleLogger.Level.DEBUG))
21+
.build();
2022

2123
// Initialize DevCycle Client
2224
DevCycleLocalClient devCycleClient = new DevCycleLocalClient(server_sdk_key, options);
2325

24-
for (int i = 0; i < 10; i++) {
25-
if (devCycleClient.isInitialized()) {
26-
break;
27-
}
28-
Thread.sleep(500);
29-
}
30-
3126
// Setup OpenFeature with the DevCycle Provider
3227
OpenFeatureAPI api = OpenFeatureAPI.getInstance();
33-
api.setProvider(devCycleClient.getOpenFeatureProvider());
28+
api.setProviderAndWait(devCycleClient.getOpenFeatureProvider());
3429

3530
Client openFeatureClient = api.getClient();
3631

@@ -41,7 +36,7 @@ public static void main(String[] args) throws InterruptedException {
4136
context.add("language", "en");
4237
context.add("country", "CA");
4338
context.add("appVersion", "1.0.0");
44-
context.add("appBuild", "1");
39+
context.add("appBuild", 1.0);
4540
context.add("deviceModel", "Macbook");
4641

4742
// Add Devcycle Custom Data values
@@ -81,5 +76,14 @@ public static void main(String[] args) throws InterruptedException {
8176
System.out.println("Value: " + details.getValue());
8277
System.out.println("Reason: " + details.getReason());
8378

79+
MutableTrackingEventDetails eventDetails = new MutableTrackingEventDetails(610.1);
80+
eventDetails.add("test-string", "test-value");
81+
eventDetails.add("test-number", 123.456);
82+
eventDetails.add("test-boolean", true);
83+
eventDetails.add("test-json", new Value(Structure.mapToStructure(defaultJsonData)));
84+
85+
openFeatureClient.track("test-of-event", context, eventDetails);
86+
87+
Thread.sleep(20000);
8488
}
8589
}

src/main/java/com/devcycle/sdk/server/common/model/DevCycleUser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public class DevCycleUser {
105105
private String sdkVersion = getPlatformData().getSdkVersion();
106106

107107
@Schema(description = "DevCycle SDK Platform")
108+
@Builder.Default
108109
@JsonProperty("sdkPlatform")
109110
private String sdkPlatform = null;
110111

@@ -153,7 +154,7 @@ public static DevCycleUser fromEvaluationContext(EvaluationContext ctx) {
153154
throw new TargetingKeyMissingError();
154155
}
155156

156-
DevCycleUser user = DevCycleUser.builder().userId(userId).build();
157+
DevCycleUser user = DevCycleUser.builder().userId(userId).sdkPlatform("java-of").build();
157158

158159
Map<String, Object> customData = new LinkedHashMap<>();
159160
Map<String, Object> privateCustomData = new LinkedHashMap<>();

0 commit comments

Comments
 (0)