Search in sources :

Example 1 with ActionResponseDto

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

the class AbstractCommandExecutor method executeBundleAction.

@Override
public ActionResponseDto executeBundleAction(final DlmsConnectionManager conn, final DlmsDevice device, final ActionRequestDto actionRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
    if (this.bundleExecutorMapKey == null) {
        throw new ProtocolAdapterException("Execution of " + this.getClass().getName() + " is not supported in a bundle context.");
    }
    final T commandInput = this.fromBundleRequestInput(actionRequestDto);
    LOGGER.debug("Translated {} from bundle to {} for call to CommandExecutor.", this.className(actionRequestDto), this.className(commandInput));
    final R executionResult = this.execute(conn, device, commandInput, messageMetadata);
    final ActionResponseDto bundleResponse = this.asBundleResponse(executionResult);
    LOGGER.debug("Translated {} to {} for bundle response after call to CommandExecutor.", this.className(executionResult), this.className(bundleResponse));
    return bundleResponse;
}
Also used : ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 2 with ActionResponseDto

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

the class BundleService method callExecutor.

private void callExecutor(final CommandExecutor<?, ?> executor, final ActionDto action, final DlmsConnectionManager conn, final DlmsDevice device, final MessageMetadata messageMetadata) {
    final String executorName = executor.getClass().getSimpleName();
    try {
        log.info("Calling executor in bundle {} [deviceId={}]", executorName, device.getDeviceIdentification());
        final ActionResponseDto response = executor.executeBundleAction(conn, device, action.getRequest(), messageMetadata);
        action.setResponse(response);
    } catch (final ConnectionException ce) {
        log.warn("A connection exception occurred while executing {} [deviceId={}]", executorName, device.getDeviceIdentification(), ce);
        throw ce;
    } catch (final DeviceKeyProcessAlreadyRunningException e) {
        // The request will NOT be sent back to Core to retry but put back on the queue
        throw e;
    } catch (final Exception e) {
        log.error("Error while executing bundle action for {} with {} [deviceId={}]", action.getRequest().getClass().getName(), executorName, device.getDeviceIdentification(), e);
        final String message = String.format("Error handling request with %s: %s", executorName, e.getMessage());
        this.addFaultResponse(action, e, message, device);
    }
}
Also used : DeviceKeyProcessAlreadyRunningException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException) ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) DeviceKeyProcessAlreadyRunningException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException) MissingExecutorException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.MissingExecutorException) NonRetryableException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.NonRetryableException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)

Example 3 with ActionResponseDto

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

the class BundleService method checkIfAdditionalActionIsNeeded.

private void checkIfAdditionalActionIsNeeded(final MessageMetadata messageMetadata, final BundleMessagesRequestDto bundleMessagesRequestDto) throws FunctionalException {
    for (final ActionResponseDto action : bundleMessagesRequestDto.getAllResponses()) {
        if (action instanceof CoupleMbusDeviceByChannelResponseDto) {
            this.mBusGatewayService.handleCoupleMbusDeviceByChannelResponse(messageMetadata, (CoupleMbusDeviceByChannelResponseDto) action);
        } else if (action instanceof DecoupleMbusDeviceResponseDto) {
            this.mBusGatewayService.handleDecoupleMbusDeviceResponse(messageMetadata, (DecoupleMbusDeviceResponseDto) action);
        } else if (action instanceof SetDeviceLifecycleStatusByChannelResponseDto) {
            this.managementService.setDeviceLifecycleStatusByChannel((SetDeviceLifecycleStatusByChannelResponseDto) action);
        } else if (action instanceof EventMessageDataResponseDto) {
            this.eventService.enrichEvents(messageMetadata, (EventMessageDataResponseDto) action);
        } else if (action instanceof FirmwareVersionResponseDto) {
            final List<FirmwareVersion> firmwareVersions = this.configurationMapper.mapAsList(((FirmwareVersionResponseDto) action).getFirmwareVersions(), FirmwareVersion.class);
            this.firmwareService.saveFirmwareVersionsReturnedFromDevice(messageMetadata.getDeviceIdentification(), firmwareVersions);
        } else if (action instanceof FirmwareVersionGasResponseDto) {
            final FirmwareVersionGasResponseDto firmwareVersionGasResponseDto = (FirmwareVersionGasResponseDto) action;
            final FirmwareVersion firmwareVersion = this.configurationMapper.map(firmwareVersionGasResponseDto.getFirmwareVersion(), FirmwareVersion.class);
            this.firmwareService.saveFirmwareVersionsReturnedFromDevice(firmwareVersionGasResponseDto.getFirmwareVersion().getMbusDeviceIdentification(), Arrays.asList(firmwareVersion));
        }
    }
}
Also used : ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) SetDeviceLifecycleStatusByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto) DecoupleMbusDeviceResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto) FirmwareVersionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionResponseDto) EventMessageDataResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto) CoupleMbusDeviceByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto) FirmwareVersionGasResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionGasResponseDto) FirmwareVersion(org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)

Example 4 with ActionResponseDto

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

the class AbstractReplaceKeyCommandExecutor method replaceKeys.

protected ActionResponseDto replaceKeys(final DlmsConnectionManager conn, final DlmsDevice device, final SetKeysRequestDto setKeysRequestDto, final MessageMetadata messageMetadata) throws OsgpException {
    log.info("Keys set on device :{}", device.getDeviceIdentification());
    SetKeysRequestDto setDecryptedKeysRequestDto = setKeysRequestDto;
    if (!setKeysRequestDto.isGeneratedKeys()) {
        setDecryptedKeysRequestDto = this.decryptRsaKeys(setKeysRequestDto);
    }
    // if keys are generated, then they are unencrypted by the GenerateAndReplaceKeyCommandExecutor
    final DlmsDevice devicePostSave = this.storeAndSendToDevice(conn, device, wrap(setDecryptedKeysRequestDto.getAuthenticationKey(), KeyId.AUTHENTICATION_KEY, SecurityKeyType.E_METER_AUTHENTICATION, setDecryptedKeysRequestDto.isGeneratedKeys()), messageMetadata);
    this.storeAndSendToDevice(conn, devicePostSave, wrap(setDecryptedKeysRequestDto.getEncryptionKey(), KeyId.GLOBAL_UNICAST_ENCRYPTION_KEY, SecurityKeyType.E_METER_ENCRYPTION, setDecryptedKeysRequestDto.isGeneratedKeys()), messageMetadata);
    return new ActionResponseDto(String.format("Replace keys for device %s was successful", device.getDeviceIdentification()));
}
Also used : ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) SetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)

Example 5 with ActionResponseDto

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

the class BundleMessageProcessorTest method shouldSetEmptyHeaderOnSuccessfulOperation.

@Test
void shouldSetEmptyHeaderOnSuccessfulOperation() throws OsgpException, JMSException {
    this.prepareBundleServiceMockWithRequestAndResponse(new ActionResponseDto());
    when(this.dlmsConnectionManager.getDlmsMessageListener()).thenReturn(this.messageListener);
    this.messageProcessor.processMessageTasks(this.message.getObject(), this.messageMetadata, this.dlmsConnectionManager, this.dlmsDevice);
    verify(this.retryHeaderFactory, times(1)).createEmptyRetryHeader();
}
Also used : ActionResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto) Test(org.junit.jupiter.api.Test)

Aggregations

ActionResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto)9 Test (org.junit.jupiter.api.Test)4 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)3 BundleMessagesRequestDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.BundleMessagesRequestDto)2 ArrayList (java.util.ArrayList)1 ConfigurableMapper (ma.glasnost.orika.impl.ConfigurableMapper)1 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)1 DeviceKeyProcessAlreadyRunningException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException)1 MissingExecutorException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.MissingExecutorException)1 NonRetryableException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.NonRetryableException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 FirmwareVersion (org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion)1 ActionResponse (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ActionResponse)1 BundleMessagesResponse (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.BundleMessagesResponse)1 CoupleMbusDeviceByChannelResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CoupleMbusDeviceByChannelResponseDto)1 DecoupleMbusDeviceResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.DecoupleMbusDeviceResponseDto)1 EventMessageDataResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.EventMessageDataResponseDto)1 FirmwareVersionGasResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionGasResponseDto)1 FirmwareVersionResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionResponseDto)1 SetDeviceLifecycleStatusByChannelResponseDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto)1