class DeviceRegistrationMessageService {

    @Transactional(value = "transactionManager")
    public Device updateRegistrationData(final String deviceIdentification, final String ipAddress,
            final String deviceType, final boolean hasSchedule) throws UnknownHostException {

        LOGGER.info("updateRegistrationData called for device: {} ipAddress: {}, deviceType: {} hasSchedule: {}.",
                deviceIdentification, ipAddress, deviceType, hasSchedule);

        // Check for existing IP addresses
        this.deviceNetworkAddressCleanupService.clearDuplicateAddresses(deviceIdentification, ipAddress);

        Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
        if (device == null) {
            // Device does not exist yet, create without an owner.
            device = this.createNewDevice(deviceIdentification, deviceType);
        }

        final InetAddress inetAddress = InetAddress.getByName(ipAddress);
        device.updateRegistrationData(inetAddress, deviceType);
        device.updateConnectionDetailsToSuccess();

        return this.deviceRepository.save(device);
    }

}