public static DeviceTypeWithUsersAndDevicesVO convertWithDevicesAndUsers(DeviceType deviceType) { if (deviceType != null) { DeviceTypeVO vo1 = convertDeviceType(deviceType); DeviceTypeWithUsersAndDevicesVO vo = new DeviceTypeWithUsersAndDevicesVO(vo1); if (deviceType.getUsers() != null) { vo.setUsers(deviceType.getUsers().stream().map(User::convertToVo).collect(Collectors.toSet())); } else { vo.setUsers(Collections.emptySet()); } if (deviceType.getDevices() != null) { Set<DeviceVO> deviceList = deviceType.getDevices().stream().map(Device::convertToVo).collect(Collectors.toSet()); vo.setDevices(deviceList); } else { vo.setDevices(Collections.emptySet()); } return vo; } return null; }
@Transactional public boolean delete(long id, boolean force) { logger.trace("About to execute named query \"DeviceType.deleteById\" for "); DeviceTypeWithUsersAndDevicesVO deviceType = getWithDevices(id); if (!force && deviceType != null && !deviceType.getDevices().isEmpty()) { logger.warn("Failed to delete non-empty device type with id {}", id); String deviceIds = deviceType.getDevices().stream().map(DeviceVO::getDeviceId).collect(Collectors.joining(", ")); throw new HiveException(String.format(Messages.DEVICE_TYPE_DELETION_NOT_ALLOWED, deviceIds), SC_BAD_REQUEST); } int result = deviceTypeDao.deleteById(id); logger.debug("Deleted {} rows from DeviceType table", result); return result > 0; }
public DeviceTypeWithUsersAndDevicesVO(DeviceTypeVO vo) { setId(vo.getId()); setName(vo.getName()); setDescription(vo.getDescription()); setEntityVersion(vo.getEntityVersion()); }
}).map(deviceType -> { if (permittedNetworks != null && !permittedNetworks.isEmpty()) { Set<DeviceVO> allowed = deviceType.getDevices().stream() .filter(device -> permittedNetworks.contains(device.getNetworkId())) .collect(Collectors.toSet()); deviceType.setDevices(allowed);
@Transactional public DeviceTypeVO createOrUpdateDeviceTypeByUser(Optional<DeviceTypeVO> deviceTypeNullable, UserVO user) { //case device type is not defined if (deviceTypeNullable == null || deviceTypeNullable.orElse(null) == null) { return null; } DeviceTypeVO deviceType = deviceTypeNullable.orElse(null); Optional<DeviceTypeVO> storedOpt = findDeviceTypeByIdOrName(deviceType); if (storedOpt.isPresent()) { return storedOpt.get(); } else { if (deviceType.getId() != null) { throw new IllegalParametersException(Messages.INVALID_REQUEST_PARAMETERS); } if (user.isAdmin()) { DeviceTypeWithUsersAndDevicesVO newDeviceType = new DeviceTypeWithUsersAndDevicesVO(deviceType); deviceTypeDao.persist(newDeviceType); deviceType.setId(newDeviceType.getId()); } else { throw new ActionNotAllowedException(Messages.DEVICE_TYPE_CREATION_NOT_ALLOWED); } return deviceType; } }