Search in sources :

Example 56 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class DefaultDeviceResponseServiceTest method testDefaultDeviceResponseWithNotOkTypeAndException.

@Test
public void testDefaultDeviceResponseWithNotOkTypeAndException() {
    // Arrange
    final ResponseMessageResultType deviceResult = ResponseMessageResultType.NOT_OK;
    final OsgpException exception = new OsgpException(ComponentType.DOMAIN_CORE, "There was an exception");
    final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(IDS).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(exception).withMessagePriority(MESSAGE_PRIORITY).withMessageType(MESSAGE_TYPE).build();
    // Act
    this.defaultDeviceResponseService.handleDefaultDeviceResponse(IDS, MESSAGE_TYPE, MESSAGE_PRIORITY, deviceResult, exception);
    final ArgumentCaptor<ResponseMessage> argument = ArgumentCaptor.forClass(ResponseMessage.class);
    verify(this.webServiceResponseMessageSender).send(argument.capture());
    // Assert
    assertThat(argument.getValue()).usingRecursiveComparison().isEqualTo(expectedResponseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) Test(org.junit.jupiter.api.Test)

Example 57 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class ConfigurationManagementService method handleGetConfigurationResponse.

public void handleGetConfigurationResponse(final ConfigurationDto configurationDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = exception;
    Configuration configuration = null;
    try {
        if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
        final List<DeviceOutputSetting> outputSettings = ssld.getOutputSettings();
        this.replaceEmptyOutputSettings(configurationDto, outputSettings);
        configuration = this.domainCoreMapper.map(configurationDto, Configuration.class);
        // TARIFF_REVERSED will be changed to the correct RelayType.
        for (final DeviceOutputSetting dos : outputSettings) {
            if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
                for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
                    if (rm.getIndex() == dos.getExternalId() && rm.getRelayType().equals(RelayType.TARIFF)) {
                        rm.changeRelayType(RelayType.TARIFF_REVERSED);
                    }
                }
            }
        }
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception for messageType: {}", messageType, e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, e.getMessage(), e);
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(configuration).withMessagePriority(messagePriority).withMessageType(MessageType.GET_CONFIGURATION.name()).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Configuration(org.opensmartgridplatform.domain.core.valueobjects.Configuration) DeviceOutputSetting(org.opensmartgridplatform.domain.core.entities.DeviceOutputSetting) RelayMap(org.opensmartgridplatform.domain.core.valueobjects.RelayMap) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld)

Example 58 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class CommonGetConfigurationResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing common get configuration response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final ConfigurationDto configurationDto = (ConfigurationDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.configurationManagementService.handleGetConfigurationResponse(configurationDto, ids, messageType, messagePriority, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConfigurationDto(org.opensmartgridplatform.dto.valueobjects.ConfigurationDto) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Example 59 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class MonitoringEndpoint method getPQValuesPeriodic.

@PayloadRoot(localPart = "GetPQValuesPeriodicRequest", namespace = NAMESPACE)
@ResponsePayload
public GetPQValuesPeriodicAsyncResponse getPQValuesPeriodic(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetPQValuesPeriodicRequest request) throws OsgpException {
    LOGGER.info("Get PQ Values Periodic Request received from organisation: {} for device: {}.", organisationIdentification, request.getDeviceIdentification());
    final GetPQValuesPeriodicAsyncResponse response = new GetPQValuesPeriodicAsyncResponse();
    try {
        final org.opensmartgridplatform.domain.da.valueobjects.GetPQValuesPeriodicRequest getPQValuesPeriodicRequest = this.mapper.map(request, org.opensmartgridplatform.domain.da.valueobjects.GetPQValuesPeriodicRequest.class);
        final String correlationUid = this.service.enqueueGetPQValuesPeriodicRequest(organisationIdentification, request.getDeviceIdentification(), getPQValuesPeriodicRequest);
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final Exception e) {
        this.handleException(LOGGER, e);
    }
    return response;
}
Also used : GetPQValuesPeriodicAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.GetPQValuesPeriodicAsyncResponse) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.common.AsyncResponse) GetPQValuesPeriodicAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.GetPQValuesPeriodicAsyncResponse) GetPQValuesAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.GetPQValuesAsyncResponse) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 60 with OsgpException

use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.

the class MonitoringEndpoint method getMeasurementReport.

@PayloadRoot(localPart = "GetMeasurementReportRequest", namespace = NAMESPACE)
@ResponsePayload
public GetMeasurementReportResponse getMeasurementReport(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetMeasurementReportRequest request) throws OsgpException {
    LOGGER.info("Get Measurement Report Request received from organisation: {} for correlationUid: {}.", organisationIdentification, request.getCorrelationUid());
    final GetMeasurementReportResponse response = new GetMeasurementReportResponse();
    try {
        final org.opensmartgridplatform.domain.da.measurements.MeasurementReport dataResponse = this.service.dequeueMeasurementReport(request.getCorrelationUid());
        if (dataResponse != null) {
            final MeasurementReport report = this.mapper.map(dataResponse, MeasurementReport.class);
            response.setMeasurementReport(report);
            response.setResult(OsgpResultType.OK);
        } else {
            response.setResult(OsgpResultType.NOT_FOUND);
        }
    } catch (final ResponseNotFoundException e) {
        LOGGER.warn("ResponseNotFoundException for getMeasurementReport", e);
        response.setResult(OsgpResultType.NOT_FOUND);
    } catch (final Exception e) {
        this.handleException(LOGGER, e);
    }
    return response;
}
Also used : ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException) MeasurementReport(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.MeasurementReport) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException) GetMeasurementReportResponse(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.GetMeasurementReportResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Aggregations

OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)235 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)153 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)153 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)128 ConstraintViolationException (javax.validation.ConstraintViolationException)98 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)75 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)67 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)64 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)54 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)51 JMSException (javax.jms.JMSException)40 IOException (java.io.IOException)30 GetKeysResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData)23 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)17 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)15 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)15 ResponseNotFoundException (org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException)10 Device (org.opensmartgridplatform.domain.core.entities.Device)10 ArrayList (java.util.ArrayList)9