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);
}
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);
}
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.");
}
}
Aggregations