Search in sources :

Example 6 with UserInfo

use of org.usermanagement.model.UserInfo in project open-kilda by telstra.

the class UserService method assignUserByRoleId.

/**
 * Assign user by role id.
 *
 * @param roleId the role id
 * @param role the role
 * @return the role
 */
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Role assignUserByRoleId(final Long roleId, final Role role) {
    RoleEntity roleEntity = roleRepository.findByRoleId(roleId);
    if (ValidatorUtil.isNull(roleEntity)) {
        LOGGER.warn("Role with role id '" + roleId + "' not found. Error: " + messageUtil.getAttributeInvalid("role_id", roleId + ""));
        throw new RequestValidationException(messageUtil.getAttributeInvalid("role_id", roleId + ""));
    }
    roleEntity.getUsers().clear();
    if (role.getUserInfo() != null) {
        for (UserInfo user : role.getUserInfo()) {
            UserEntity userEntity = userRepository.findByUserId(user.getUserId());
            roleEntity.getUsers().add(userEntity);
        }
    }
    roleEntity = roleRepository.save(roleEntity);
    activityLogger.log(ActivityType.ASSIGN_USERS_BY_ROLE, roleEntity.getName());
    LOGGER.info("Users assigned with role successfully (role id: " + roleId + ")");
    return RoleConversionUtil.toRole(roleEntity, false, true);
}
Also used : RoleEntity(org.usermanagement.dao.entity.RoleEntity) UserInfo(org.usermanagement.model.UserInfo) RequestValidationException(org.usermanagement.exception.RequestValidationException) UserEntity(org.usermanagement.dao.entity.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with UserInfo

use of org.usermanagement.model.UserInfo in project open-kilda by telstra.

the class FlowService method getAllFlows.

/**
 * get All Flows.
 *
 * @return SwitchRelationData
 */
public List<FlowInfo> getAllFlows(List<String> statuses, boolean controller) {
    List<FlowInfo> flows = new ArrayList<FlowInfo>();
    if (!CollectionUtil.isEmpty(statuses)) {
        statuses = statuses.stream().map((status) -> status.toLowerCase()).collect(Collectors.toList());
    }
    if (CollectionUtil.isEmpty(statuses) || statuses.contains("active")) {
        flows = flowsIntegrationService.getFlows();
        if (flows == null) {
            flows = new ArrayList<FlowInfo>();
        }
    }
    if (!controller) {
        if (storeService.getLinkStoreConfig().getUrls().size() > 0) {
            try {
                UserInfo userInfo = userService.getLoggedInUserInfo();
                if (userInfo.getPermissions().contains(IConstants.Permission.FW_FLOW_INVENTORY)) {
                    List<InventoryFlow> inventoryFlows = new ArrayList<InventoryFlow>();
                    String status = "";
                    for (String statusObj : statuses) {
                        if (StringUtil.isNullOrEmpty(status)) {
                            status += statusObj;
                        } else {
                            status += "," + statusObj;
                        }
                    }
                    inventoryFlows = flowStoreService.getFlowsWithParams(status);
                    processInventoryFlow(flows, inventoryFlows);
                }
            } catch (Exception ex) {
                LOGGER.error("Error occurred while retrieving flows from store", ex);
            }
        }
    }
    return flows;
}
Also used : FlowInfo(org.openkilda.model.FlowInfo) InventoryFlow(org.openkilda.integration.source.store.dto.InventoryFlow) ArrayList(java.util.ArrayList) UserInfo(org.usermanagement.model.UserInfo) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) IntegrationException(org.openkilda.integration.exception.IntegrationException) RequestValidationException(org.usermanagement.exception.RequestValidationException) AccessDeniedException(java.nio.file.AccessDeniedException)

Example 8 with UserInfo

use of org.usermanagement.model.UserInfo in project open-kilda by telstra.

the class UserController method saveOrUpdateSettings.

/**
 * Save or update settings.
 *
 * @param data the data
 * @return the string
 */
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/settings", method = RequestMethod.PATCH)
public String saveOrUpdateSettings(@RequestBody final String data) {
    UserInfo userInfo = new UserInfo();
    userInfo.setData(data);
    userInfo.setUserId(serverContext.getRequestContext().getUserId());
    LOGGER.info("Save or update user settings. (userId: " + userInfo.getUserId() + ")");
    userService.saveOrUpdateSettings(userInfo);
    return data;
}
Also used : UserInfo(org.usermanagement.model.UserInfo) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with UserInfo

use of org.usermanagement.model.UserInfo in project open-kilda by telstra.

the class SwitchService method getSwitch.

/**
 * get All SwitchList.
 *
 * @return SwitchRelationData the switch info
 * @throws IntegrationException the integration exception
 */
public SwitchInfo getSwitch(final String switchId, boolean controller) throws IntegrationException {
    SwitchInfo switchInfo = null;
    try {
        switchInfo = switchIntegrationService.getSwitchesById(switchId);
    } catch (InvalidResponseException ex) {
        LOGGER.error("Error occurred while retrieving switches from controller", ex);
    }
    if (!controller) {
        try {
            UserInfo userInfo = userService.getLoggedInUserInfo();
            if (userInfo.getPermissions().contains(IConstants.Permission.SW_SWITCH_INVENTORY)) {
                if (storeService.getSwitchStoreConfig().getUrls().size() > 0) {
                    InventorySwitch inventorySwitch = switchStoreService.getSwitch(switchId);
                    if (inventorySwitch.getSwitchId() != null) {
                        switchInfo = processInventorySwitch(switchInfo, inventorySwitch);
                    } else {
                        SwitchDiscrepancy discrepancy = new SwitchDiscrepancy();
                        discrepancy.setControllerDiscrepancy(false);
                        discrepancy.setStatus(true);
                        discrepancy.setInventoryDiscrepancy(true);
                        SwitchStatus switchState = new SwitchStatus();
                        switchState.setControllerStatus(switchInfo.getState());
                        discrepancy.setStatusValue(switchState);
                        switchInfo.setDiscrepancy(discrepancy);
                    }
                }
            }
        } catch (Exception ex) {
            LOGGER.error("Error occurred while retrieving switches from store", ex);
            throw new StoreIntegrationException("Error occurred while retrieving switches from store");
        }
    }
    return switchInfo;
}
Also used : InventorySwitch(org.openkilda.integration.source.store.dto.InventorySwitch) SwitchDiscrepancy(org.openkilda.model.SwitchDiscrepancy) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) UserInfo(org.usermanagement.model.UserInfo) SwitchInfo(org.openkilda.model.SwitchInfo) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) SwitchStatus(org.openkilda.model.SwitchStatus) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) IntegrationException(org.openkilda.integration.exception.IntegrationException) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) RequestValidationException(org.usermanagement.exception.RequestValidationException) AccessDeniedException(java.nio.file.AccessDeniedException)

Example 10 with UserInfo

use of org.usermanagement.model.UserInfo in project open-kilda by telstra.

the class SwitchService method getSwitches.

/**
 * get All SwitchList.
 *
 * @return SwitchRelationData the switch info
 * @throws IntegrationException the integration exception
 */
public List<SwitchInfo> getSwitches(boolean storeConfigurationStatus, boolean controller) throws IntegrationException {
    List<SwitchInfo> switchInfo = switchIntegrationService.getSwitches();
    if (switchInfo == null) {
        switchInfo = new ArrayList<SwitchInfo>();
    }
    if (!controller) {
        try {
            UserInfo userInfo = userService.getLoggedInUserInfo();
            if (userInfo.getPermissions().contains(IConstants.Permission.SW_SWITCH_INVENTORY)) {
                if (storeConfigurationStatus && storeService.getSwitchStoreConfig().getUrls().size() > 0) {
                    List<InventorySwitch> inventorySwitches = new ArrayList<InventorySwitch>();
                    inventorySwitches = switchStoreService.getSwitches();
                    processInventorySwitch(switchInfo, inventorySwitches);
                }
            }
        } catch (Exception ex) {
            LOGGER.error("Error occurred while retrieving switches from store", ex);
        }
    }
    return switchInfo;
}
Also used : ArrayList(java.util.ArrayList) InventorySwitch(org.openkilda.integration.source.store.dto.InventorySwitch) UserInfo(org.usermanagement.model.UserInfo) SwitchInfo(org.openkilda.model.SwitchInfo) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException) IntegrationException(org.openkilda.integration.exception.IntegrationException) StoreIntegrationException(org.openkilda.integration.exception.StoreIntegrationException) RequestValidationException(org.usermanagement.exception.RequestValidationException) AccessDeniedException(java.nio.file.AccessDeniedException)

Aggregations

UserInfo (org.usermanagement.model.UserInfo)17 AccessDeniedException (java.nio.file.AccessDeniedException)6 RequestValidationException (org.usermanagement.exception.RequestValidationException)6 IntegrationException (org.openkilda.integration.exception.IntegrationException)4 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)4 UserEntity (org.usermanagement.dao.entity.UserEntity)4 ArrayList (java.util.ArrayList)3 HttpSession (javax.servlet.http.HttpSession)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 RoleEntity (org.usermanagement.dao.entity.RoleEntity)3 RequestContext (org.openkilda.auth.model.RequestContext)2 InvalidOtpException (org.openkilda.exception.InvalidOtpException)2 OtpRequiredException (org.openkilda.exception.OtpRequiredException)2 TwoFaKeyNotSetException (org.openkilda.exception.TwoFaKeyNotSetException)2 StoreIntegrationException (org.openkilda.integration.exception.StoreIntegrationException)2 InventoryFlow (org.openkilda.integration.source.store.dto.InventoryFlow)2 InventorySwitch (org.openkilda.integration.source.store.dto.InventorySwitch)2 FlowInfo (org.openkilda.model.FlowInfo)2 SwitchInfo (org.openkilda.model.SwitchInfo)2