Search in sources :

Example 1 with DeviceStatusDto

use of org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto in project open-smart-grid-platform by OSGP.

the class TariffSwitchingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.

private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    DeviceStatusDto status = null;
    try {
        final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
        status = response.getDeviceStatus();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
    }
    final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(status).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 2 with DeviceStatusDto

use of org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto in project open-smart-grid-platform by OSGP.

the class CommonGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.

private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    DeviceStatusDto status = null;
    try {
        final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
        status = response.getDeviceStatus();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
    }
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build()).result(result).osgpException(osgpException).dataObject(status).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 3 with DeviceStatusDto

use of org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto in project open-smart-grid-platform by OSGP.

the class PublicLightingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.

private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
    ResponseMessageResultType result = ResponseMessageResultType.OK;
    OsgpException osgpException = null;
    DeviceStatusDto status = null;
    try {
        final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
        status = response.getDeviceStatus();
    } catch (final Exception e) {
        LOGGER.error("Device Response Exception", e);
        result = ResponseMessageResultType.NOT_OK;
        osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
    }
    final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build();
    final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(status).build();
    responseMessageSender.send(responseMessage);
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) ProtocolResponseMessage(org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) IOException(java.io.IOException) JMSException(javax.jms.JMSException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 4 with DeviceStatusDto

use of org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method handleOslpResponseGetStatus.

private void handleOslpResponseGetStatus(final DeviceRequest deviceRequest, final OslpEnvelope oslpResponse, final DeviceResponseHandler deviceResponseHandler) {
    this.saveOslpResponseLogEntry(deviceRequest, oslpResponse);
    this.updateSequenceNumber(deviceRequest.getDeviceIdentification(), oslpResponse);
    DeviceStatusDto deviceStatus = null;
    if (oslpResponse.getPayloadMessage().hasGetStatusResponse()) {
        final Oslp.GetStatusResponse getStatusResponse = oslpResponse.getPayloadMessage().getGetStatusResponse();
        final Oslp.Status oslpStatus = getStatusResponse.getStatus();
        if (oslpStatus == Oslp.Status.OK) {
            // Required properties.
            final List<LightValueDto> lightValues = this.mapper.mapAsList(getStatusResponse.getValueList(), LightValueDto.class);
            final LinkTypeDto preferredType = this.getPreferredLinktype(getStatusResponse);
            final LinkTypeDto actualLinkType = this.getActualLinktype(getStatusResponse);
            final LightTypeDto lightType = this.getLightType(getStatusResponse);
            final int eventNotificationMask = getStatusResponse.getEventNotificationMask();
            deviceStatus = new DeviceStatusDto(lightValues, preferredType, actualLinkType, lightType, eventNotificationMask);
            // Optional properties.
            this.setBootLoaderVersion(deviceStatus, getStatusResponse);
            this.setCurrentConfigurationBankUsed(deviceStatus, getStatusResponse);
            this.setCurrentIp(deviceStatus, getStatusResponse);
            this.setCurrentTime(deviceStatus, getStatusResponse);
            this.setDcOutputVoltageCurrent(deviceStatus, getStatusResponse);
            this.setDcOutputVoltageMaximum(deviceStatus, getStatusResponse);
            this.setEventNotificationsMask(deviceStatus, getStatusResponse);
            this.setExternalFlashMemSize(deviceStatus, getStatusResponse);
            this.setFirmwareVersion(deviceStatus, getStatusResponse);
            this.setHardwareId(deviceStatus, getStatusResponse);
            this.setInternalFlashMemSize(deviceStatus, getStatusResponse);
            this.setLastInternalTestResultCode(deviceStatus, getStatusResponse);
            this.setMacAddress(deviceStatus, getStatusResponse);
            this.setMaximumOutputPowerOnDcOutput(deviceStatus, getStatusResponse);
            this.setName(deviceStatus, getStatusResponse);
            this.setNumberOfOutputs(deviceStatus, getStatusResponse);
            this.setSerialNumber(deviceStatus, getStatusResponse);
            this.setStartupCounter(deviceStatus, getStatusResponse);
        } else {
            // handle failure by throwing exceptions if needed
            LOGGER.error("Unable to convert Oslp.GetStatusResponse");
        }
    }
    final DeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest, deviceStatus);
    deviceResponseHandler.handleResponse(deviceResponse);
}
Also used : GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) LinkTypeDto(org.opensmartgridplatform.dto.valueobjects.LinkTypeDto) LightTypeDto(org.opensmartgridplatform.dto.valueobjects.LightTypeDto) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.EmptyDeviceResponse) DeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.DeviceResponse) GetConfigurationDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetConfigurationDeviceResponse) GetStatusDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse) GetFirmwareVersionDeviceResponse(org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetFirmwareVersionDeviceResponse) Oslp(org.opensmartgridplatform.oslp.Oslp) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto)

Example 5 with DeviceStatusDto

use of org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto in project open-smart-grid-platform by OSGP.

the class PublicLightingGetStatusResponseMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) throws JMSException {
    LOGGER.debug("Processing public lighting get status response message");
    String correlationUid = null;
    String messageType = null;
    int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
    String organisationIdentification = null;
    String deviceIdentification = null;
    ResponseMessage responseMessage;
    ResponseMessageResultType responseMessageResultType = null;
    OsgpException osgpException = null;
    Object dataObject;
    try {
        correlationUid = message.getJMSCorrelationID();
        messageType = message.getJMSType();
        messagePriority = message.getJMSPriority();
        organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
        deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
        responseMessage = (ResponseMessage) message.getObject();
        responseMessageResultType = responseMessage.getResult();
        osgpException = responseMessage.getOsgpException();
        dataObject = responseMessage.getDataObject();
    } catch (final JMSException e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
        LOGGER.debug("correlationUid: {}", correlationUid);
        LOGGER.debug("messageType: {}", messageType);
        LOGGER.debug("messagePriority: {}", messagePriority);
        LOGGER.debug("organisationIdentification: {}", organisationIdentification);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
        LOGGER.debug("deviceIdentification: {}", deviceIdentification);
        LOGGER.debug("osgpException", osgpException);
        return;
    }
    if (OsgpSystemCorrelationUid.CORRELATION_UID.equals(correlationUid)) {
        LOGGER.info("Received message for device: {} of type: {} with correlation UID: {} and result: {}.", deviceIdentification, messageType, correlationUid, responseMessageResultType.name());
        this.adHocManagementService.updateLastCommunicationTime(deviceIdentification);
        return;
    }
    try {
        LOGGER.info("Calling application service function to handle response: {}", messageType);
        final DeviceStatusDto deviceLightStatus = (DeviceStatusDto) dataObject;
        final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
        this.adHocManagementService.handleGetStatusResponse(deviceLightStatus, ids, messageType, messagePriority, responseMessageResultType, osgpException);
    } catch (final Exception e) {
        this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
    }
}
Also used : OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) JMSException(javax.jms.JMSException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage) ResponseMessageResultType(org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType) CorrelationIds(org.opensmartgridplatform.shared.infra.jms.CorrelationIds) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Aggregations

DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)11 JMSException (javax.jms.JMSException)8 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)6 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)6 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)5 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.oslp.elster.device.responses.GetStatusDeviceResponse)4 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)4 IOException (java.io.IOException)3 LightValueDto (org.opensmartgridplatform.dto.valueobjects.LightValueDto)3 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)3 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)3 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)3 GetStatusDeviceResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.GetStatusDeviceResponse)2 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)2 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)2 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)2 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)2 Iec61850GetStatusCommand (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850GetStatusCommand)2 Ssld (org.opensmartgridplatform.core.db.api.iec61850.entities.Ssld)2 LightTypeDto (org.opensmartgridplatform.dto.valueobjects.LightTypeDto)2