public boolean isNetworkExists(Long networkId) { return ofNullable(networkId) .map(id -> networkDao.find(id) != null) .orElse(false); }
private Optional<NetworkVO> findNetworkByIdOrName(NetworkVO network) { return ofNullable(network.getId()) .map(id -> ofNullable(networkDao.find(id))) .orElseGet(() -> networkDao.findFirstByName(network.getName())); } }
private Optional<NetworkVO> findNetworkByIdOrName(NetworkVO network) { return ofNullable(network.getId()) .map(id -> ofNullable(networkDao.find(id))) .orElseGet(() -> networkDao.findFirstByName(network.getName())); } }
/** * Revokes user access to given network * * @param userId id of user * @param networkId id of network */ @Transactional(propagation = Propagation.REQUIRED) public void unassignNetwork(@NotNull long userId, @NotNull long networkId) { UserVO existingUser = userDao.find(userId); if (existingUser == null) { logger.error("Can't unassign network with id {}: user {} not found", networkId, userId); throw new HiveException(String.format(Messages.USER_NOT_FOUND, userId), NOT_FOUND.getStatusCode()); } NetworkVO existingNetwork = networkDao.find(networkId); if (existingNetwork == null) { logger.error("Can't unassign user with id {}: network {} not found", userId, networkId); throw new HiveException(String.format(Messages.NETWORK_NOT_FOUND, networkId), NOT_FOUND.getStatusCode()); } userDao.unassignNetwork(existingUser, networkId); }
@Transactional public NetworkVO update(@NotNull Long networkId, NetworkUpdate networkUpdate) { NetworkVO existing = networkDao.find(networkId); if (existing == null) { throw new NoSuchElementException(String.format(Messages.NETWORK_NOT_FOUND, networkId)); } if (networkUpdate.getName().isPresent()){ existing.setName(networkUpdate.getName().get()); } if (networkUpdate.getDescription().isPresent()){ existing.setDescription(networkUpdate.getDescription().get()); } hiveValidator.validate(existing); return networkDao.merge(existing); }