Search in sources :

Example 6 with FaultResponseParameterDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto in project open-smart-grid-platform by OSGP.

the class BundleResponseMessageProcessor method handleError.

@Override
protected void handleError(final Exception e, final MessageMetadata deviceMessageMetadata, final ResponseMessage responseMessage) throws FunctionalException {
    final OsgpException osgpException = this.ensureOsgpException(e);
    final BundleMessagesRequestDto bundleMessagesResponseDto = (BundleMessagesRequestDto) responseMessage.getDataObject();
    final List<ActionDto> actionList = bundleMessagesResponseDto.getActionList();
    for (final ActionDto action : actionList) {
        if (action.getResponse() == null) {
            final List<FaultResponseParameterDto> parameterList = new ArrayList<>();
            final FaultResponseParameterDto deviceIdentificationParameter = new FaultResponseParameterDto("deviceIdentification", deviceMessageMetadata.getDeviceIdentification());
            parameterList.add(deviceIdentificationParameter);
            action.setResponse(this.faultResponseForException(e, parameterList, "Unable to handle request"));
        }
    }
    this.bundleService.handleBundleResponse(deviceMessageMetadata, responseMessage.getResult(), osgpException, bundleMessagesResponseDto);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) BundleMessagesRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto) FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto) ArrayList(java.util.ArrayList) ActionDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)

Example 7 with FaultResponseParameterDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto in project open-smart-grid-platform by OSGP.

the class BundleResponseMessageProcessorTest method assertResponse.

public void assertResponse(final FaultResponseDto actualResponse, final Integer expectedCode, final String expectedMessage, final String expectedComponent, final String expectedInnerException, final String expectedInnerMessage, final List<FaultResponseParameterDto> expectedParameterList) {
    assertThat(actualResponse).withFailMessage("faultResponse").isNotNull();
    /*
     * Fault Response should not contain the result fields for a generic
     * Action Response, and the result should always be NOT OK.
     */
    assertThat(actualResponse.getException()).withFailMessage("exception").isNull();
    assertThat(actualResponse.getResultString()).withFailMessage("resultString").isNull();
    assertThat(actualResponse.getResult()).withFailMessage("result").isEqualTo(OsgpResultTypeDto.NOT_OK);
    assertThat(actualResponse.getCode()).withFailMessage("code").isEqualTo(expectedCode);
    assertThat(actualResponse.getMessage()).withFailMessage("message").isEqualTo(expectedMessage);
    assertThat(actualResponse.getComponent()).withFailMessage("component").isEqualTo(expectedComponent);
    assertThat(actualResponse.getInnerException()).withFailMessage("innerException").isEqualTo(expectedInnerException);
    assertThat(actualResponse.getInnerMessage()).withFailMessage("innerMessage").isEqualTo(expectedInnerMessage);
    if (expectedParameterList == null || expectedParameterList.isEmpty()) {
        assertThat(actualResponse.getFaultResponseParameters()).withFailMessage("parameters").isNull();
    } else {
        assertThat(actualResponse.getFaultResponseParameters()).withFailMessage("parameters").isNotNull();
        final List<FaultResponseParameterDto> actualParameterList = actualResponse.getFaultResponseParameters().getParameterList();
        assertThat(actualParameterList).withFailMessage("parameter list").isNotNull();
        final int numberOfParameters = expectedParameterList.size();
        assertThat(actualParameterList.size()).withFailMessage("number of parameters").isEqualTo(numberOfParameters);
        for (int i = 0; i < numberOfParameters; i++) {
            final FaultResponseParameterDto expectedParameter = expectedParameterList.get(i);
            final FaultResponseParameterDto actualParameter = actualParameterList.get(i);
            final int parameterNumber = i + 1;
            assertThat(actualParameter.getKey()).withFailMessage("parameter key " + parameterNumber).isEqualTo(expectedParameter.getKey());
            assertThat(actualParameter.getValue()).withFailMessage("parameter value " + parameterNumber).isEqualTo(expectedParameter.getValue());
        }
    }
}
Also used : FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto)

Example 8 with FaultResponseParameterDto

use of org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto in project open-smart-grid-platform by OSGP.

the class FaultResponseConverter method createFaultResponseParameterList.

private List<FaultResponseParameter> createFaultResponseParameterList(final FaultResponseParametersDto faultResponseParametersDto) {
    final List<FaultResponseParameter> faultResponseParameterList = new ArrayList<>();
    for (final FaultResponseParameterDto parameterDto : faultResponseParametersDto.getParameterList()) {
        final String key = parameterDto.getKey();
        final String value = parameterDto.getValue();
        final FaultResponseParameter parameter = new FaultResponseParameter(key, value);
        faultResponseParameterList.add(parameter);
    }
    return faultResponseParameterList;
}
Also used : FaultResponseParameter(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FaultResponseParameter) FaultResponseParameterDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto) ArrayList(java.util.ArrayList)

Aggregations

FaultResponseParameterDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseParameterDto)8 ArrayList (java.util.ArrayList)4 FaultResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FaultResponseDto)3 Test (org.junit.jupiter.api.Test)2 FaultResponseParameter (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.FaultResponseParameter)2 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 ActionDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionDto)1 BundleMessagesRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto)1 ComponentType (org.opensmartgridplatform.shared.exceptionhandling.ComponentType)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 FunctionalExceptionType (org.opensmartgridplatform.shared.exceptionhandling.FunctionalExceptionType)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1