Search in sources :

Example 1 with GetDataResponse

use of org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method handleGetDataResponse.

public void handleGetDataResponse(final GetDataResponseDto dataResponseDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    GetDataResponse dataResponse = null;
    OsgpException exception = null;
    try {
        if (responseMessageResultType == ResponseMessageResultType.NOT_OK || osgpException != null) {
            LOGGER.error("Device Response not ok.", osgpException);
            throw osgpException;
        }
        this.handleResponseMessageReceived(ids.getDeviceIdentification());
        dataResponse = this.mapper.map(dataResponseDto, GetDataResponse.class);
    } catch (final Exception e) {
        LOGGER.error("Unexpected Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        exception = this.ensureOsgpException(e, "Exception occurred while getting data");
    }
    // Support for Push messages, generate correlationUid
    String actualCorrelationUid = ids.getCorrelationUid();
    if ("no-correlationUid".equals(actualCorrelationUid)) {
        actualCorrelationUid = this.correlationIdProviderUUIDService.getCorrelationId("DeviceGenerated", ids.getDeviceIdentification());
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withCorrelationUid(actualCorrelationUid).withMessageType(messageType).withResult(result).withOsgpException(exception).withDataObject(dataResponse).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageType);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetDataResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OptimisticLockException(javax.persistence.OptimisticLockException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)

Example 2 with GetDataResponse

use of org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse in project open-smart-grid-platform by OSGP.

the class AdHocManagementService method handleInternalDataResponse.

public void handleInternalDataResponse(final GetDataResponseDto dataResponseDto, final CorrelationIds ids, final String messageType) {
    LOGGER.info("handleInternalDataResponse for MessageType: {}", messageType);
    final GetDataResponse dataResponse = this.mapper.map(dataResponseDto, GetDataResponse.class);
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(ResponseMessageResultType.OK).withMessageType(messageType).withDataObject(dataResponse).build();
    this.webServiceResponseMessageSender.send(responseMessage, messageType);
}
Also used : GetDataResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 3 with GetDataResponse

use of org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse in project open-smart-grid-platform by OSGP.

the class MicrogridsService method dequeueGetDataResponse.

public GetDataResponse dequeueGetDataResponse(final String correlationUid) throws OsgpException {
    LOGGER.debug("dequeueGetDataRequest called with correlation uid {}", correlationUid);
    final ResponseData responseData = this.responseDataService.dequeue(correlationUid, ResponseMessage.class, ComponentType.WS_MICROGRIDS);
    final ResponseMessage response = (ResponseMessage) responseData.getMessageData();
    switch(response.getResult()) {
        case NOT_FOUND:
            throw new ResponseNotFoundException(ComponentType.WS_MICROGRIDS, "Response message not found.");
        case NOT_OK:
            if (response.getOsgpException() != null) {
                throw response.getOsgpException();
            }
            throw new TechnicalException(ComponentType.WS_MICROGRIDS, "Response message not ok.");
        case OK:
            return (GetDataResponse) response.getDataObject();
        default:
            // Should not get here
            throw new TechnicalException(ComponentType.WS_MICROGRIDS, "Response message contains invalid result.");
    }
}
Also used : ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.microgrids.application.exceptionhandling.ResponseNotFoundException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponseData(org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData) GetDataResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Aggregations

GetDataResponse (org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataResponse)3 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)3 OptimisticLockException (javax.persistence.OptimisticLockException)1 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)1 ResponseNotFoundException (org.opensmartgridplatform.adapter.ws.microgrids.application.exceptionhandling.ResponseNotFoundException)1 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)1