String enabledAsStr = fileContent.getValue(getEnabledPropertyName(feature), null);
if (enabledAsStr != null) {
// new state instance
FeatureState state = new FeatureState(feature);
state.setEnabled(isTrue(enabledAsStr));
// active strategy (may be null)
String strategy = fileContent.getValue(getStrategyPropertyName(feature), null);
state.setStrategyId(strategy);
// all parameters
String paramPrefix = getParameterPropertyName(feature, "");
for (String key : fileContent.getKeysStartingWith(paramPrefix)) {
String id = key.substring(paramPrefix.length());
String value = fileContent.getValue(key, null);
state.setParameter(id, value);
}
/*
* Backwards compatibility: if there are users stored in the old format, add them to the corresponding property
*/
List<String> additionalUsers = toList(fileContent.getValue(getUsersPropertyName(feature), null));
if (!additionalUsers.isEmpty()) {
// join the users to one list and update the property
List<String> currentUsers = toList(state.getParameter(UsernameActivationStrategy.PARAM_USERS));
currentUsers.addAll(additionalUsers);
state.setParameter(UsernameActivationStrategy.PARAM_USERS, Strings.join(currentUsers, ","));
// we should set strategy id if it is not yet set
if (state.getStrategyId() == null) {
state.setStrategyId(UsernameActivationStrategy.ID);
}
}
return state;