use of org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleSetDataResponse.
public void handleSetDataResponse(final EmptyResponseDto emptyResponseDto, final CorrelationIds ids, final String messageType, final ResponseMessageResultType responseMessageResultType, final OsgpException osgpException) {
LOGGER.info("handleResponse for MessageType: {}", messageType);
ResponseMessageResultType result = ResponseMessageResultType.OK;
EmptyResponse emptyResponse = 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());
emptyResponse = this.mapper.map(emptyResponseDto, EmptyResponse.class);
} catch (final Exception e) {
LOGGER.error("Unexpected Exception", e);
result = ResponseMessageResultType.NOT_OK;
exception = this.ensureOsgpException(e, "Exception occurred while setting data");
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(exception).withDataObject(emptyResponse).build();
this.webServiceResponseMessageSender.send(responseMessage, messageType);
}
use of org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse in project open-smart-grid-platform by OSGP.
the class AdHocManagementEndpoint method getSetDataResponse.
@PayloadRoot(localPart = "SetDataAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public SetDataResponse getSetDataResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetDataAsyncRequest request) throws OsgpException {
LOGGER.info("Get Set Data Response received from organisation: {} with correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
final SetDataResponse response = new SetDataResponse();
try {
final EmptyResponse setDataResponse = this.service.dequeueSetDataResponse(request.getAsyncRequest().getCorrelationUid());
if (setDataResponse != null) {
response.setResult(OsgpResultType.OK);
} else {
response.setResult(OsgpResultType.NOT_FOUND);
}
} catch (final ResponseNotFoundException e) {
LOGGER.warn("ResponseNotFoundException for getSetDataResponse", e);
response.setResult(OsgpResultType.NOT_FOUND);
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse in project open-smart-grid-platform by OSGP.
the class MicrogridsService method dequeueSetDataResponse.
public EmptyResponse dequeueSetDataResponse(final String correlationUid) throws OsgpException {
LOGGER.debug("dequeueSetDataRequest 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 new EmptyResponse();
default:
// Should not get here
throw new TechnicalException(ComponentType.WS_MICROGRIDS, "Response message contains invalid result.");
}
}
Aggregations