Skip to content

Commit 41592e4

Browse files
authored
Feature Management - APIView comments (#46720)
* APIView comments * Feature to FeatureDefinition * Renaming a few things
1 parent ac0a5d9 commit 41592e4

File tree

23 files changed

+267
-227
lines changed

23 files changed

+267
-227
lines changed

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/FeatureManager.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import com.azure.spring.cloud.feature.management.models.Allocation;
2828
import com.azure.spring.cloud.feature.management.models.Conditions;
2929
import com.azure.spring.cloud.feature.management.models.EvaluationEvent;
30-
import com.azure.spring.cloud.feature.management.models.Feature;
30+
import com.azure.spring.cloud.feature.management.models.FeatureDefinition;
3131
import com.azure.spring.cloud.feature.management.models.FeatureFilterEvaluationContext;
3232
import com.azure.spring.cloud.feature.management.models.FeatureManagementException;
3333
import com.azure.spring.cloud.feature.management.models.FilterNotFoundException;
@@ -187,13 +187,13 @@ public Mono<Variant> getVariantAsync(String feature, Object featureContext) {
187187

188188
private Mono<EvaluationEvent> checkFeature(String featureName, Object featureContext)
189189
throws FilterNotFoundException {
190-
List<Feature> featureFlags = featureManagementConfigurations.getFeatureFlags();
190+
List<FeatureDefinition> featureFlags = featureManagementConfigurations.getFeatureFlags();
191191

192192
if (featureFlags == null) {
193193
return Mono.just(new EvaluationEvent(null));
194194
}
195195

196-
Feature featureFlag = featureFlags.stream()
196+
FeatureDefinition featureFlag = featureFlags.stream()
197197
.filter(feature -> feature.getId().equals(featureName)).findAny().orElse(null);
198198

199199
EvaluationEvent event = new EvaluationEvent(featureFlag);
@@ -233,7 +233,7 @@ private void publishTelemetryIfEnabled(EvaluationEvent event) {
233233

234234
private Mono<EvaluationEvent> assignAllocation(Mono<EvaluationEvent> monoEvent) {
235235
return monoEvent.map(event -> {
236-
Feature featureFlag = event.getFeature();
236+
FeatureDefinition featureFlag = event.getFeature();
237237

238238
if (featureFlag.getVariants() == null || featureFlag.getAllocation() == null) {
239239
return event;
@@ -249,7 +249,7 @@ private Mono<EvaluationEvent> assignAllocation(Mono<EvaluationEvent> monoEvent)
249249
}
250250

251251
private void assignDefaultDisabledReason(EvaluationEvent event) {
252-
Feature featureFlag = event.getFeature();
252+
FeatureDefinition featureFlag = event.getFeature();
253253
event.setReason(VariantAssignmentReason.DEFAULT_WHEN_DISABLED);
254254
if (event.getFeature().getAllocation() == null) {
255255
return;
@@ -270,7 +270,7 @@ private void assignDefaultEnabledVariant(EvaluationEvent event) {
270270
}
271271
this.assignVariantOverride(event.getFeature().getVariants(),
272272
event.getFeature().getAllocation().getDefaultWhenEnabled(), true, event);
273-
Feature featureFlag = event.getFeature();
273+
FeatureDefinition featureFlag = event.getFeature();
274274

275275
if (featureFlag.getAllocation() != null) {
276276
event.setVariant(
@@ -280,7 +280,7 @@ private void assignDefaultEnabledVariant(EvaluationEvent event) {
280280
}
281281

282282
private void assignVariant(EvaluationEvent event) {
283-
Feature featureFlag = event.getFeature();
283+
FeatureDefinition featureFlag = event.getFeature();
284284
if (featureFlag.getVariants().size() == 0 || featureFlag.getAllocation() == null) {
285285
return;
286286
}
@@ -376,7 +376,7 @@ private void assignVariantOverride(List<VariantReference> variants, String defau
376376
}
377377

378378
private Mono<EvaluationEvent> checkFeatureFilters(EvaluationEvent event, Object featureContext) {
379-
Feature featureFlag = event.getFeature();
379+
FeatureDefinition featureFlag = event.getFeature();
380380
Conditions conditions = featureFlag.getConditions();
381381
List<FeatureFilterEvaluationContext> featureFilters = conditions.getClientFilters();
382382

@@ -405,7 +405,7 @@ private Mono<EvaluationEvent> checkFeatureFilters(EvaluationEvent event, Object
405405
return Flux.merge(filterResults).reduce((a, b) -> a || b).single().map(result -> event.setEnabled(result));
406406
}
407407

408-
private Variant variantNameToVariant(Feature featureFlag, String variantName) {
408+
private Variant variantNameToVariant(FeatureDefinition featureFlag, String variantName) {
409409
for (VariantReference variant : featureFlag.getVariants()) {
410410
if (variant.getName().equals(variantName)) {
411411
return new Variant(variantName, variant.getConfigurationValue());

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/filters/TargetingFilter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ public class TargetingFilter implements FeatureFilter, ContextualFeatureFilter {
3636
/**
3737
* users field in the filter
3838
*/
39-
protected static final String USERS = "Users";
39+
private static final String USERS = "Users";
4040

4141
/**
4242
* groups field in the filter
4343
*/
44-
protected static final String GROUPS = "Groups";
44+
private static final String GROUPS = "Groups";
4545

4646
/**
4747
* Audience in the filter
4848
*/
49-
protected static final String AUDIENCE = "Audience";
49+
private static final String AUDIENCE = "Audience";
5050

5151
/**
5252
* Audience that always returns false
@@ -56,7 +56,7 @@ public class TargetingFilter implements FeatureFilter, ContextualFeatureFilter {
5656
/**
5757
* Error message for when the total Audience value is greater than 100 percent.
5858
*/
59-
protected static final String OUT_OF_RANGE = "The value is out of the accepted range.";
59+
private static final String OUT_OF_RANGE = "The value is out of the accepted range.";
6060

6161
private static final String REQUIRED_PARAMETER = "Value cannot be null.";
6262

@@ -69,12 +69,12 @@ public class TargetingFilter implements FeatureFilter, ContextualFeatureFilter {
6969
/**
7070
* Accessor for identifying the current user/group when evaluating
7171
*/
72-
protected final TargetingContextAccessor contextAccessor;
72+
private final TargetingContextAccessor contextAccessor;
7373

7474
/**
7575
* Options for evaluating the filter
7676
*/
77-
protected final TargetingEvaluationOptions options;
77+
private final TargetingEvaluationOptions options;
7878

7979
/**
8080
* Filter for targeting a user/group/percentage of users.

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/implementation/FeatureManagementProperties.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import org.springframework.boot.context.properties.ConfigurationProperties;
99

10-
import com.azure.spring.cloud.feature.management.models.Feature;
10+
import com.azure.spring.cloud.feature.management.models.FeatureDefinition;
1111
import com.fasterxml.jackson.annotation.JsonProperty;
1212
import com.fasterxml.jackson.databind.ObjectMapper;
1313

@@ -20,11 +20,11 @@ public class FeatureManagementProperties {
2020
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
2121

2222
@JsonProperty("feature-flags")
23-
private List<Feature> featureFlags;
23+
private List<FeatureDefinition> featureFlags;
2424

2525
//private List<Feature> convertedFeatureFlags;
2626

27-
public List<Feature> getFeatureFlags() {
27+
public List<FeatureDefinition> getFeatureFlags() {
2828
return featureFlags;
2929
}
3030

@@ -33,19 +33,19 @@ public List<Feature> getFeatureFlags() {
3333
*
3434
* @param featureFlags the feature flags to set
3535
*/
36-
public void setFeatureFlags(List<Feature> featureFlags) {
36+
public void setFeatureFlags(List<FeatureDefinition> featureFlags) {
3737
if (featureFlags == null || featureFlags.isEmpty()) {
3838
this.featureFlags = List.of();
3939
return;
4040
}
4141

4242
// Check if the first element is a Feature instance to determine if we need conversion
43-
if (featureFlags.get(0) instanceof Feature) {
44-
List<Feature> features = new ArrayList<>();
43+
if (featureFlags.get(0) instanceof FeatureDefinition) {
44+
List<FeatureDefinition> features = new ArrayList<>();
4545
for (Object flag : featureFlags) {
4646
// This should always be true based on our check, but we verify each element to be safe
47-
if (flag instanceof Feature) {
48-
features.add((Feature) flag);
47+
if (flag instanceof FeatureDefinition) {
48+
features.add((FeatureDefinition) flag);
4949
}
5050
}
5151

@@ -56,9 +56,9 @@ public void setFeatureFlags(List<Feature> featureFlags) {
5656
}
5757

5858
// Convert the feature flags to the correct type
59-
List<Feature> convertedFlags = new ArrayList<>();
59+
List<FeatureDefinition> convertedFlags = new ArrayList<>();
6060
for (Object feature : featureFlags) {
61-
Feature convertedFeature = OBJECT_MAPPER.convertValue(feature, Feature.class);
61+
FeatureDefinition convertedFeature = OBJECT_MAPPER.convertValue(feature, FeatureDefinition.class);
6262
convertedFlags.add(convertedFeature);
6363
}
6464
this.featureFlags = convertedFlags;

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/implementation/models/Recurrence.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,48 @@
77

88
/**
99
* A recurrence definition describing how time window recurs
10-
* */
10+
*/
1111
@JsonIgnoreProperties(ignoreUnknown = true)
1212
public class Recurrence {
1313
/**
1414
* The recurrence pattern specifying how often the time window repeats
15-
* */
15+
*/
1616
private RecurrencePattern pattern;
17+
1718
/**
1819
* The recurrence range specifying how long the recurrence pattern repeats
19-
* */
20+
*/
2021
private RecurrenceRange range;
2122

2223
/**
2324
* @return the recurrence pattern specifying how often the time window repeats
24-
* */
25+
*/
2526
public RecurrencePattern getPattern() {
2627
return pattern;
2728
}
2829

2930
/**
3031
* @param pattern the recurrence pattern to be set
31-
* */
32-
public void setPattern(RecurrencePattern pattern) {
32+
* @return the updated Recurrence object
33+
*/
34+
public Recurrence setPattern(RecurrencePattern pattern) {
3335
this.pattern = pattern;
36+
return this;
3437
}
3538

3639
/**
3740
* @return the recurrence range specifying how long the recurrence pattern repeats
38-
* */
41+
*/
3942
public RecurrenceRange getRange() {
4043
return range;
4144
}
4245

4346
/**
4447
* @param range the recurrence range to be set
45-
* */
46-
public void setRange(RecurrenceRange range) {
48+
* @return the updated Recurrence object
49+
*/
50+
public Recurrence setRange(RecurrenceRange range) {
4751
this.range = range;
52+
return this;
4853
}
4954
}

sdk/spring/spring-cloud-azure-feature-management/src/main/java/com/azure/spring/cloud/feature/management/implementation/models/RecurrencePattern.java

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/**
1515
* The recurrence pattern specifying how often the time window repeats
16-
* */
16+
*/
1717
@JsonIgnoreProperties(ignoreUnknown = true)
1818
public class RecurrencePattern {
1919
/**
@@ -22,8 +22,8 @@ public class RecurrencePattern {
2222
private RecurrencePatternType type = RecurrencePatternType.DAILY;
2323

2424
/**
25-
* The number of units between occurrences, where units can be in days, weeks, months, or years,
26-
* depending on the pattern type. Default value is 1
25+
* The number of units between occurrences, where units can be in days, weeks, months, or years, depending on the
26+
* pattern type. Default value is 1
2727
*/
2828
private Integer interval = 1;
2929

@@ -34,60 +34,66 @@ public class RecurrencePattern {
3434

3535
/**
3636
* The first day of the week
37-
* */
37+
*/
3838
private DayOfWeek firstDayOfWeek = DayOfWeek.SUNDAY;
3939

4040
/**
4141
* @return the recurrence pattern type
42-
* */
42+
*/
4343
public RecurrencePatternType getType() {
4444
return type;
4545
}
4646

4747
/**
4848
* @param type pattern type to be set
49+
* @return the updated RecurrencePattern object
4950
* @throws IllegalArgumentException if type is invalid
50-
* */
51-
public void setType(String type) throws IllegalArgumentException {
51+
*/
52+
public RecurrencePattern setType(String type) throws IllegalArgumentException {
5253
try {
5354
this.type = RecurrencePatternType.valueOf(type.toUpperCase());
5455
} catch (final IllegalArgumentException e) {
5556
throw new IllegalArgumentException(
56-
String.format(RecurrenceConstants.INVALID_VALUE, "Recurrence.Pattern.Type", Arrays.toString(RecurrencePatternType.values())));
57+
String.format(RecurrenceConstants.INVALID_VALUE, "Recurrence.Pattern.Type",
58+
Arrays.toString(RecurrencePatternType.values())));
5759
}
60+
return this;
5861
}
5962

6063
/**
6164
* @return the number of units between occurrences
62-
* */
65+
*/
6366
public Integer getInterval() {
6467
return interval;
6568
}
6669

6770
/**
6871
* @param interval the time units to be set
72+
* @return the updated RecurrencePattern object
6973
* @throws IllegalArgumentException if interval is invalid
70-
* */
71-
public void setInterval(Integer interval) throws IllegalArgumentException {
74+
*/
75+
public RecurrencePattern setInterval(Integer interval) throws IllegalArgumentException {
7276
if (interval == null || interval <= 0) {
7377
throw new IllegalArgumentException(
7478
String.format(RecurrenceConstants.OUT_OF_RANGE, "Recurrence.Pattern.Interval"));
7579
}
7680
this.interval = interval;
81+
return this;
7782
}
7883

7984
/**
8085
* @return the days of the week on which the time window occurs
81-
* */
86+
*/
8287
public List<DayOfWeek> getDaysOfWeek() {
8388
return daysOfWeek;
8489
}
8590

8691
/**
8792
* @param daysOfWeek the days that time window occurs
93+
* @return the updated RecurrencePattern object
8894
* @throws IllegalArgumentException if daysOfWeek is null/empty, or has invalid value
89-
* */
90-
public void setDaysOfWeek(List<String> daysOfWeek) throws IllegalArgumentException {
95+
*/
96+
public RecurrencePattern setDaysOfWeek(List<String> daysOfWeek) throws IllegalArgumentException {
9197
if (daysOfWeek == null || daysOfWeek.size() == 0) {
9298
throw new IllegalArgumentException(
9399
String.format(RecurrenceConstants.REQUIRED_PARAMETER, "Recurrence.Pattern.DaysOfWeek"));
@@ -99,22 +105,25 @@ public void setDaysOfWeek(List<String> daysOfWeek) throws IllegalArgumentExcepti
99105
}
100106
} catch (final IllegalArgumentException e) {
101107
throw new IllegalArgumentException(
102-
String.format(RecurrenceConstants.INVALID_VALUE, "Recurrence.Pattern.DaysOfWeek", Arrays.toString(DayOfWeek.values())));
108+
String.format(RecurrenceConstants.INVALID_VALUE, "Recurrence.Pattern.DaysOfWeek",
109+
Arrays.toString(DayOfWeek.values())));
103110
}
111+
return this;
104112
}
105113

106114
/**
107115
* @return the first day of the week
108-
* */
116+
*/
109117
public DayOfWeek getFirstDayOfWeek() {
110118
return firstDayOfWeek;
111119
}
112120

113121
/**
114122
* @param firstDayOfWeek the first day of the week
123+
* @return the updated RecurrencePattern object
115124
* @throws IllegalArgumentException if firstDayOfWeek is invalid
116-
* */
117-
public void setFirstDayOfWeek(String firstDayOfWeek) throws IllegalArgumentException {
125+
*/
126+
public RecurrencePattern setFirstDayOfWeek(String firstDayOfWeek) throws IllegalArgumentException {
118127
if (firstDayOfWeek == null) {
119128
throw new IllegalArgumentException(
120129
String.format(RecurrenceConstants.REQUIRED_PARAMETER, "Recurrence.Pattern.FirstDayOfWeek"));
@@ -124,7 +133,9 @@ public void setFirstDayOfWeek(String firstDayOfWeek) throws IllegalArgumentExcep
124133
this.firstDayOfWeek = DayOfWeek.valueOf(firstDayOfWeek.toUpperCase());
125134
} catch (final IllegalArgumentException e) {
126135
throw new IllegalArgumentException(
127-
String.format(RecurrenceConstants.INVALID_VALUE, "Recurrence.Pattern.FirstDayOfWeek", Arrays.toString(DayOfWeek.values())));
136+
String.format(RecurrenceConstants.INVALID_VALUE, "Recurrence.Pattern.FirstDayOfWeek",
137+
Arrays.toString(DayOfWeek.values())));
128138
}
139+
return this;
129140
}
130141
}

0 commit comments

Comments
 (0)