Search in sources :

Example 6 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method coupleLightMeasurementDeviceForSsld.

/**
 * Send request message to domain component to couple an SSLD with a light measurement device.
 *
 * @param organisationIdentification Organization issuing the request.
 * @param deviceIdentification The SSLD.
 * @param lightMeasurementDeviceIdentification The light measurement device.
 * @param messagePriority The priority of the message.
 * @return Correlation UID.
 * @throws FunctionalException In case the organization is not authorized or the SSLD or LMD can
 *     not be found.
 */
public String coupleLightMeasurementDeviceForSsld(final String organisationIdentification, final String deviceIdentification, final String lightMeasurementDeviceIdentification, final int messagePriority) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final Device device = this.domainHelperService.findDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.SET_LIGHT_MEASUREMENT_DEVICE);
    final Device lightMeasurementDevice = this.domainHelperService.findDevice(lightMeasurementDeviceIdentification);
    LOGGER.info("Found lightMeasurementDevice: {}", lightMeasurementDevice.getDeviceIdentification());
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final MessageMetadata deviceMessageMetadata = new Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.SET_LIGHT_MEASUREMENT_DEVICE.name()).withMessagePriority(messagePriority).build();
    final PublicLightingRequestMessage message = new PublicLightingRequestMessage.Builder().messageMetadata(deviceMessageMetadata).request(lightMeasurementDeviceIdentification).build();
    this.messageSender.send(message);
    return correlationUid;
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder) PublicLightingRequestMessage(org.opensmartgridplatform.adapter.ws.publiclighting.infra.jms.PublicLightingRequestMessage)

Example 7 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class ScheduleManagementService method enqueueSetLightSchedule.

public String enqueueSetLightSchedule(@Identification final String organisationIdentification, @Identification final String deviceIdentification, @Valid final Schedule schedule, final DateTime scheduledTime, final int messagePriority) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
    this.domainHelperService.isAllowed(organisation, device, DeviceFunction.SET_LIGHT_SCHEDULE);
    this.domainHelperService.isInMaintenance(device);
    LOGGER.debug("enqueueSetLightSchedule called with organisation {} and device {}", organisationIdentification, deviceIdentification);
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
    final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.SET_LIGHT_SCHEDULE.name()).withMessagePriority(messagePriority).withScheduleTime(scheduledTime == null ? null : scheduledTime.getMillis()).build();
    final PublicLightingRequestMessage message = new PublicLightingRequestMessage.Builder().messageMetadata(messageMetadata).request(schedule).build();
    this.messageSender.send(message);
    return correlationUid;
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) PublicLightingRequestMessage(org.opensmartgridplatform.adapter.ws.publiclighting.infra.jms.PublicLightingRequestMessage)

Example 8 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class ConfigurationServiceTest method getKeys.

@Test
void getKeys() throws FunctionalException {
    // SETUP
    when(this.domainHelperService.findSmartMeter(DEVICE_IDENTIFICATION)).thenReturn(device);
    // CALL
    this.instance.getKeys(messageMetadata, getKeysRequestData);
    // VERIFY
    final GetKeysRequestDto expectedRequestDto = new GetKeysRequestDto(Arrays.asList(SecretTypeDto.E_METER_AUTHENTICATION_KEY, SecretTypeDto.E_METER_MASTER_KEY));
    final MessageMetadata expectedMessageMetadata = messageMetadata.builder().withIpAddress(IP_ADDRESS).withNetworkSegmentIds(BASE_TRANSCEIVER_STATION_ID, CELL_ID).build();
    verify(this.osgpCoreRequestMessageSender).send(this.requestMessageCaptor.capture(), this.messageMetadataCaptor.capture());
    assertThat(this.requestMessageCaptor.getValue()).usingRecursiveComparison().isEqualTo(expectedRequestDto);
    assertThat(this.messageMetadataCaptor.getValue()).isEqualToComparingFieldByField(expectedMessageMetadata);
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) GetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetKeysRequestDto) Test(org.junit.jupiter.api.Test)

Example 9 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class RequestService method enqueueAndSendRequest.

public AsyncResponse enqueueAndSendRequest(final RequestMessageMetadata requestMessageMetadata, final Serializable requestData) throws FunctionalException {
    log.debug("{} called with organisation {} and device {}", requestMessageMetadata.getMessageType(), requestMessageMetadata.getOrganisationIdentification(), requestMessageMetadata.getDeviceIdentification());
    if (requestMessageMetadata.getDeviceFunction() != null) {
        this.checkAllowed(requestMessageMetadata.getOrganisationIdentification(), requestMessageMetadata.getDeviceIdentification(), requestMessageMetadata.getDeviceFunction());
    }
    final String correlationUid = this.correlationIdProviderService.getCorrelationId(requestMessageMetadata.getOrganisationIdentification(), requestMessageMetadata.getDeviceIdentification());
    final MessageMetadata messageMetadata = requestMessageMetadata.newMessageMetadata(correlationUid);
    final SmartMeteringRequestMessage message = SmartMeteringRequestMessage.newBuilder().messageMetadata(messageMetadata).request(requestData).build();
    this.smartMeteringRequestMessageSender.send(message);
    return this.createAsyncResponse(correlationUid, messageMetadata.getDeviceIdentification());
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) RequestMessageMetadata(org.opensmartgridplatform.adapter.ws.smartmetering.endpoints.RequestMessageMetadata) SmartMeteringRequestMessage(org.opensmartgridplatform.adapter.ws.smartmetering.infra.jms.SmartMeteringRequestMessage)

Example 10 with MessageMetadata

use of org.opensmartgridplatform.shared.infra.jms.MessageMetadata in project open-smart-grid-platform by OSGP.

the class MicrogridsGetDataRequestMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing microgrids get data request message");
    final MessageMetadata messageMetadata;
    final GetDataRequestDto getDataRequest;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        getDataRequest = (GetDataRequestDto) message.getObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        return;
    }
    final RequestMessageData requestMessageData = RequestMessageData.newBuilder().messageMetadata(messageMetadata).build();
    this.printDomainInfo(requestMessageData);
    final Iec61850DeviceResponseHandler iec61850DeviceResponseHandler = this.createIec61850DeviceResponseHandler(requestMessageData, message);
    final DeviceRequest.Builder deviceRequestBuilder = DeviceRequest.newBuilder().messageMetaData(messageMetadata);
    this.deviceService.getData(new GetDataDeviceRequest(deviceRequestBuilder, getDataRequest), iec61850DeviceResponseHandler);
}
Also used : Iec61850DeviceResponseHandler(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) GetDataRequestDto(org.opensmartgridplatform.dto.valueobjects.microgrids.GetDataRequestDto) GetDataDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.rtu.requests.GetDataDeviceRequest) JMSException(javax.jms.JMSException) DeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest) GetDataDeviceRequest(org.opensmartgridplatform.adapter.protocol.iec61850.device.rtu.requests.GetDataDeviceRequest) RequestMessageData(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)

Aggregations

MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)147 JMSException (javax.jms.JMSException)65 Device (org.opensmartgridplatform.domain.core.entities.Device)29 Test (org.junit.jupiter.api.Test)25 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)23 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)22 DeviceRequest (org.opensmartgridplatform.adapter.protocol.iec61850.device.DeviceRequest)20 RequestMessageData (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.RequestMessageData)20 Iec61850DeviceResponseHandler (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.Iec61850DeviceResponseHandler)20 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)19 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)18 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)14 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)14 ObjectMessage (javax.jms.ObjectMessage)13 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)13 Serializable (java.io.Serializable)12 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)12 UpdateFirmwareRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto)10