Search in sources :

Example 1 with ControlEntry

use of com.epam.pipeline.entity.utils.ControlEntry 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());
}
Also used : CustomControl(com.epam.pipeline.entity.user.CustomControl) StringUtils(org.apache.commons.lang.StringUtils) DataStorageValidator(com.epam.pipeline.manager.datastorage.DataStorageValidator) MessageConstants(com.epam.pipeline.common.MessageConstants) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) CollectionUtils(org.apache.commons.collections4.CollectionUtils) NumberUtils(org.apache.commons.lang.math.NumberUtils) ArrayList(java.util.ArrayList) UserContext(com.epam.pipeline.security.UserContext) MessageHelper(com.epam.pipeline.common.MessageHelper) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) PipelineUserVO(com.epam.pipeline.controller.vo.PipelineUserVO) Map(java.util.Map) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) Role(com.epam.pipeline.entity.user.Role) MapUtils(org.apache.commons.collections4.MapUtils) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Collection(java.util.Collection) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Set(java.util.Set) ControlEntry(com.epam.pipeline.entity.utils.ControlEntry) Collectors(java.util.stream.Collectors) List(java.util.List) UserDao(com.epam.pipeline.dao.user.UserDao) AuthManager(com.epam.pipeline.manager.security.AuthManager) RoleDao(com.epam.pipeline.dao.user.RoleDao) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) PipelineUser(com.epam.pipeline.entity.user.PipelineUser) ControlEntry(com.epam.pipeline.entity.utils.ControlEntry) CustomControl(com.epam.pipeline.entity.user.CustomControl) ControlEntry(com.epam.pipeline.entity.utils.ControlEntry) Map(java.util.Map)

Aggregations

MessageConstants (com.epam.pipeline.common.MessageConstants)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 PipelineUserVO (com.epam.pipeline.controller.vo.PipelineUserVO)1 RoleDao (com.epam.pipeline.dao.user.RoleDao)1 UserDao (com.epam.pipeline.dao.user.UserDao)1 CustomControl (com.epam.pipeline.entity.user.CustomControl)1 DefaultRoles (com.epam.pipeline.entity.user.DefaultRoles)1 PipelineUser (com.epam.pipeline.entity.user.PipelineUser)1 Role (com.epam.pipeline.entity.user.Role)1 ControlEntry (com.epam.pipeline.entity.utils.ControlEntry)1 DataStorageValidator (com.epam.pipeline.manager.datastorage.DataStorageValidator)1 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)1 SystemPreferences (com.epam.pipeline.manager.preference.SystemPreferences)1 AuthManager (com.epam.pipeline.manager.security.AuthManager)1 UserContext (com.epam.pipeline.security.UserContext)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1