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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations