Search in sources :

Example 1 with EmptyResponse

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);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) EmptyResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse) 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 EmptyResponse

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;
}
Also used : ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.microgrids.application.exceptionhandling.ResponseNotFoundException) SetDataResponse(org.opensmartgridplatform.adapter.ws.schema.microgrids.adhocmanagement.SetDataResponse) EmptyResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse) ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.microgrids.application.exceptionhandling.ResponseNotFoundException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 3 with EmptyResponse

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.");
    }
}
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) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) EmptyResponse(org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse)

Aggregations

EmptyResponse (org.opensmartgridplatform.domain.microgrids.valueobjects.EmptyResponse)3 ResponseNotFoundException (org.opensmartgridplatform.adapter.ws.microgrids.application.exceptionhandling.ResponseNotFoundException)2 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)2 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)2 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)2 OptimisticLockException (javax.persistence.OptimisticLockException)1 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)1 SetDataResponse (org.opensmartgridplatform.adapter.ws.schema.microgrids.adhocmanagement.SetDataResponse)1 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)1 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)1 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)1