Skip to content

Commit

Permalink
Fix Java OpenFeature docs (#490)
Browse files Browse the repository at this point in the history
* Fix Java OpenFeature docs

* Update java.mdx
  • Loading branch information
z4kn4fein authored Sep 24, 2024
1 parent 93ffaa1 commit 692845a
Show file tree
Hide file tree
Showing 14 changed files with 78 additions and 44 deletions.
6 changes: 3 additions & 3 deletions website/docs/sdk-reference/android.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#");

```java
boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "<key-of-my-awesome-feature>", false);
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand All @@ -64,7 +64,7 @@ if(isMyAwesomeFeatureEnabled) {
// Or asynchronously
client.getValueAsync(Boolean.class, "<key-of-my-awesome-feature>", false)
.thenAccept(isMyAwesomeFeatureEnabled -> {
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down Expand Up @@ -176,7 +176,7 @@ client.getValueAsync(
User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object
false // Default value
).thenAccept(isMyAwesomeFeatureEnabled -> {
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
2 changes: 1 addition & 1 deletion website/docs/sdk-reference/dart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final client = ConfigCatClient.get(

```dart
final isMyAwesomeFeatureEnabled = await client.getValue(key: 'isMyAwesomeFeatureEnabled', defaultValue: false);
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
2 changes: 1 addition & 1 deletion website/docs/sdk-reference/dotnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var client = ConfigCatClient.Get("#YOUR-SDK-KEY#");

```csharp
var isMyAwesomeFeatureEnabled = await client.GetValueAsync("isMyAwesomeFeatureEnabled", false);
if(isMyAwesomeFeatureEnabled)
if (isMyAwesomeFeatureEnabled)
{
doTheNewThing();
}
Expand Down
4 changes: 2 additions & 2 deletions website/docs/sdk-reference/java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#");

```java
boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", false);
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down Expand Up @@ -183,7 +183,7 @@ client.getValueAsync(
User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object
false // Default value
).thenAccept(isMyAwesomeFeatureEnabled -> {
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
43 changes: 30 additions & 13 deletions website/docs/sdk-reference/openfeature/java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import TabItem from '@theme/TabItem';
```groovy title="build.gradle"
dependencies {
implementation 'dev.openfeature.contrib.providers:configcat:0.0.4'
implementation 'dev.openfeature:sdk:1.+'
}
```

Expand All @@ -27,9 +28,14 @@ dependencies {

```xml title="pom.xml"
<dependency>
<groupId>dev.openfeature.contrib.providers</groupId>
<artifactId>configcat</artifactId>
<version>0.0.4</version>
<groupId>dev.openfeature.contrib.providers</groupId>
<artifactId>configcat</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>dev.openfeature</groupId>
<artifactId>sdk</artifactId>
<version>[1.0,)</version>
</dependency>
```

Expand All @@ -42,10 +48,13 @@ The `ConfigCatProvider` constructor takes a `ConfigCatProviderConfig` argument c
```java
// Build options for the ConfigCat SDK.
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder()
.sdkKey("#YOUR-SDK-KEY#")
.pollingMode(PollingModes.autoPoll())
.logLevel(LogLevel.WARNING)
.build();
.sdkKey("#YOUR-SDK-KEY#")
.options(options -> {
options.pollingMode(PollingModes.autoPoll());
options.logLevel(LogLevel.WARNING);
// ...
})
.build();

// Configure the provider.
OpenFeatureAPI.getInstance().setProviderAndWait(new ConfigCatProvider(configCatProviderConfig));
Expand All @@ -60,7 +69,7 @@ For more information about all the configuration options, see the [Java SDK docu

```java
boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false);
if(isAwesomeFeatureEnabled)
if (isAwesomeFeatureEnabled)
{
doTheNewThing();
}
Expand All @@ -70,6 +79,14 @@ else
}
```

### 4. Cleaning up

On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client.

```cs
OpenFeatureAPI.getInstance().shutdown();
```

## Evaluation Context

An <a href="https://openfeature.dev/docs/reference/concepts/evaluation-context" target="_blank">evaluation context</a> in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation.
Expand All @@ -87,11 +104,11 @@ The following table shows how the different context attributes are mapped to Use
To evaluate feature flags for a context, use the <a href="https://openfeature.dev/docs/reference/concepts/evaluation-api/" target="_blank">OpenFeature Evaluation API</a>:

```java
MutableContext evaluationContext = new MutableContext();
evaluationContext.setTargetingKey("#SOME-USER-ID#");
evaluationContext.add("Email", "[email protected]");
evaluationContext.add("Country", "CountryID");
evaluationContext.add("Rating", 4.5);
MutableContext context = new MutableContext();
context.setTargetingKey("#SOME-USER-ID#");
context.add("Email", "[email protected]");
context.add("Country", "CountryID");
context.add("Rating", 4.5);

boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context);
```
Expand Down
2 changes: 1 addition & 1 deletion website/docs/sdk-reference/openfeature/php.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ For more information about all the configuration options, see the [PHP SDK docum

```php
$isAwesomeFeatureEnabled = $client->getBooleanValue('isAwesomeFeatureEnabled', false);
if(is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) {
if (is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
2 changes: 1 addition & 1 deletion website/docs/sdk-reference/php.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $client = new \ConfigCat\ConfigCatClient("#YOUR-SDK-KEY#");

```php
$isMyAwesomeFeatureEnabled = $client->getValue("isMyAwesomeFeatureEnabled", false);
if(is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) {
if (is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
6 changes: 3 additions & 3 deletions website/versioned_docs/version-V1/sdk-reference/android.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#");

```java
boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "<key-of-my-awesome-feature>", false);
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand All @@ -70,7 +70,7 @@ if(isMyAwesomeFeatureEnabled) {
// Or asynchronously
client.getValueAsync(Boolean.class, "<key-of-my-awesome-feature>", false)
.thenAccept(isMyAwesomeFeatureEnabled -> {
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down Expand Up @@ -182,7 +182,7 @@ client.getValueAsync(
User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object
false // Default value
).thenAccept(isMyAwesomeFeatureEnabled -> {
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-V1/sdk-reference/dart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final client = ConfigCatClient.get(

```dart
final isMyAwesomeFeatureEnabled = await client.getValue(key: 'isMyAwesomeFeatureEnabled', defaultValue: false);
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-V1/sdk-reference/dotnet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var client = ConfigCatClient.Get("#YOUR-SDK-KEY#");

```csharp
var isMyAwesomeFeatureEnabled = client.GetValue("isMyAwesomeFeatureEnabled", false);
if(isMyAwesomeFeatureEnabled)
if (isMyAwesomeFeatureEnabled)
{
doTheNewThing();
}
Expand Down
4 changes: 2 additions & 2 deletions website/versioned_docs/version-V1/sdk-reference/java.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ConfigCatClient client = ConfigCatClient.get("#YOUR-SDK-KEY#");

```java
boolean isMyAwesomeFeatureEnabled = client.getValue(Boolean.class, "isMyAwesomeFeatureEnabled", false);
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down Expand Up @@ -188,7 +188,7 @@ client.getValueAsync(
User.newBuilder().build("#UNIQUE-USER-IDENTIFIER#"), // Optional User Object
false // Default value
).thenAccept(isMyAwesomeFeatureEnabled -> {
if(isMyAwesomeFeatureEnabled) {
if (isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import TabItem from '@theme/TabItem';
```groovy title="build.gradle"
dependencies {
implementation 'dev.openfeature.contrib.providers:configcat:0.0.4'
implementation 'dev.openfeature:sdk:1.+'
}
```

Expand All @@ -27,9 +28,14 @@ dependencies {

```xml title="pom.xml"
<dependency>
<groupId>dev.openfeature.contrib.providers</groupId>
<artifactId>configcat</artifactId>
<version>0.0.4</version>
<groupId>dev.openfeature.contrib.providers</groupId>
<artifactId>configcat</artifactId>
<version>0.0.4</version>
</dependency>
<dependency>
<groupId>dev.openfeature</groupId>
<artifactId>sdk</artifactId>
<version>[1.0,)</version>
</dependency>
```

Expand All @@ -42,10 +48,13 @@ The `ConfigCatProvider` constructor takes a `ConfigCatProviderConfig` argument c
```java
// Build options for the ConfigCat SDK.
ConfigCatProviderConfig configCatProviderConfig = ConfigCatProviderConfig.builder()
.sdkKey("#YOUR-SDK-KEY#")
.pollingMode(PollingModes.autoPoll())
.logLevel(LogLevel.WARNING)
.build();
.sdkKey("#YOUR-SDK-KEY#")
.options(options -> {
options.pollingMode(PollingModes.autoPoll());
options.logLevel(LogLevel.WARNING);
// ...
})
.build();

// Configure the provider.
OpenFeatureAPI.getInstance().setProviderAndWait(new ConfigCatProvider(configCatProviderConfig));
Expand All @@ -60,7 +69,7 @@ For more information about all the configuration options, see the [Java SDK docu

```java
boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false);
if(isAwesomeFeatureEnabled)
if (isAwesomeFeatureEnabled)
{
doTheNewThing();
}
Expand All @@ -70,6 +79,14 @@ else
}
```

### 4. Cleaning up

On application shutdown, clean up the OpenFeature provider and the underlying ConfigCat client.

```cs
OpenFeatureAPI.getInstance().shutdown();
```

## Evaluation Context

An <a href="https://openfeature.dev/docs/reference/concepts/evaluation-context" target="_blank">evaluation context</a> in the OpenFeature specification is a container for arbitrary contextual data that can be used as a basis for feature flag evaluation.
Expand All @@ -87,11 +104,11 @@ The following table shows how the different context attributes are mapped to Use
To evaluate feature flags for a context, use the <a href="https://openfeature.dev/docs/reference/concepts/evaluation-api/" target="_blank">OpenFeature Evaluation API</a>:

```java
MutableContext evaluationContext = new MutableContext();
evaluationContext.setTargetingKey("#SOME-USER-ID#");
evaluationContext.add("Email", "[email protected]");
evaluationContext.add("Country", "CountryID");
evaluationContext.add("Rating", 4.5);
MutableContext context = new MutableContext();
context.setTargetingKey("#SOME-USER-ID#");
context.add("Email", "[email protected]");
context.add("Country", "CountryID");
context.add("Rating", 4.5);

boolean isAwesomeFeatureEnabled = client.getBooleanValue("isAwesomeFeatureEnabled", false, context);
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ For more information about all the configuration options, see the [PHP SDK docum

```php
$isAwesomeFeatureEnabled = $client->getBooleanValue('isAwesomeFeatureEnabled', false);
if(is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) {
if (is_bool($isAwesomeFeatureEnabled) && $isAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down
2 changes: 1 addition & 1 deletion website/versioned_docs/version-V1/sdk-reference/php.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ $client = new \ConfigCat\ConfigCatClient("#YOUR-SDK-KEY#");

```php
$isMyAwesomeFeatureEnabled = $client->getValue("isMyAwesomeFeatureEnabled", false);
if(is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) {
if (is_bool($isMyAwesomeFeatureEnabled) && $isMyAwesomeFeatureEnabled) {
doTheNewThing();
} else {
doTheOldThing();
Expand Down

0 comments on commit 692845a

Please sign in to comment.