-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #193 from martiner/liry-ff
add listing of aggregated feature flags for project
- Loading branch information
Showing
8 changed files
with
256 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (C) 2007-2015, GoodData(R) Corporation. All rights reserved. | ||
*/ | ||
package com.gooddata.gdc; | ||
|
||
import static com.gooddata.util.Validate.notNull; | ||
|
||
/** | ||
* Feature flag is a boolean flag used for enabling / disabling some specific feature of GoodData platform. | ||
* It can be used in various scopes (per project, per project group, per user, global etc.). | ||
*/ | ||
public class FeatureFlag { | ||
|
||
private final String name; | ||
private boolean enabled; | ||
|
||
public FeatureFlag(final String name, final boolean enabled) { | ||
this.name = notNull(name, "name cannot be null"); | ||
this.enabled = enabled; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public boolean getEnabled() { | ||
return enabled; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
final FeatureFlag that = (FeatureFlag) o; | ||
|
||
if (enabled != that.enabled) return false; | ||
return !(name != null ? !name.equals(that.name) : that.name != null); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = name != null ? name.hashCode() : 0; | ||
result = 31 * result + (enabled ? 1 : 0); | ||
return result; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{name='" + name + '\'' + ", enabled=" + enabled + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (C) 2007-2015, GoodData(R) Corporation. All rights reserved. | ||
*/ | ||
package com.gooddata.gdc; | ||
|
||
import org.codehaus.jackson.annotate.JsonAnySetter; | ||
import org.codehaus.jackson.annotate.JsonIgnoreProperties; | ||
import org.codehaus.jackson.annotate.JsonTypeInfo; | ||
import org.codehaus.jackson.annotate.JsonTypeName; | ||
import org.springframework.web.util.UriTemplate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.springframework.util.Assert.notNull; | ||
import static org.springframework.util.CollectionUtils.isEmpty; | ||
|
||
@JsonTypeInfo(include = JsonTypeInfo.As.WRAPPER_OBJECT, use = JsonTypeInfo.Id.NAME) | ||
@JsonTypeName("featureFlags") | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class FeatureFlags { | ||
|
||
public static final String AGGREGATED_FEATURE_FLAGS_URI = "/gdc/internal/projects/{projectId}/featureFlags"; | ||
public static final UriTemplate AGGREGATED_FEATURE_FLAGS_TEMPLATE = new UriTemplate(AGGREGATED_FEATURE_FLAGS_URI); | ||
|
||
private final List<FeatureFlag> featureFlags = new ArrayList<>(); | ||
|
||
/* protected helper method for JSON deserialization */ | ||
@JsonAnySetter | ||
protected void addFlag(final String name, final boolean enabled) { | ||
notNull(name); | ||
featureFlags.add(new FeatureFlag(name, enabled)); | ||
} | ||
|
||
public List<FeatureFlag> getFeatureFlags() { | ||
return featureFlags; | ||
} | ||
|
||
@Override | ||
public boolean equals(final Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
final FeatureFlags that = (FeatureFlags) o; | ||
|
||
return !(featureFlags != null ? !featureFlags.equals(that.featureFlags) : that.featureFlags != null); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return featureFlags != null ? featureFlags.hashCode() : 0; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FeatureFlags{" + featureFlags + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) 2007-2015, GoodData(R) Corporation. All rights reserved. | ||
*/ | ||
package com.gooddata.gdc; | ||
|
||
import org.testng.annotations.Test; | ||
|
||
import static com.gooddata.util.ResourceUtils.readObjectFromResource; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.testng.AssertJUnit.assertNotNull; | ||
|
||
public class FeatureFlagsTest { | ||
|
||
@Test | ||
public void testDeserialize() { | ||
final FeatureFlags featureFlags = readObjectFromResource(getClass(), "/gdc/featureFlags.json", | ||
FeatureFlags.class); | ||
assertNotNull(featureFlags); | ||
|
||
assertThat(featureFlags.getFeatureFlags(), hasSize(2)); | ||
assertThat(featureFlags.getFeatureFlags(), contains( | ||
new FeatureFlag("testFeature", true), | ||
new FeatureFlag("testFeature2", false))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.