Search in sources :

Example 81 with Device

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

the class AdHocManagementService method setLight.

// === SET LIGHT ===
public void setLight(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final List<LightValue> lightValues, final String messageType, final int messagePriority) throws FunctionalException {
    LOGGER.debug("setLight called for device {} with organisation {}", deviceIdentification, organisationIdentification);
    this.findOrganisation(organisationIdentification);
    final Device device = this.findActiveDevice(deviceIdentification);
    final List<org.opensmartgridplatform.dto.valueobjects.LightValueDto> lightValuesDto = this.domainCoreMapper.mapAsList(lightValues, org.opensmartgridplatform.dto.valueobjects.LightValueDto.class);
    final LightValueMessageDataContainerDto lightValueMessageDataContainer = new LightValueMessageDataContainerDto(lightValuesDto);
    this.osgpCoreRequestMessageSender.send(new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, lightValueMessageDataContainer), messageType, messagePriority, device.getIpAddress());
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) CdmaDevice(org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) LightValueMessageDataContainerDto(org.opensmartgridplatform.dto.valueobjects.LightValueMessageDataContainerDto)

Example 82 with Device

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

the class AdHocManagementService method handleGetStatusResponse.

public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final GetStatusResponse response = new GetStatusResponse();
    response.setOsgpException(exception);
    response.setResult(deviceResult);
    if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
        LOGGER.error("Device Response not ok.", exception);
    } else {
        final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
        try {
            final Device dev = this.deviceDomainService.searchDevice(ids.getDeviceIdentification());
            if (LightMeasurementDevice.LMD_TYPE.equals(dev.getDeviceType())) {
                this.handleLmd(status, response);
            } else {
                this.handleSsld(ids.getDeviceIdentification(), status, DomainType.PUBLIC_LIGHTING, response);
            }
        } catch (final FunctionalException e) {
            LOGGER.error("Caught FunctionalException", e);
        }
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(response.getResult()).withOsgpException(response.getOsgpException()).withDataObject(response.getDeviceStatusMapped()).withMessagePriority(messagePriority).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.domain.shared.GetStatusResponse) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) CdmaDevice(org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 83 with Device

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

the class AdHocManagementService method updateLmdLastCommunicationTime.

private LightMeasurementDevice updateLmdLastCommunicationTime(final LightMeasurementDevice lmd) {
    final Instant now = Instant.now();
    LOGGER.info("Trying to update lastCommunicationTime for light measurement device: {} at DateTime: {}", lmd.getDeviceIdentification(), Date.from(now));
    lmd.setLastCommunicationTime(now);
    final Device gateway = lmd.getGatewayDevice();
    if (gateway != null) {
        this.rtuDeviceRepository.findById(gateway.getId()).ifPresent(rtu -> this.updateGatewayLastCommunicationTime(rtu, now));
    }
    return this.lightMeasurementDeviceRepository.save(lmd);
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) CdmaDevice(org.opensmartgridplatform.domain.core.valueobjects.CdmaDevice) RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) Instant(java.time.Instant)

Example 84 with Device

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

the class ScheduleManagementService method setLightSchedule.

// === SET LIGHT SCHEDULE ===
/**
 * Set a light schedule.
 */
public void setLightSchedule(final CorrelationIds ids, final Schedule schedule, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
    LOGGER.info("setSchedule called with organisation {} and device {}.", ids.getOrganisationIdentification(), ids.getDeviceIdentification());
    this.findOrganisation(ids.getOrganisationIdentification());
    final Device device = this.findActiveDevice(ids.getDeviceIdentification());
    final ScheduleDto scheduleDto = this.domainCoreMapper.map(schedule, ScheduleDto.class);
    this.osgpCoreRequestMessageSender.send(new RequestMessage(ids, scheduleDto), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) ScheduleDto(org.opensmartgridplatform.dto.valueobjects.ScheduleDto)

Example 85 with Device

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

the class ScheduleManagementService method setHasSchedule.

// === SET HAS SCHEDULE ===
/**
 * Method for setting the 'hasSchedule' boolean for a device.
 *
 * @throws FunctionalException
 */
public void setHasSchedule(final String deviceIdentification, final Boolean hasSchedule) throws FunctionalException {
    LOGGER.info("setHasSchedule called for device {} with hasSchedule: {}.", deviceIdentification, hasSchedule);
    final Device device = this.findActiveDevice(deviceIdentification);
    final Ssld ssld = this.findSsldForDevice(device);
    ssld.setHasSchedule(hasSchedule);
    this.ssldRepository.save(ssld);
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

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