Search in sources :

Example 6 with ProtocolResponseMessage

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

the class DeviceRequestMessageListener method sendException.

private void sendException(final ObjectMessage objectMessage, final Exception exception) {
    try {
        final ResponseMessageResultType result = ResponseMessageResultType.NOT_OK;
        final FunctionalException osgpException = new FunctionalException(FunctionalExceptionType.UNSUPPORTED_DEVICE_ACTION, ComponentType.PROTOCOL_IEC61850, exception);
        final Serializable dataObject = objectMessage.getObject();
        final MessageMetadata messageMetadata = MessageMetadata.fromMessage(objectMessage);
        final ProtocolResponseMessage protocolResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata.builder().withScheduled(false).build()).result(result).osgpException(osgpException).dataObject(dataObject).build();
        this.deviceResponseMessageSender.send(protocolResponseMessage);
    } catch (final Exception e) {
        LOGGER.error("Unexpected error during sendException(ObjectMessage, Exception)", e);
    }
}
Also used : Serializable(java.io.Serializable) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) JMSException(javax.jms.JMSException) NotSupportedException(org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)

Example 7 with ProtocolResponseMessage

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

the class DeviceResponseMessageService method handleMaxScheduleTimeExceeded.

private void handleMaxScheduleTimeExceeded(final ProtocolResponseMessage message, final FunctionalException maxScheduleTimeExceededException) {
    final ProtocolResponseMessage maxScheduleTimeExceededResponseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(message.messageMetadata()).result(ResponseMessageResultType.NOT_OK).osgpException(maxScheduleTimeExceededException).dataObject(message.getDataObject()).build();
    this.domainResponseMessageSender.send(maxScheduleTimeExceededResponseMessage);
}
Also used : ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 8 with ProtocolResponseMessage

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

the class GetFirmwareFileResponseMessageProcessor method createUpdateFirmwareRequestDto.

private UpdateFirmwareRequestDto createUpdateFirmwareRequestDto(final Serializable messageObject) {
    if (messageObject instanceof ProtocolResponseMessage) {
        final ProtocolResponseMessage protocolResponseMessage = (ProtocolResponseMessage) messageObject;
        final Serializable dataObject = protocolResponseMessage.getDataObject();
        if (dataObject instanceof FirmwareFileDto) {
            final FirmwareFileDto firmwareFileDto = (FirmwareFileDto) dataObject;
            return new UpdateFirmwareRequestDto(firmwareFileDto.getFirmwareIdentification(), protocolResponseMessage.getDeviceIdentification());
        }
    }
    LOGGER.warn("Firmware Identification not present.");
    return null;
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) Serializable(java.io.Serializable) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 9 with ProtocolResponseMessage

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

the class GetFirmwareFileMessageProcessor method sendSuccesResponse.

private void sendSuccesResponse(final MessageMetadata metadata, final ProtocolInfo protocolInfo, final FirmwareFileDto firmwareFileDto) {
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(metadata).result(ResponseMessageResultType.OK).osgpException(null).dataObject(firmwareFileDto).build();
    this.protocolResponseMessageSender.send(responseMessage, DeviceFunction.GET_FIRMWARE_FILE.name(), protocolInfo, metadata);
}
Also used : ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)

Example 10 with ProtocolResponseMessage

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

the class DeviceResponseMessageServiceTest method testProcessScheduledMessageSuccess.

/**
 * test processMessage with a scheduled task that has been successful
 */
@Test
public void testProcessScheduledMessageSuccess() {
    final ProtocolResponseMessage message = new ProtocolResponseMessage.Builder().messageMetadata(MESSAGE_METADATA.builder().withScheduled(true).build()).result(ResponseMessageResultType.OK).dataObject(DATA_OBJECT).build();
    final ScheduledTask scheduledTask = new ScheduledTask(MESSAGE_METADATA, DOMAIN, DOMAIN_VERSION, DATA_OBJECT, SCHEDULED_TIME);
    scheduledTask.setPending();
    when(this.scheduledTaskService.findByCorrelationUid(anyString())).thenReturn(scheduledTask);
    this.deviceResponseMessageService.processMessage(message);
    // check if message is send and task is deleted
    verify(this.domainResponseMessageSender).send(message);
    verify(this.scheduledTaskService).deleteScheduledTask(scheduledTask);
}
Also used : ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ScheduledTask(org.opensmartgridplatform.domain.core.entities.ScheduledTask) Test(org.junit.jupiter.api.Test)

Aggregations

ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)47 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)18 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)17 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)14 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)13 JMSException (javax.jms.JMSException)12 Serializable (java.io.Serializable)6 IOException (java.io.IOException)5 Test (org.junit.jupiter.api.Test)5 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)4 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)3 ScheduledTask (org.opensmartgridplatform.domain.core.entities.ScheduledTask)3 NotSupportedException (org.opensmartgridplatform.shared.exceptionhandling.NotSupportedException)3 RetryHeader (org.opensmartgridplatform.shared.infra.jms.RetryHeader)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse)2 ConfigurationDto (org.opensmartgridplatform.dto.valueobjects.ConfigurationDto)2 FirmwareFileDto (org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto)2 FirmwareVersionDto (org.opensmartgridplatform.dto.valueobjects.FirmwareVersionDto)2