use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class FlowService method getFlowById.
/**
* Flow by flow id.
*
* @param flowId
* the flow id
* @return the flow by id
* @throws AccessDeniedException the access denied exception
*/
public FlowInfo getFlowById(String flowId, boolean controller) throws AccessDeniedException {
FlowInfo flowInfo = new FlowInfo();
FlowV2 flow = null;
try {
flow = flowsIntegrationService.getFlowById(flowId);
} catch (InvalidResponseException ex) {
LOGGER.error("Error occurred while retrieving flows from controller", ex);
if (controller) {
throw new InvalidResponseException(ex.getCode(), ex.getResponse());
}
}
Map<String, String> csNames = switchIntegrationService.getSwitchNames();
if (flow != null) {
flowInfo = flowConverter.toFlowV2Info(flow, csNames);
}
UserInfo userInfo = userService.getLoggedInUserInfo();
try {
if (!controller && userInfo.getPermissions().contains(IConstants.Permission.FW_FLOW_INVENTORY)) {
if (storeService.getLinkStoreConfig().getUrls().size() > 0) {
InventoryFlow inventoryFlow = flowStoreService.getFlowById(flowId);
if (flow == null && inventoryFlow.getId() == null) {
throw new RequestValidationException("Can not get flow: Flow " + flowId + " not found");
} else if (flow != null && inventoryFlow.getId() != null) {
flowInfo.setState(inventoryFlow.getState());
FlowDiscrepancy discrepancy = new FlowDiscrepancy();
discrepancy.setControllerDiscrepancy(false);
if (flowInfo.getMaximumBandwidth() != (inventoryFlow.getMaximumBandwidth() == null ? 0 : inventoryFlow.getMaximumBandwidth())) {
discrepancy.setBandwidth(true);
FlowBandwidth flowBandwidth = new FlowBandwidth();
flowBandwidth.setControllerBandwidth(flow.getMaximumBandwidth());
flowBandwidth.setInventoryBandwidth(inventoryFlow.getMaximumBandwidth());
discrepancy.setBandwidthValue(flowBandwidth);
}
if (("UP".equalsIgnoreCase(flowInfo.getStatus()) && !"ACTIVE".equalsIgnoreCase(inventoryFlow.getState())) || ("DOWN".equalsIgnoreCase(flowInfo.getStatus()) && "ACTIVE".equalsIgnoreCase(inventoryFlow.getState()))) {
discrepancy.setStatus(true);
FlowState flowState = new FlowState();
flowState.setControllerState(flow.getStatus());
flowState.setInventoryState(inventoryFlow.getState());
discrepancy.setStatusValue(flowState);
}
flowInfo.setInventoryFlow(true);
flowInfo.setDiscrepancy(discrepancy);
} else if (inventoryFlow.getId() == null && flow != null) {
FlowDiscrepancy discrepancy = new FlowDiscrepancy();
discrepancy.setInventoryDiscrepancy(true);
discrepancy.setControllerDiscrepancy(false);
discrepancy.setStatus(true);
discrepancy.setBandwidth(true);
FlowBandwidth flowBandwidth = new FlowBandwidth();
flowBandwidth.setControllerBandwidth(flow.getMaximumBandwidth());
flowBandwidth.setInventoryBandwidth(0);
discrepancy.setBandwidthValue(flowBandwidth);
FlowState flowState = new FlowState();
flowState.setControllerState(flow.getStatus());
flowState.setInventoryState(null);
discrepancy.setStatusValue(flowState);
flowInfo.setDiscrepancy(discrepancy);
} else {
flowConverter.toFlowInfo(flowInfo, inventoryFlow, csNames);
}
}
}
if (flow == null) {
throw new RequestValidationException("Can not get flow: Flow " + flowId + " not found");
}
} catch (Exception ex) {
LOGGER.error("Error occurred while retrieving flows from store", ex);
throw new RequestValidationException(ex.getMessage());
}
return flowInfo;
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class SwitchService method saveOrUpdateSwitchName.
/**
* Save or update switch name.
*
* @param switchId the switch id
* @param switchName the switch name
* @return the SwitchInfo
*/
public SwitchInfo saveOrUpdateSwitchName(String switchId, String switchName) {
String storageType = applicationSettingService.getApplicationSetting(ApplicationSetting.SWITCH_NAME_STORAGE_TYPE);
if (storageType.equals(IConstants.StorageType.DATABASE_STORAGE.name())) {
SwitchNameEntity switchNameEntity = switchNameRepository.findBySwitchDpid(switchId);
if (switchNameEntity == null) {
switchNameEntity = new SwitchNameEntity();
}
switchNameEntity.setSwitchDpid(switchId);
switchNameEntity.setSwitchName(switchName);
switchNameEntity.setUpdatedDate(new Date());
switchNameRepository.save(switchNameEntity);
SwitchInfo switchInfo = new SwitchInfo();
switchInfo.setSwitchId(switchId);
switchInfo.setName(switchName);
return switchInfo;
} else {
throw new RequestValidationException("Storage-Type in Application Settings is not Database, " + "so switch name can not be updated");
}
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class RoleService method deleteRoleById.
/**
* Delete role by id.
*
* @param roleId the role id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public void deleteRoleById(final Long roleId) {
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 + ""));
}
Set<UserEntity> userEntityList = userRepository.findByRoles_roleId(roleId);
if (userEntityList.size() > 0) {
String users = "";
for (UserEntity userEntity : userEntityList) {
users += !"".equals(users) ? "," + userEntity.getName() : userEntity.getName();
}
LOGGER.warn("Role with role id '" + roleId + "' not allowed to delete. Error: " + messageUtil.getAttributeDeletionNotAllowed(roleEntity.getName(), users));
throw new RequestValidationException(messageUtil.getAttributeDeletionNotAllowed(roleEntity.getName(), users));
}
roleRepository.delete(roleEntity);
activityLogger.log(ActivityType.DELETE_ROLE, roleEntity.getName());
LOGGER.info("Role(roleId: " + roleId + ") deleted successfully.");
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class RoleService method getRolesById.
/**
* Gets the roles by id.
*
* @param roleIds the role ids
* @return the roles by id
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Set<RoleEntity> getRolesById(final List<Long> roleIds) {
Set<RoleEntity> roleEntities = new HashSet<>();
List<RoleEntity> roleEntityList = roleRepository.findAll();
for (Long roleId : roleIds) {
RoleEntity roleEntity = roleEntityList.parallelStream().filter((entity) -> entity.getRoleId().equals(roleId)).findFirst().orElse(null);
if (!ValidatorUtil.isNull(roleEntity)) {
roleEntities.add(roleEntity);
} else {
LOGGER.warn("Role with role id '" + roleId + "' not found. Error: " + messageUtil.getAttributeNotFound("roles"));
throw new RequestValidationException(messageUtil.getAttributeNotFound("roles"));
}
}
return roleEntities;
}
use of org.usermanagement.exception.RequestValidationException in project open-kilda by telstra.
the class RoleService method updateRole.
/**
* Update role.
*
* @param roleId the role id
* @param role the role
* @return the role
*/
@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
public Role updateRole(final Long roleId, final Role role) {
roleValidator.validateUpdateRole(role, roleId);
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 + ""));
}
if (role.getPermissionId() != null) {
roleEntity.getPermissions().clear();
for (Long permissionId : role.getPermissionId()) {
PermissionEntity permissionEntity = permissionRepository.findByPermissionId(permissionId);
if (permissionEntity != null) {
roleEntity.getPermissions().add(permissionEntity);
}
}
}
roleEntity = RoleConversionUtil.toUpateRoleEntity(role, roleEntity);
roleRepository.save(roleEntity);
activityLogger.log(ActivityType.UPDATE_ROLE, roleEntity.getName());
LOGGER.info("Role updated successfully (roleId: " + roleId + ")");
return RoleConversionUtil.toRole(roleEntity, true, false);
}
Aggregations