use of com.epam.pipeline.entity.user.CustomControl in project cloud-pipeline by epam.
the class UserManager method getUserControls.
/**
* Reads file with control setting from disk and resolves settings applied to current user.
* @return {@link List} of {@link CustomControl} that should be applied to current user
*/
public List<CustomControl> getUserControls() {
PipelineUser currentUser = authManager.getCurrentUser();
if (currentUser == null) {
return Collections.emptyList();
}
List<ControlEntry> settings = preferenceManager.getPreference(SystemPreferences.UI_CONTROLS_SETTINGS);
if (settings == null) {
return Collections.emptyList();
}
Set<String> authorities = currentUser.getAuthorities();
return settings.stream().map(entry -> {
Map<String, String> userSettings = entry.getUserSettings().entrySet().stream().filter(authEntry -> authorities.contains(authEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
// if no setting found or settings are ambiguous (more than one are present)
if (MapUtils.isEmpty(userSettings) || userSettings.size() > 1) {
return new CustomControl(entry.getKey(), entry.getDefaultValue());
}
return new CustomControl(entry.getKey(), userSettings.values().stream().findFirst().orElse(entry.getDefaultValue()));
}).collect(Collectors.toList());
}
Aggregations