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;
}
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);
}
}
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));
}
}
}
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()));
}
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();
}
Aggregations