Search in sources :

Example 66 with OsgpException

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

the class AdHocManagementEndpoint method getData.

// === GET DATA ===
@PayloadRoot(localPart = "GetDataRequest", namespace = NAMESPACE)
@ResponsePayload
public GetDataAsyncResponse getData(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetDataRequest request) throws OsgpException {
    LOGGER.info("Get Data Request received from organisation: {} for device: {}.", organisationIdentification, request.getDeviceIdentification());
    final GetDataAsyncResponse response = new GetDataAsyncResponse();
    try {
        final org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataRequest dataRequest = this.mapper.map(request, org.opensmartgridplatform.domain.microgrids.valueobjects.GetDataRequest.class);
        final String correlationUid = this.service.enqueueGetDataRequest(organisationIdentification, request.getDeviceIdentification(), dataRequest);
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : SetDataAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.microgrids.adhocmanagement.SetDataAsyncResponse) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.microgrids.common.AsyncResponse) GetDataAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.microgrids.adhocmanagement.GetDataAsyncResponse) GetDataAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.microgrids.adhocmanagement.GetDataAsyncResponse) 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 67 with OsgpException

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

the class AdHocManagementEndpoint method getDeviceModelResponse.

@PayloadRoot(localPart = "GetDeviceModelAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public GetDeviceModelResponse getDeviceModelResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetDeviceModelAsyncRequest request) throws OsgpException {
    LOGGER.info("Get Device Model Response received from organisation: {} for correlationUid: {}.", organisationIdentification, request.getAsyncRequest().getCorrelationUid());
    GetDeviceModelResponse response = new GetDeviceModelResponse();
    try {
        final org.opensmartgridplatform.domain.da.valueobjects.GetDeviceModelResponse dataResponse = this.service.dequeueGetDeviceModelResponse(request.getAsyncRequest().getCorrelationUid());
        if (dataResponse != null) {
            response = this.mapper.map(dataResponse, GetDeviceModelResponse.class);
            response.setResult(OsgpResultType.OK);
        } else {
            response.setResult(OsgpResultType.NOT_FOUND);
        }
    } catch (final ResponseNotFoundException e) {
        LOGGER.warn("ResponseNotFoundException for getDeviceModel", e);
        response.setResult(OsgpResultType.NOT_FOUND);
    } catch (final Exception e) {
        this.handleException(LOGGER, e);
    }
    response.setDeviceIdentification(request.getAsyncRequest().getDeviceId());
    return response;
}
Also used : GetDeviceModelResponse(org.opensmartgridplatform.adapter.ws.schema.distributionautomation.generic.GetDeviceModelResponse) ResponseNotFoundException(org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException) 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 68 with OsgpException

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

the class SessionProviderKpn method getIpAddress.

@Override
public String getIpAddress(final String iccId) throws OsgpException {
    GetSessionInfoResponse response;
    try {
        response = this.jasperWirelessTerminalClient.getSession(iccId);
    } catch (final SoapFaultClientException e) {
        final String errorMessage = String.format("iccId %s is probably not supported in this session provider", iccId);
        LOGGER.error(errorMessage, e);
        throw new FunctionalException(FunctionalExceptionType.INVALID_ICCID, ComponentType.PROTOCOL_DLMS, new OsgpException(ComponentType.PROTOCOL_DLMS, e.getMessage()));
    }
    final SessionInfoType sessionInfoType = this.getSessionInfo(response);
    if (sessionInfoType == null) {
        return null;
    }
    return sessionInfoType.getIpAddress();
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetSessionInfoResponse(com.jasperwireless.api.ws.service.GetSessionInfoResponse) SoapFaultClientException(org.springframework.ws.soap.client.SoapFaultClientException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SessionInfoType(com.jasperwireless.api.ws.service.SessionInfoType)

Example 69 with OsgpException

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

the class GetFirmwareFileResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Processing {} response message", this.messageType.name());
    }
    // Get metadata from message and update message type to update
    // firmware
    final MessageMetadata messageMetadata = new MessageMetadata.Builder(MessageMetadata.fromMessage(message)).withMessageType(MessageType.UPDATE_FIRMWARE.name()).build();
    final Serializable messageObject = message.getObject();
    final ThrowingConsumer<DlmsConnectionManager> taskForConnectionManager = conn -> this.processMessageTasks(messageObject, messageMetadata, conn);
    try {
        this.createAndHandleConnectionForDevice(this.domainHelperService.findDlmsDevice(messageMetadata), messageMetadata, taskForConnectionManager);
    } catch (final OsgpException e) {
        LOGGER.error("Something went wrong with the DlmsConnection", e);
    }
}
Also used : FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) Logger(org.slf4j.Logger) OsgpResponseMessageProcessor(org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.responses.from.core.OsgpResponseMessageProcessor) UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) LoggerFactory(org.slf4j.LoggerFactory) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Autowired(org.springframework.beans.factory.annotation.Autowired) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) JMSException(javax.jms.JMSException) Serializable(java.io.Serializable) Component(org.springframework.stereotype.Component) FirmwareService(org.opensmartgridplatform.adapter.protocol.dlms.application.services.FirmwareService) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ThrowingConsumer(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ThrowingConsumer) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Serializable(java.io.Serializable) DlmsConnectionManager(org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager)

Example 70 with OsgpException

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

the class GetFirmwareFileResponseMessageProcessor method processMessageTasks.

@SuppressWarnings(// SilentException cannot be caught since it does not extend Exception.
"squid:S1193")
void processMessageTasks(final Serializable messageObject, final MessageMetadata messageMetadata, final DlmsConnectionManager conn) throws OsgpException {
    try {
        final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
        LOGGER.info("{} called for device: {} for organisation: {}", messageMetadata.getMessageType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification());
        final Serializable response;
        response = this.handleMessage(conn, device, messageObject);
        // Send response
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, this.responseMessageSender, response);
    } catch (final Exception exception) {
        // Return original request + exception
        if (!(exception instanceof SilentException)) {
            LOGGER.error("Unexpected exception during {}", this.messageType.name(), exception);
        }
        this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, exception, this.responseMessageSender, this.createUpdateFirmwareRequestDto(messageObject));
    } finally {
        final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
        this.doConnectionPostProcessing(device, conn, messageMetadata);
    }
}
Also used : Serializable(java.io.Serializable) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException)

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