Search in sources :

Example 86 with Device

use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.

the class BaseTask method findDevices.

/**
 * Try to find all devices which are not 'in maintenance' for a list of device models.
 */
protected List<Device> findDevices(final List<DeviceModel> deviceModels, final String deviceType) {
    LOGGER.info("Trying to find devices for device models for manufacturer...");
    final List<Device> devices = new ArrayList<>();
    for (final DeviceModel deviceModel : deviceModels) {
        final List<Device> devsInUse = this.deviceRepository.findByDeviceModelAndDeviceTypeAndInMaintenanceAndDeviceLifecycleStatus(deviceModel, deviceType, false, DeviceLifecycleStatus.IN_USE);
        final List<Device> devsRegistered = this.deviceRepository.findByDeviceModelAndDeviceTypeAndInMaintenanceAndDeviceLifecycleStatus(deviceModel, deviceType, false, DeviceLifecycleStatus.REGISTERED);
        devices.addAll(devsInUse);
        devices.addAll(devsRegistered);
    }
    if (devices.isEmpty()) {
        LOGGER.warn("No devices found for device models for manufacturer");
    } else {
        LOGGER.info("{} devices found for device models for manufacturer", devices.size());
        for (final Device device : devices) {
            LOGGER.info(" device: {}", device.getDeviceIdentification());
        }
    }
    return devices;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) ArrayList(java.util.ArrayList)

Example 87 with Device

use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.

the class BaseTask method getGatewayLastCommunicationTime.

private long getGatewayLastCommunicationTime(final LightMeasurementDevice lightMeasurementDevice, final long valueForMissingTime) {
    final Device gatewayDevice = lightMeasurementDevice.getGatewayDevice();
    if (gatewayDevice == null) {
        return valueForMissingTime;
    }
    final long lastSuccessFullConnectionTimestampGateway = getTime(gatewayDevice.getLastSuccessfulConnectionTimestamp(), valueForMissingTime);
    final long lastCommunicationTimeRtuGateway = this.rtuDeviceRepository.findById(gatewayDevice.getId()).map(rtu -> getTime(rtu.getLastCommunicationTime(), valueForMissingTime)).orElse(valueForMissingTime);
    return Long.max(lastSuccessFullConnectionTimestampGateway, lastCommunicationTimeRtuGateway);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DateTimeZone(org.joda.time.DateTimeZone) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Date(java.util.Date) RtuDeviceRepository(org.opensmartgridplatform.domain.core.repositories.RtuDeviceRepository) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EventRepository(org.opensmartgridplatform.domain.core.repositories.EventRepository) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) LightMeasurementDeviceRepository(org.opensmartgridplatform.domain.core.repositories.LightMeasurementDeviceRepository) DeviceLifecycleStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceLifecycleStatus) Map(java.util.Map) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DeviceModelRepository(org.opensmartgridplatform.domain.core.repositories.DeviceModelRepository) ManufacturerRepository(org.opensmartgridplatform.domain.core.repositories.ManufacturerRepository) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) Logger(org.slf4j.Logger) Predicate(java.util.function.Predicate) Collection(java.util.Collection) DateTime(org.joda.time.DateTime) Set(java.util.Set) DeviceRepository(org.opensmartgridplatform.domain.core.repositories.DeviceRepository) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) OsgpCoreRequestMessageSender(org.opensmartgridplatform.adapter.domain.publiclighting.infra.jms.core.OsgpCoreRequestMessageSender) Device(org.opensmartgridplatform.domain.core.entities.Device) CollectionUtils(org.springframework.util.CollectionUtils) DomainTypeDto(org.opensmartgridplatform.dto.valueobjects.DomainTypeDto) Comparator(java.util.Comparator) OsgpSystemCorrelationUid(org.opensmartgridplatform.adapter.domain.publiclighting.application.valueobjects.OsgpSystemCorrelationUid) DeviceFunction(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunction) MessagePriorityEnum(org.opensmartgridplatform.shared.wsheaderattribute.priority.MessagePriorityEnum) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device)

Example 88 with Device

use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.

the class SetEncryptionKeyExchangeOnGMeterDataConverter method convert.

@Override
public GMeterInfoDto convert(final SetEncryptionKeyExchangeOnGMeterRequestData value, final SmartMeter smartMeter) throws FunctionalException {
    final SmartMeter gasDevice = this.domainHelperService.findSmartMeter(value.getDeviceIdentification());
    final Device gatewayDevice = gasDevice.getGatewayDevice();
    if (gatewayDevice == null) {
        /*
       * For now throw a FunctionalException, based on the same reasoning
       * as with the channel a couple of lines up. As soon as we have
       * scenario's with direct communication with gas meters this will
       * have to be changed.
       */
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have an energy meter as gateway device."));
    }
    return new GMeterInfoDto(gasDevice.getChannel(), gasDevice.getDeviceIdentification());
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) GMeterInfoDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GMeterInfoDto) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 89 with Device

use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.

the class MonitoringService method requestActualMeterReads.

public void requestActualMeterReads(final MessageMetadata messageMetadata, final ActualMeterReadsQuery actualMeterReadsQuery) throws FunctionalException {
    LOGGER.info("requestActualMeterReads for organisationIdentification: {} for deviceIdentification: {}", messageMetadata.getOrganisationIdentification(), messageMetadata.getDeviceIdentification());
    final SmartMeter smartMeter = this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());
    if (actualMeterReadsQuery.isMbusDevice()) {
        if (smartMeter.getChannel() == null) {
            /*
         * For now, throw a FunctionalException. As soon as we can
         * communicate with some types of gas meters directly, and not
         * through an M-Bus port of an energy meter, this will have to
         * be changed.
         */
            throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have a channel configured."));
        }
        final Device gatewayDevice = smartMeter.getGatewayDevice();
        if (gatewayDevice == null) {
            /*
         * For now throw a FunctionalException, based on the same
         * reasoning as with the channel a couple of lines up. As soon
         * as we have scenario's with direct communication with gas
         * meters this will have to be changed.
         */
            throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.DOMAIN_SMART_METERING, new AssertionError("Meter for gas reads should have an energy meter as gateway device."));
        }
        final ActualMeterReadsQueryDto requestDto = new ActualMeterReadsQueryDto(ChannelDto.fromNumber(smartMeter.getChannel()));
        this.osgpCoreRequestMessageSender.send(requestDto, messageMetadata.builder().withDeviceIdentification(gatewayDevice.getDeviceIdentification()).withIpAddress(gatewayDevice.getIpAddress()).withNetworkSegmentIds(gatewayDevice.getBtsId(), gatewayDevice.getCellId()).build());
    } else {
        this.osgpCoreRequestMessageSender.send(new ActualMeterReadsQueryDto(), messageMetadata.builder().withIpAddress(smartMeter.getIpAddress()).withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()).build());
    }
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) ActualMeterReadsQueryDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActualMeterReadsQueryDto) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 90 with Device

use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.

the class AddDeviceSteps method findDeviceByDeviceIdentification.

private Device findDeviceByDeviceIdentification(final String deviceIdentification) {
    final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
    assertThat(device).as("Device must exist for identification " + deviceIdentification).isNotNull();
    return device;
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

Aggregations

Device (org.opensmartgridplatform.domain.core.entities.Device)179 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)49 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)36 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)35 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)32 Test (org.junit.jupiter.api.Test)27 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)27 Transactional (org.springframework.transaction.annotation.Transactional)24 Then (io.cucumber.java.en.Then)21 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)18 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)17 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)15 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)12 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)11 Date (java.util.Date)10 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9