Search in sources :

Example 76 with ResponseMessage

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

the class GetFirmwareFileResponseMessageProcessorTest method processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest.

@Test
void processMessageShouldSendNotOkResponseMessageContainingOriginalFirmwareUpdateRequest() throws OsgpException, JMSException {
    // arrange
    final FirmwareFileDto firmwareFileDto = this.setupFirmwareFileDto();
    final ResponseMessage responseMessage = this.setupResponseMessage(firmwareFileDto);
    final ObjectMessage message = new ObjectMessageBuilder().withMessageType(MessageType.GET_FIRMWARE_FILE.name()).withObject(responseMessage).build();
    final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
    final ArgumentCaptor<ResponseMessage> responseMessageArgumentCaptor = ArgumentCaptor.forClass(ResponseMessage.class);
    when(this.domainHelperService.findDlmsDevice(any(MessageMetadata.class))).thenReturn(this.dlmsDevice);
    when(this.dlmsConnectionManagerMock.getDlmsMessageListener()).thenReturn(this.dlmsMessageListenerMock);
    when(this.firmwareService.updateFirmware(same(this.dlmsConnectionManagerMock), same(this.dlmsDevice), same(firmwareFileDto), any(MessageMetadata.class))).thenThrow(new ProtocolAdapterException("Firmware file fw is not available."));
    // act
    this.getFirmwareFileResponseMessageProcessor.processMessageTasks(message.getObject(), messageMetadata, this.dlmsConnectionManagerMock);
    // assert
    verify(this.responseMessageSender, times(1)).send(responseMessageArgumentCaptor.capture());
    final ResponseMessage capturedValue = responseMessageArgumentCaptor.getValue();
    assertThat(((UpdateFirmwareRequestDto) capturedValue.getDataObject()).getFirmwareIdentification()).isSameAs(firmwareFileDto.getFirmwareIdentification());
    assertThat(capturedValue.getResult()).isSameAs(ResponseMessageResultType.NOT_OK);
    assertThat(capturedValue.bypassRetry()).isFalse();
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ObjectMessage(javax.jms.ObjectMessage) DlmsDeviceBuilder(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDeviceBuilder) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) Test(org.junit.jupiter.api.Test)

Example 77 with ResponseMessage

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

the class PublicLightingAdHocManagementEndpoint method getSetLightResponse.

@PayloadRoot(localPart = "SetLightAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public SetLightResponse getSetLightResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetLightAsyncRequest request) throws OsgpException {
    LOGGER.info("Get Set Light Response received from organisation: {} with correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
    final SetLightResponse response = new SetLightResponse();
    try {
        final ResponseMessage message = this.adHocManagementService.dequeueSetLightResponse(request.getAsyncRequest().getCorrelationUid());
        if (message != null) {
            response.setResult(OsgpResultType.fromValue(message.getResult().getValue()));
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) SetLightResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 78 with ResponseMessage

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

the class PublicLightingAdHocManagementEndpoint method getResumeScheduleResponse.

@PayloadRoot(localPart = "ResumeScheduleAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public ResumeScheduleResponse getResumeScheduleResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final ResumeScheduleAsyncRequest request) throws OsgpException {
    LOGGER.info("Resume Schedule Async Request received from organisation: {} for device: {}.", organisationIdentification, request.getAsyncRequest().getDeviceId());
    final ResumeScheduleResponse response = new ResumeScheduleResponse();
    try {
        final ResponseMessage message = this.adHocManagementService.dequeueResumeScheduleResponse(request.getAsyncRequest().getCorrelationUid());
        if (message != null) {
            response.setResult(OsgpResultType.fromValue(message.getResult().getValue()));
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResumeScheduleResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 79 with ResponseMessage

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

the class PublicLightingAdHocManagementEndpoint method getSetTransitionResponse.

@PayloadRoot(localPart = "SetTransitionAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public SetTransitionResponse getSetTransitionResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetTransitionAsyncRequest request) throws OsgpException {
    LOGGER.info("Get Set Transition Response received from organisation: {} with correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
    final SetTransitionResponse response = new SetTransitionResponse();
    try {
        final ResponseMessage message = this.adHocManagementService.dequeueSetTransitionResponse(request.getAsyncRequest().getCorrelationUid());
        if (message != null) {
            response.setResult(OsgpResultType.fromValue(message.getResult().getValue()));
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : SetTransitionResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 80 with ResponseMessage

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

the class PublicLightingAdHocManagementEndpoint method getGetStatusResponse.

@PayloadRoot(localPart = "GetStatusAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public GetStatusResponse getGetStatusResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetStatusAsyncRequest request) throws OsgpException {
    LOGGER.info("Get Status Response received from organisation: {} for correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
    final GetStatusResponse response = new GetStatusResponse();
    try {
        final ResponseMessage message = this.adHocManagementService.dequeueGetStatusResponse(request.getAsyncRequest().getCorrelationUid());
        if (message != null) {
            response.setResult(OsgpResultType.fromValue(message.getResult().getValue()));
            response.setStatus(this.adHocManagementMapper.map(message.getDataObject(), org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Status.class));
        }
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)144 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)78 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)66 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)33 JMSException (javax.jms.JMSException)29 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)23 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)20 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)20 ConstraintViolationException (javax.validation.ConstraintViolationException)19 Test (org.junit.jupiter.api.Test)19 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)16 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)12 ObjectMessage (javax.jms.ObjectMessage)9 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)8 Transactional (org.springframework.transaction.annotation.Transactional)5 ArrayList (java.util.ArrayList)4 Device (org.opensmartgridplatform.domain.core.entities.Device)4 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)4 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)4