From 9f90384bd8e0bd2896aa9f756598d081bd94c07a Mon Sep 17 00:00:00 2001 From: stefanermens Date: Mon, 10 Feb 2025 13:58:07 +0100 Subject: [PATCH 01/10] SMHE-2164: Add SetSpecificAttributeValueCommandExecutor Signed-off-by: stefanermens --- ...SpecificAttributeValueCommandExecutor.java | 113 ++++++++++++++++++ .../SetSpecificAttributeValueRequestDto.java | 26 ++++ 2 files changed, 139 insertions(+) create mode 100644 osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java create mode 100644 osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java new file mode 100644 index 00000000000..499b755f8e9 --- /dev/null +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc; + +import java.util.List; +import lombok.extern.slf4j.Slf4j; +import org.openmuc.jdlms.AccessResultCode; +import org.openmuc.jdlms.AttributeAddress; +import org.openmuc.jdlms.ObisCode; +import org.openmuc.jdlms.SetParameter; +import org.openmuc.jdlms.datatypes.DataObject; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager; +import org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException; +import org.opensmartgridplatform.dlms.exceptions.ObjectConfigException; +import org.opensmartgridplatform.dlms.objectconfig.Attribute; +import org.opensmartgridplatform.dlms.objectconfig.CosemObject; +import org.opensmartgridplatform.dlms.objectconfig.DlmsDataType; +import org.opensmartgridplatform.dlms.objectconfig.DlmsObjectType; +import org.opensmartgridplatform.dlms.services.ObjectConfigService; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.ActionResponseDto; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto; +import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException; +import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; +import org.springframework.stereotype.Component; + +@Component +@Slf4j +public class SetSpecificAttributeValueCommandExecutor + extends AbstractCommandExecutor { + + private final DlmsHelper dlmsHelper; + private final ObjectConfigService objectConfigService; + + public SetSpecificAttributeValueCommandExecutor( + final DlmsHelper dlmsHelper, final ObjectConfigService objectConfigService) { + super(SetSpecificAttributeValueRequestDto.class); + this.objectConfigService = objectConfigService; + this.dlmsHelper = dlmsHelper; + } + + @Override + public ActionResponseDto asBundleResponse(final Void executionResult) + throws ProtocolAdapterException { + return new ActionResponseDto("Set specific attribute was successful"); + } + + @Override + public Void execute( + final DlmsConnectionManager conn, + final DlmsDevice device, + final SetSpecificAttributeValueRequestDto requestData, + final MessageMetadata messageMetadata) + throws FunctionalException, ProtocolAdapterException { + + final DlmsObjectType objectType = DlmsObjectType.valueOf(requestData.getDlmsObjectTag()); + final CosemObject cosemObject; + try { + cosemObject = + this.objectConfigService.getCosemObject( + device.getProtocolName(), device.getProtocolVersion(), objectType); + } catch (final ObjectConfigException e) { + throw new ProtocolAdapterException(AbstractCommandExecutor.ERROR_IN_OBJECT_CONFIG, e); + } + + final Attribute attribute = cosemObject.getAttribute(requestData.getAttributeId()); + + final DlmsDataType dataType = attribute.getDatatype(); + + final DataObject data = + switch (dataType) { + case UNSIGNED -> DataObject.newUInteger8Data(requestData.getIntValue().shortValue()); + case LONG_UNSIGNED -> DataObject.newUInteger16Data(requestData.getIntValue()); + case DOUBLE_LONG_UNSIGNED -> DataObject.newUInteger32Data(requestData.getIntValue()); + case LONG64_UNSIGNED -> DataObject.newUInteger64Data(requestData.getIntValue()); + case INTEGER -> DataObject.newInteger8Data(requestData.getIntValue().byteValue()); + case LONG -> DataObject.newInteger16Data(requestData.getIntValue().shortValue()); + case DOUBLE_LONG -> DataObject.newInteger32Data(requestData.getIntValue()); + case LONG64 -> DataObject.newInteger64Data(requestData.getIntValue()); + default -> + throw new ProtocolAdapterException( + "Datatype " + dataType.name() + " not supported for integer value"); + }; + + final AttributeAddress attributeAddress = + new AttributeAddress( + cosemObject.getClassId(), + new ObisCode(cosemObject.getObis()), + requestData.getAttributeId()); + final SetParameter setParameter = new SetParameter(attributeAddress, data); + + log.debug( + "Set specific attribute value, class id: {}, obis code: {}, attribute id: {}, value: {}", + cosemObject.getClassId(), + cosemObject.getObis(), + requestData.getAttributeId(), + requestData.getIntValue()); + + final List resultCodes = + this.dlmsHelper.setWithList(conn, device, List.of(setParameter)); + + if (!resultCodes.stream().allMatch(code -> code.equals(AccessResultCode.SUCCESS))) { + log.debug("Result of THD configuration is {}", resultCodes); + throw new ProtocolAdapterException("THD configuration resulted in: " + resultCodes); + } + + return null; + } +} diff --git a/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java new file mode 100644 index 00000000000..0a46c848bc2 --- /dev/null +++ b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java @@ -0,0 +1,26 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.dto.valueobjects.smartmetering; + +import java.io.Serial; +import lombok.Getter; + +@Getter +public class SetSpecificAttributeValueRequestDto implements ActionRequestDto { + + @Serial private static final long serialVersionUID = 6091630820323702494L; + + private final String dlmsObjectTag; + private final int attributeId; + private final Integer intValue; + + public SetSpecificAttributeValueRequestDto( + final String dlmsObjectTag, final int attributeId, final Integer intValue) { + super(); + this.dlmsObjectTag = dlmsObjectTag; + this.attributeId = attributeId; + this.intValue = intValue; + } +} From f0b8f6b070e41e76ba87be385dc02c9967245226 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Mon, 10 Feb 2025 14:04:40 +0100 Subject: [PATCH 02/10] SMHE-2164: Add watchdog object to config Signed-off-by: stefanermens --- .../dlms/objectconfig/DlmsObjectType.java | 1 + .../dlmsprofiles/dlmsprofile-dsmr422.json | 18 ++++++++++++++++++ .../dlmsprofiles/dlmsprofile-smr500.json | 18 ++++++++++++++++++ .../dlms/services/Protocol.java | 12 ++++++------ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/osgp/protocol-adapter-dlms/osgp-dlms/src/main/java/org/opensmartgridplatform/dlms/objectconfig/DlmsObjectType.java b/osgp/protocol-adapter-dlms/osgp-dlms/src/main/java/org/opensmartgridplatform/dlms/objectconfig/DlmsObjectType.java index e979af01f77..23137b43855 100644 --- a/osgp/protocol-adapter-dlms/osgp-dlms/src/main/java/org/opensmartgridplatform/dlms/objectconfig/DlmsObjectType.java +++ b/osgp/protocol-adapter-dlms/osgp-dlms/src/main/java/org/opensmartgridplatform/dlms/objectconfig/DlmsObjectType.java @@ -109,6 +109,7 @@ public enum DlmsObjectType { PHASE_OUTAGE_TEST, LAST_GASP_TEST, ADMINISTRATIVE_IN_OUT, + WATCHDOG_TIMER, CONFIGURATION_OBJECT, RANDOMISATION_SETTINGS, ACTIVITY_CALENDAR, diff --git a/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-dsmr422.json b/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-dsmr422.json index 6e93b03e734..bd5cbfa95ba 100644 --- a/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-dsmr422.json +++ b/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-dsmr422.json @@ -2524,6 +2524,24 @@ } ] }, + { + "tag": "WATCHDOG_TIMER", + "description": "Connection watchdog timer P3", + "class-id": 1, + "version": 0, + "obis": "0.1.94.31.2.255", + "group": "ABSTRACT", + "meterTypes": ["SP","PP"], + "attributes": [ + { + "id": 2, + "description": "value", + "datatype": "long-unsigned", + "valuetype": "SET_BY_CLIENT", + "access": "RW" + } + ] + }, { "tag": "CONFIGURATION_OBJECT", "description": "Configuration object", diff --git a/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-smr500.json b/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-smr500.json index ee4b3c2f568..d22ddd5b5c0 100644 --- a/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-smr500.json +++ b/osgp/protocol-adapter-dlms/osgp-dlms/src/main/resources/dlmsprofiles/dlmsprofile-smr500.json @@ -3303,6 +3303,24 @@ } ] }, + { + "tag": "WATCHDOG_TIMER", + "description": "Connection watchdog timer P3", + "class-id": 1, + "version": 0, + "obis": "0.1.94.31.2.255", + "group": "ABSTRACT", + "meterTypes": ["SP","PP"], + "attributes": [ + { + "id": 2, + "description": "value", + "datatype": "long-unsigned", + "valuetype": "SET_BY_CLIENT", + "access": "RW" + } + ] + }, { "tag": "CONFIGURATION_OBJECT", "description": "Configuration object", diff --git a/osgp/protocol-adapter-dlms/osgp-dlms/src/test/java/org/opensmartgridplatform/dlms/services/Protocol.java b/osgp/protocol-adapter-dlms/osgp-dlms/src/test/java/org/opensmartgridplatform/dlms/services/Protocol.java index e1f352f82d2..415631a406f 100644 --- a/osgp/protocol-adapter-dlms/osgp-dlms/src/test/java/org/opensmartgridplatform/dlms/services/Protocol.java +++ b/osgp/protocol-adapter-dlms/osgp-dlms/src/test/java/org/opensmartgridplatform/dlms/services/Protocol.java @@ -12,12 +12,12 @@ @Getter public enum Protocol { DSMR_2_2("DSMR", "2.2", 52, 2, 4, 6, 14, 0, 0, 0, 0, false, false), - DSMR_4_2_2("DSMR", "4.2.2", 93, 11, 27, 6, 14, 6, 13, 5, 6, true, false), - SMR_4_3("SMR", "4.3", 94, 11, 27, 6, 14, 6, 13, 6, 7, true, false), - SMR_5_0_0("SMR", "5.0.0", 115, 11, 27, 6, 14, 6, 15, 9, 14, true, true), - SMR_5_1("SMR", "5.1", 119, 11, 27, 6, 14, 6, 15, 9, 14, true, true), - SMR_5_2("SMR", "5.2", 158, 11, 27, 6, 14, 6, 15, 10, 15, true, true), - SMR_5_5("SMR", "5.5", 162, 11, 27, 6, 14, 6, 15, 10, 15, true, true); + DSMR_4_2_2("DSMR", "4.2.2", 94, 11, 27, 6, 14, 6, 13, 5, 6, true, false), + SMR_4_3("SMR", "4.3", 95, 11, 27, 6, 14, 6, 13, 6, 7, true, false), + SMR_5_0_0("SMR", "5.0.0", 116, 11, 27, 6, 14, 6, 15, 9, 14, true, true), + SMR_5_1("SMR", "5.1", 120, 11, 27, 6, 14, 6, 15, 9, 14, true, true), + SMR_5_2("SMR", "5.2", 159, 11, 27, 6, 14, 6, 15, 10, 15, true, true), + SMR_5_5("SMR", "5.5", 163, 11, 27, 6, 14, 6, 15, 10, 15, true, true); private final String name; private final String version; From a76fda432c2e3840cf721dabc4478935dba10d02 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Tue, 11 Feb 2025 13:22:11 +0100 Subject: [PATCH 03/10] SMHE-2164: Add SetSpecificAttributeValue request to GXF Signed-off-by: stefanermens --- .../services/ActionMapperService.java | 5 ++ .../application/services/AdhocService.java | 43 ++++++++++ ...ttributeValueResponseMessageProcessor.java | 56 ++++++++++++ ...AttributeValueRequestMessageProcessor.java | 40 +++++++++ .../services/ActionMapperService.java | 13 +++ .../endpoints/SmartMeteringAdhocEndpoint.java | 82 ++++++++++++++++++ ..._function_SET_SPECIFIC_ATTRIBUTE_VALUE.sql | 10 +++ .../core/valueobjects/DeviceFunction.java | 1 + .../SetSpecificAttributeValueRequest.java | 57 ++++++++++++ .../SetSpecificAttributeValueRequestData.java | 86 +++++++++++++++++++ .../application/services/AdhocService.java | 55 +++++++++--- ...AttributeValueRequestMessageProcessor.java | 48 +++++++++++ .../smartmetering/NotificationTypeDto.java | 3 +- .../main/resources/SmartMeteringAdhoc.wsdl | 67 ++++++++++++++- .../schemas/adhoc-ws-smartmetering.xsd | 64 ++++++++++++++ .../schemas/bundle-ws-smartmetering.xsd | 18 ++++ .../shared/infra/jms/MessageType.java | 1 + 17 files changed, 635 insertions(+), 14 deletions(-) create mode 100644 osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java create mode 100644 osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java create mode 100644 osgp/platform/osgp-core/src/main/resources/db/migration/V20250211131912345__Add_device_function_SET_SPECIFIC_ATTRIBUTE_VALUE.sql create mode 100644 osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java create mode 100644 osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java create mode 100644 osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/ActionMapperService.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/ActionMapperService.java index 2f5e7722ba3..38050274e91 100644 --- a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/ActionMapperService.java +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/ActionMapperService.java @@ -67,6 +67,7 @@ import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetPushSetupSmsRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetPushSetupUdpRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetRandomisationSettingsRequestData; +import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetSpecificAttributeValueRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetThdConfigurationRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecificAttributeValueRequestData; @@ -118,6 +119,7 @@ import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetPushSetupSmsRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetPushSetupUdpRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetRandomisationSettingsRequestDataDto; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetThdConfigurationRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecialDaysRequestDataDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecificAttributeValueRequestDto; @@ -172,6 +174,8 @@ public class ActionMapperService { CLASS_MAP.put(UpdateFirmwareRequestData.class, UpdateFirmwareRequestDto.class); CLASS_MAP.put(SetKeysRequestData.class, SetKeysRequestDto.class); CLASS_MAP.put(SpecificAttributeValueRequestData.class, SpecificAttributeValueRequestDto.class); + CLASS_MAP.put( + SetSpecificAttributeValueRequestData.class, SetSpecificAttributeValueRequestDto.class); CLASS_MAP.put( GetAssociationLnObjectsRequestData.class, GetAssociationLnObjectsRequestDto.class); CLASS_MAP.put(CoupleMbusDeviceRequestData.class, GetAssociationLnObjectsRequestDto.class); @@ -270,6 +274,7 @@ private void postConstruct() { CLASS_TO_MAPPER_MAP.put(UpdateFirmwareRequestData.class, this.commonMapper); CLASS_TO_MAPPER_MAP.put(SetKeysRequestData.class, this.configurationMapper); CLASS_TO_MAPPER_MAP.put(SpecificAttributeValueRequestData.class, this.commonMapper); + CLASS_TO_MAPPER_MAP.put(SetSpecificAttributeValueRequestData.class, this.commonMapper); CLASS_TO_MAPPER_MAP.put(GetAssociationLnObjectsRequestData.class, this.commonMapper); CLASS_TO_MAPPER_MAP.put(SetClockConfigurationRequestData.class, this.configurationMapper); CLASS_TO_MAPPER_MAP.put(GetThdFingerprintRequestData.class, this.monitoringMapper); diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java index 3c09f495fb5..6e70d8435a5 100644 --- a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java @@ -13,6 +13,7 @@ import org.opensmartgridplatform.domain.core.entities.SmartMeter; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AssociationLnListType; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.ScanMbusChannelsResponseData; +import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetSpecificAttributeValueRequest; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecificAttributeValueRequest; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SynchronizeTimeRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.TestAlarmSchedulerRequestData; @@ -22,6 +23,7 @@ import org.opensmartgridplatform.dto.valueobjects.smartmetering.ObisCodeValuesDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.ScanMbusChannelsRequestDataDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.ScanMbusChannelsResponseDto; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecificAttributeValueRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SynchronizeTimeRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.TestAlarmSchedulerRequestDto; @@ -248,6 +250,47 @@ public void handleGetSpecificAttributeValueResponse( this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType()); } + public void setSpecificAttributeValue( + final MessageMetadata messageMetadata, final SetSpecificAttributeValueRequest request) + throws FunctionalException { + + log.debug( + "setSpecificAttributeValue for organisationIdentification: {} for deviceIdentification: {}", + messageMetadata.getOrganisationIdentification(), + messageMetadata.getDeviceIdentification()); + + final SmartMeter smartMeter = + this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification()); + + final SetSpecificAttributeValueRequestDto requestDto = + new SetSpecificAttributeValueRequestDto( + request.getDlmsObjectTag(), request.getAttributeId(), request.getIntValue()); + + this.osgpCoreRequestMessageSender.send( + requestDto, + messageMetadata + .builder() + .withNetworkAddress(smartMeter.getNetworkAddress()) + .withNetworkSegmentIds(smartMeter.getBtsId(), smartMeter.getCellId()) + .build()); + } + + public void handleSetSpecificAttributeValueResponse( + final MessageMetadata messageMetadata, + final ResponseMessageResultType deviceResult, + final OsgpException exception, + final String resultData) { + + log.debug( + "handleSetSpecificAttributeValueResponse for MessageType: {}", + messageMetadata.getMessageType()); + + final ResponseMessage responseMessage = + this.createResponseMessageWithDataObject( + deviceResult, exception, messageMetadata, resultData); + this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType()); + } + public void scanMbusChannels(final MessageMetadata messageMetadata) throws FunctionalException { log.debug( diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java new file mode 100644 index 00000000000..77435186b5c --- /dev/null +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java @@ -0,0 +1,56 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.core.messageprocessors; + +import org.opensmartgridplatform.adapter.domain.smartmetering.application.services.AdhocService; +import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.core.OsgpCoreResponseMessageProcessor; +import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.ws.WebServiceResponseMessageSender; +import org.opensmartgridplatform.shared.exceptionhandling.ComponentType; +import org.opensmartgridplatform.shared.exceptionhandling.OsgpException; +import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; +import org.opensmartgridplatform.shared.infra.jms.MessageProcessorMap; +import org.opensmartgridplatform.shared.infra.jms.MessageType; +import org.opensmartgridplatform.shared.infra.jms.ResponseMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +@Component +public class SetSpecificAttributeValueResponseMessageProcessor + extends OsgpCoreResponseMessageProcessor { + + @Autowired + @Qualifier("domainSmartMeteringAdhocService") + private AdhocService adhocService; + + @Autowired + public SetSpecificAttributeValueResponseMessageProcessor( + final WebServiceResponseMessageSender responseMessageSender, + @Qualifier("domainSmartMeteringInboundOsgpCoreResponsesMessageProcessorMap") + final MessageProcessorMap messageProcessorMap) { + super( + responseMessageSender, + messageProcessorMap, + MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE, + ComponentType.DOMAIN_SMART_METERING); + } + + @Override + protected boolean hasRegularResponseObject(final ResponseMessage responseMessage) { + return responseMessage.getDataObject() instanceof String; + } + + @Override + protected void handleMessage( + final MessageMetadata deviceMessageMetadata, + final ResponseMessage responseMessage, + final OsgpException osgpException) { + this.adhocService.handleSetSpecificAttributeValueResponse( + deviceMessageMetadata, + responseMessage.getResult(), + osgpException, + (String) responseMessage.getDataObject()); + } +} diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java new file mode 100644 index 00000000000..494b678cf22 --- /dev/null +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java @@ -0,0 +1,40 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.ws.messageprocessors; + +import org.opensmartgridplatform.adapter.domain.smartmetering.application.services.AdhocService; +import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.BaseRequestMessageProcessor; +import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetSpecificAttributeValueRequest; +import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException; +import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; +import org.opensmartgridplatform.shared.infra.jms.MessageProcessorMap; +import org.opensmartgridplatform.shared.infra.jms.MessageType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Component; + +@Component +public class SetSpecificAttributeValueRequestMessageProcessor extends BaseRequestMessageProcessor { + + @Autowired + @Qualifier("domainSmartMeteringAdhocService") + private AdhocService adhocService; + + @Autowired + protected SetSpecificAttributeValueRequestMessageProcessor( + @Qualifier("domainSmartMeteringInboundWebServiceRequestsMessageProcessorMap") + final MessageProcessorMap messageProcessorMap) { + super(messageProcessorMap, MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE); + } + + @Override + protected void handleMessage(final MessageMetadata deviceMessageMetadata, final Object dataObject) + throws FunctionalException { + + final SetSpecificAttributeValueRequest request = (SetSpecificAttributeValueRequest) dataObject; + + this.adhocService.setSpecificAttributeValue(deviceMessageMetadata, request); + } +} diff --git a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java index d503ad63a70..1c1f6c70c59 100644 --- a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java +++ b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java @@ -52,6 +52,7 @@ import org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.SetPushSetupUdpRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.SetRandomisationSettingsRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.SetSpecialDaysRequest; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.SetSpecificAttributeValueRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.SetThdConfigurationRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.SynchronizeTimeRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.bundle.UpdateFirmwareRequest; @@ -103,6 +104,7 @@ import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetPushSetupSmsRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetPushSetupUdpRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetRandomisationSettingsRequestData; +import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetSpecificAttributeValueRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SetThdConfigurationRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecialDaysRequestData; import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SpecificAttributeValueRequestData; @@ -234,6 +236,10 @@ public class ActionMapperService { org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc .GetSpecificAttributeValueRequestData.class, SpecificAttributeValueRequestData.class); + CLASS_MAP.put( + org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc + .SetSpecificAttributeValueRequestData.class, + SpecificAttributeValueRequestData.class); CLASS_MAP.put( org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration .SetClockConfigurationRequestData.class, @@ -286,6 +292,8 @@ public class ActionMapperService { CLASS_MAP.put(SetKeysRequest.class, SetKeysRequestData.class); CLASS_MAP.put(GetAssociationLnObjectsRequest.class, GetAssociationLnObjectsRequestData.class); CLASS_MAP.put(GetSpecificAttributeValueRequest.class, SpecificAttributeValueRequestData.class); + CLASS_MAP.put( + SetSpecificAttributeValueRequest.class, SetSpecificAttributeValueRequestData.class); CLASS_MAP.put(SetClockConfigurationRequest.class, SetClockConfigurationRequestData.class); CLASS_MAP.put(GetConfigurationObjectRequest.class, GetConfigurationObjectRequestData.class); CLASS_MAP.put(GetPowerQualityProfileRequest.class, GetPowerQualityProfileRequestData.class); @@ -375,6 +383,11 @@ private void mapAdHocRequestData() { .GetSpecificAttributeValueRequestData.class, this.adhocMapper); CLASS_TO_MAPPER_MAP.put(GetSpecificAttributeValueRequest.class, this.adhocMapper); + CLASS_TO_MAPPER_MAP.put( + org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc + .SetSpecificAttributeValueRequestData.class, + this.adhocMapper); + CLASS_TO_MAPPER_MAP.put(SetSpecificAttributeValueRequest.class, this.adhocMapper); CLASS_TO_MAPPER_MAP.put( org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ScanMbusChannelsRequestData .class, diff --git a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java index 2c03168d295..020dfbaf73b 100644 --- a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java +++ b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java @@ -28,6 +28,10 @@ import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ScanMbusChannelsAsyncResponse; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ScanMbusChannelsRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ScanMbusChannelsResponse; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncRequest; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncResponse; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueRequest; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueResponse; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SynchronizeTimeAsyncRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SynchronizeTimeAsyncResponse; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SynchronizeTimeRequest; @@ -322,6 +326,84 @@ public GetSpecificAttributeValueResponse getSpecificAttributeValueResponse( return response; } + @PayloadRoot( + localPart = "SetSpecificAttributeValueRequest", + namespace = SMARTMETER_ADHOC_NAMESPACE) + @ResponsePayload + public SetSpecificAttributeValueAsyncResponse setSpecificAttributeValue( + @OrganisationIdentification final String organisationIdentification, + @RequestPayload final SetSpecificAttributeValueRequest request, + @MessagePriority final String messagePriority, + @ScheduleTime final String scheduleTime, + @ResponseUrl final String responseUrl, + @BypassRetry final String bypassRetry) + throws OsgpException { + + final org.opensmartgridplatform.domain.core.valueobjects.smartmetering + .SpecificAttributeValueRequest + setSpecificAttributeValueRequest = + this.adhocMapper.map( + request, + org.opensmartgridplatform.domain.core.valueobjects.smartmetering + .SpecificAttributeValueRequest.class); + + final RequestMessageMetadata requestMessageMetadata = + RequestMessageMetadata.newBuilder() + .withOrganisationIdentification(organisationIdentification) + .withDeviceIdentification(request.getDeviceIdentification()) + .withDeviceFunction(DeviceFunction.GET_SPECIFIC_ATTRIBUTE_VALUE) + .withMessageType(MessageType.GET_SPECIFIC_ATTRIBUTE_VALUE) + .withMessagePriority(messagePriority) + .withScheduleTime(scheduleTime) + .withBypassRetry(bypassRetry) + .build(); + + final AsyncResponse asyncResponse = + this.requestService.enqueueAndSendRequest( + requestMessageMetadata, setSpecificAttributeValueRequest); + + this.saveResponseUrlIfNeeded(asyncResponse.getCorrelationUid(), responseUrl); + + return this.adhocMapper.map(asyncResponse, SetSpecificAttributeValueAsyncResponse.class); + } + + @PayloadRoot( + localPart = "SetSpecificAttributeValueAsyncRequest", + namespace = SMARTMETER_ADHOC_NAMESPACE) + @ResponsePayload + public SetSpecificAttributeValueResponse setSpecificAttributeValueResponse( + @RequestPayload final SetSpecificAttributeValueAsyncRequest request) throws OsgpException { + + SetSpecificAttributeValueResponse response = null; + try { + response = new SetSpecificAttributeValueResponse(); + final ResponseData responseData = + this.responseDataService.get( + request.getCorrelationUid(), ComponentType.WS_SMART_METERING); + + response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue())); + if (ResponseMessageResultType.OK == responseData.getResultType()) { + response.setAttributeValueData((String) responseData.getMessageData()); + } else if (responseData.getMessageData() instanceof OsgpException) { + throw (OsgpException) responseData.getMessageData(); + } else if (responseData.getMessageData() instanceof Exception) { + throw new TechnicalException( + ComponentType.WS_SMART_METERING, + "An exception occurred: Set specific attribute value", + (Exception) responseData.getMessageData()); + } else { + throw new TechnicalException( + ComponentType.WS_SMART_METERING, + "An exception occurred: Set specific attribute value", + null); + } + } catch (final Exception e) { + this.handleException(e); + } + + return response; + } + @PayloadRoot(localPart = "GetAssociationLnObjectsRequest", namespace = SMARTMETER_ADHOC_NAMESPACE) @ResponsePayload public GetAssociationLnObjectsAsyncResponse getAssociationLnObjects( diff --git a/osgp/platform/osgp-core/src/main/resources/db/migration/V20250211131912345__Add_device_function_SET_SPECIFIC_ATTRIBUTE_VALUE.sql b/osgp/platform/osgp-core/src/main/resources/db/migration/V20250211131912345__Add_device_function_SET_SPECIFIC_ATTRIBUTE_VALUE.sql new file mode 100644 index 00000000000..0e483bc84e6 --- /dev/null +++ b/osgp/platform/osgp-core/src/main/resources/db/migration/V20250211131912345__Add_device_function_SET_SPECIFIC_ATTRIBUTE_VALUE.sql @@ -0,0 +1,10 @@ +DO +$$ +BEGIN + + IF NOT EXISTS (SELECT 1 FROM device_function_mapping WHERE "function" = 'SET_SPECIFIC_ATTRIBUTE_VALUE') THEN + insert into device_function_mapping (function_group, "function") values ('OWNER', 'SET_SPECIFIC_ATTRIBUTE_VALUE'); + END IF; + +END; +$$ diff --git a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/DeviceFunction.java b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/DeviceFunction.java index 5af45e755ae..987e3939223 100644 --- a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/DeviceFunction.java +++ b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/DeviceFunction.java @@ -91,6 +91,7 @@ public enum DeviceFunction { SET_RANDOMISATION_SETTINGS, SET_REBOOT, SET_SPECIAL_DAYS, + SET_SPECIFIC_ATTRIBUTE_VALUE, SET_TARIFF_SCHEDULE, SET_THD_CONFIGURATION, SET_TRANSITION, diff --git a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java new file mode 100644 index 00000000000..f17ec94d035 --- /dev/null +++ b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java @@ -0,0 +1,57 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.domain.core.valueobjects.smartmetering; + +public class SetSpecificAttributeValueRequest extends SetSpecificAttributeValueRequestData { + + private static final long serialVersionUID = 1; + + private final String deviceIdentification; + + public SetSpecificAttributeValueRequest( + final String dlmsObjectTag, + final int attributeId, + final int intValue, + final String deviceIdentification) { + super(dlmsObjectTag, attributeId, intValue); + this.deviceIdentification = deviceIdentification; + } + + public String getDeviceIdentification() { + return this.deviceIdentification; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = + prime * result + + ((this.deviceIdentification == null) ? 0 : this.deviceIdentification.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (!super.equals(obj)) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final SetSpecificAttributeValueRequest other = (SetSpecificAttributeValueRequest) obj; + if (this.deviceIdentification == null) { + if (other.deviceIdentification != null) { + return false; + } + } else if (!this.deviceIdentification.equals(other.deviceIdentification)) { + return false; + } + return true; + } +} diff --git a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java new file mode 100644 index 00000000000..81846cd9955 --- /dev/null +++ b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java @@ -0,0 +1,86 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.domain.core.valueobjects.smartmetering; + +import java.io.Serializable; +import org.opensmartgridplatform.domain.core.valueobjects.DeviceFunction; +import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException; + +public class SetSpecificAttributeValueRequestData implements Serializable, ActionRequest { + + private static final long serialVersionUID = -7326169764207317011L; + + private final String dlmsObjectTag; + private final int attributeId; + private final int intValue; + + public SetSpecificAttributeValueRequestData( + final String dlmsObjectType, final int attributeId, final int intValue) { + super(); + this.dlmsObjectTag = dlmsObjectType; + this.attributeId = attributeId; + this.intValue = intValue; + } + + public String getDlmsObjectTag() { + return this.dlmsObjectTag; + } + + public int getAttributeId() { + return this.attributeId; + } + + public int getIntValue() { + return this.intValue; + } + + @Override + public void validate() throws FunctionalException { + // not needed here + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = (prime * result) + this.attributeId; + result = (prime * result) + this.intValue; + result = (prime * result) + this.dlmsObjectTag.hashCode(); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (this.getClass() != obj.getClass()) { + return false; + } + final SetSpecificAttributeValueRequestData other = (SetSpecificAttributeValueRequestData) obj; + if (this.attributeId != other.attributeId) { + return false; + } + if (this.intValue != other.intValue) { + return false; + } + if (this.dlmsObjectTag == null) { + if (other.dlmsObjectTag != null) { + return false; + } + } else if (!this.dlmsObjectTag.equals(other.dlmsObjectTag)) { + return false; + } + return true; + } + + @Override + public DeviceFunction getDeviceFunction() { + return DeviceFunction.SET_SPECIFIC_ATTRIBUTE_VALUE; + } +} diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/application/services/AdhocService.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/application/services/AdhocService.java index d9fb3fd2be8..c66c3c28e22 100644 --- a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/application/services/AdhocService.java +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/application/services/AdhocService.java @@ -5,6 +5,7 @@ package org.opensmartgridplatform.adapter.protocol.dlms.application.services; import java.io.Serializable; +import lombok.extern.slf4j.Slf4j; import org.openmuc.jdlms.AccessResultCode; import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.alarm.TestAlarmSchedulerCommandExecutor; import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.datetime.SynchronizeTimeCommandExecutor; @@ -12,34 +13,49 @@ import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.GetAllAttributeValuesCommandExecutor; import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.GetAssociationLnObjectsCommandExecutor; import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.GetSpecificAttributeValueCommandExecutor; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc.SetSpecificAttributeValueCommandExecutor; import org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice; import org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager; import org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException; import org.opensmartgridplatform.dto.valueobjects.smartmetering.AssociationLnListTypeDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.ScanMbusChannelsResponseDto; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecificAttributeValueRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SynchronizeTimeRequestDto; import org.opensmartgridplatform.dto.valueobjects.smartmetering.TestAlarmSchedulerRequestDto; import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException; import org.opensmartgridplatform.shared.exceptionhandling.OsgpException; import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +@Slf4j @Service(value = "dlmsAdhocService") public class AdhocService { - @Autowired private TestAlarmSchedulerCommandExecutor testAlarmSchedulerCommandExecutor; - @Autowired private SynchronizeTimeCommandExecutor synchronizeTimeCommandExecutor; - - @Autowired private GetAllAttributeValuesCommandExecutor getAllAttributeValuesCommandExecutor; - - @Autowired - private GetSpecificAttributeValueCommandExecutor getSpecificAttributeValueCommandExecutor; - - @Autowired private GetAssociationLnObjectsCommandExecutor getAssociationLnObjectsCommandExecutor; - - @Autowired private ScanMbusChannelsCommandExecutor scanMbusChannelsCommandExecutor; + private final TestAlarmSchedulerCommandExecutor testAlarmSchedulerCommandExecutor; + private final SynchronizeTimeCommandExecutor synchronizeTimeCommandExecutor; + private final GetAllAttributeValuesCommandExecutor getAllAttributeValuesCommandExecutor; + private final SetSpecificAttributeValueCommandExecutor setSpecificAttributeValueCommandExecutor; + private final GetSpecificAttributeValueCommandExecutor getSpecificAttributeValueCommandExecutor; + private final GetAssociationLnObjectsCommandExecutor getAssociationLnObjectsCommandExecutor; + private final ScanMbusChannelsCommandExecutor scanMbusChannelsCommandExecutor; + + public AdhocService( + final TestAlarmSchedulerCommandExecutor testAlarmSchedulerCommandExecutor, + final SynchronizeTimeCommandExecutor synchronizeTimeCommandExecutor, + final GetAllAttributeValuesCommandExecutor getAllAttributeValuesCommandExecutor, + final SetSpecificAttributeValueCommandExecutor setSpecificAttributeValueCommandExecutor, + final GetSpecificAttributeValueCommandExecutor getSpecificAttributeValueCommandExecutor, + final GetAssociationLnObjectsCommandExecutor getAssociationLnObjectsCommandExecutor, + final ScanMbusChannelsCommandExecutor scanMbusChannelsCommandExecutor) { + this.testAlarmSchedulerCommandExecutor = testAlarmSchedulerCommandExecutor; + this.synchronizeTimeCommandExecutor = synchronizeTimeCommandExecutor; + this.getAllAttributeValuesCommandExecutor = getAllAttributeValuesCommandExecutor; + this.setSpecificAttributeValueCommandExecutor = setSpecificAttributeValueCommandExecutor; + this.getSpecificAttributeValueCommandExecutor = getSpecificAttributeValueCommandExecutor; + this.getAssociationLnObjectsCommandExecutor = getAssociationLnObjectsCommandExecutor; + this.scanMbusChannelsCommandExecutor = scanMbusChannelsCommandExecutor; + } // === REQUEST Synchronize Time DATA === @@ -86,6 +102,21 @@ public Serializable getSpecificAttributeValue( conn, device, specificAttributeValueRequestDataDto, messageMetadata); } + public void setSpecificAttributeValue( + final DlmsConnectionManager conn, + final DlmsDevice device, + final SetSpecificAttributeValueRequestDto setSpecificAttributeValueRequestDataDto, + final MessageMetadata messageMetadata) + throws FunctionalException, ProtocolAdapterException { + try { + this.setSpecificAttributeValueCommandExecutor.execute( + conn, device, setSpecificAttributeValueRequestDataDto, messageMetadata); + } catch (final ProtocolAdapterException e) { + log.error("Unexpected exception while setting value.", e); + throw e; + } + } + public ScanMbusChannelsResponseDto scanMbusChannels( final DlmsConnectionManager conn, final DlmsDevice device, diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java new file mode 100644 index 00000000000..ec29e96aeaa --- /dev/null +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.processors; + +import java.io.Serializable; +import org.opensmartgridplatform.adapter.protocol.dlms.application.services.AdhocService; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager; +import org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException; +import org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DeviceRequestMessageProcessor; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecificAttributeValueRequestDto; +import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException; +import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; +import org.opensmartgridplatform.shared.infra.jms.MessageType; +import org.springframework.stereotype.Component; + +@Component +public class SetSpecificAttributeValueRequestMessageProcessor + extends DeviceRequestMessageProcessor { + + private final AdhocService adhocService; + + protected SetSpecificAttributeValueRequestMessageProcessor(final AdhocService adhocService) { + super(MessageType.GET_SPECIFIC_ATTRIBUTE_VALUE); + this.adhocService = adhocService; + } + + @Override + protected Serializable handleMessage( + final DlmsConnectionManager conn, + final DlmsDevice device, + final Serializable requestObject, + final MessageMetadata messageMetadata) + throws ProtocolAdapterException, FunctionalException { + + this.assertRequestObjectType(SpecificAttributeValueRequestDto.class, requestObject); + + final SetSpecificAttributeValueRequestDto request = + (SetSpecificAttributeValueRequestDto) requestObject; + + this.adhocService.setSpecificAttributeValue(conn, device, request, messageMetadata); + + return null; + } +} diff --git a/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java index 1b81bf6e3a4..16cc3d6544a 100644 --- a/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java +++ b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java @@ -27,6 +27,7 @@ public enum NotificationTypeDto { SET_PUSH_SETUP_SMS, GET_ALL_ATTRIBUTE_VALUES, GET_SPECIFIC_ATTRIBUTE_VALUE, + SET_SPECIFIC_ATTRIBUTE_VALUE, SET_KEY_ON_G_METER, HANDLE_BUNDLED_ACTIONS, GET_ASSOCIATION_LN_OBJECTS, @@ -58,5 +59,5 @@ public enum NotificationTypeDto { SYSTEM_EVENT, CLEAR_MBUS_STATUS_ON_ALL_CHANNELS, SET_THD_CONFIGURATION, - GET_THD_FINGERPRINT + GET_THD_FINGERPRINT, } diff --git a/osgp/shared/osgp-ws-smartmetering/src/main/resources/SmartMeteringAdhoc.wsdl b/osgp/shared/osgp-ws-smartmetering/src/main/resources/SmartMeteringAdhoc.wsdl index fc46ccb3460..260660d39b1 100644 --- a/osgp/shared/osgp-ws-smartmetering/src/main/resources/SmartMeteringAdhoc.wsdl +++ b/osgp/shared/osgp-ws-smartmetering/src/main/resources/SmartMeteringAdhoc.wsdl @@ -70,6 +70,25 @@ + + + + + + + + + + + + + + + @@ -176,6 +195,20 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -378,4 +443,4 @@ - \ No newline at end of file + diff --git a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd index 997da0103f4..55e44d29625 100644 --- a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd +++ b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd @@ -148,6 +148,7 @@ + @@ -204,6 +205,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd index 80f34e9d039..6bf4e132795 100644 --- a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd +++ b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd @@ -249,6 +249,14 @@ + + + + + + + @@ -417,6 +425,7 @@ + @@ -566,6 +575,14 @@ + + + + + + + @@ -698,6 +715,7 @@ + diff --git a/osgp/shared/shared/src/main/java/org/opensmartgridplatform/shared/infra/jms/MessageType.java b/osgp/shared/shared/src/main/java/org/opensmartgridplatform/shared/infra/jms/MessageType.java index 25343c4561c..7511d7f2e43 100644 --- a/osgp/shared/shared/src/main/java/org/opensmartgridplatform/shared/infra/jms/MessageType.java +++ b/osgp/shared/shared/src/main/java/org/opensmartgridplatform/shared/infra/jms/MessageType.java @@ -94,6 +94,7 @@ public enum MessageType { SET_RANDOMISATION_SETTINGS, SET_REBOOT, SET_SPECIAL_DAYS, + SET_SPECIFIC_ATTRIBUTE_VALUE, SET_TARIFF_SCHEDULE, SET_THD_CONFIGURATION, SET_TRANSITION, From f4418ba9ab0e84de46b4e9ae240d21e3d0335989 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Thu, 13 Feb 2025 11:14:04 +0100 Subject: [PATCH 04/10] SMHE-2164: Add Watchdog timer object to simulator Signed-off-by: stefanermens --- .../protocol/dlms/server/profile/Dsmr422Profile.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Dsmr422Profile.java b/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Dsmr422Profile.java index 66ffa8e8b9f..47e4d175768 100644 --- a/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Dsmr422Profile.java +++ b/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Dsmr422Profile.java @@ -15,6 +15,7 @@ import org.opensmartgridplatform.dlms.interfaceclass.attribute.ProfileGenericAttribute; import org.opensmartgridplatform.simulator.protocol.dlms.cosem.CaptureObject; import org.opensmartgridplatform.simulator.protocol.dlms.cosem.DefinableLoadProfile; +import org.opensmartgridplatform.simulator.protocol.dlms.cosem.LongUnsignedData; import org.opensmartgridplatform.simulator.protocol.dlms.util.DynamicValues; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -77,4 +78,10 @@ public DefinableLoadProfile definableLoadProfile( return new DefinableLoadProfile(dynamicValues, cal, null, DEFAULT_CAPTURE_OBJECTS); } + + @Bean + public LongUnsignedData watchdogTimer() { + final String obisCode = "0.1.94.31.2.255"; + return new LongUnsignedData(obisCode, 72); // Default timer is 72 hours + } } From 1b123ecb0ecb6bac6eb1919a1442f40c86aa7a03 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Fri, 14 Feb 2025 15:05:33 +0100 Subject: [PATCH 05/10] SMHE-2164: Add cucumber test for Set specific attribute value Signed-off-by: stefanermens --- .../PlatformSmartmeteringKeys.java | 3 + .../SetSpecificAttributeValue.java | 63 +++++++++++++++++++ ...tSpecificAttributeValueRequestFactory.java | 41 ++++++++++++ .../ad-hoc/SetSpecificAttributeValue.feature | 37 +++++++++++ .../application/services/AdhocService.java | 2 +- ...ttributeValueResponseMessageProcessor.java | 4 +- .../services/ActionMapperService.java | 2 +- .../endpoints/SmartMeteringAdhocEndpoint.java | 23 ++----- .../SetSpecificAttributeValueRequest.java | 6 +- .../SetSpecificAttributeValueRequestData.java | 30 ++++----- ...SpecificAttributeValueCommandExecutor.java | 12 ++-- ...AttributeValueRequestMessageProcessor.java | 5 +- .../dlms/server/profile/Smr5Profile.java | 7 +++ .../SetSpecificAttributeValueRequestDto.java | 10 +-- .../schemas/adhoc-ws-smartmetering.xsd | 5 +- .../schemas/bundle-ws-smartmetering.xsd | 2 +- .../schemas/notification-ws-smartmetering.xsd | 1 + 17 files changed, 194 insertions(+), 59 deletions(-) create mode 100644 integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java create mode 100644 integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java create mode 100644 integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/PlatformSmartmeteringKeys.java b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/PlatformSmartmeteringKeys.java index c9a8ced8f15..dffde4a247b 100644 --- a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/PlatformSmartmeteringKeys.java +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/PlatformSmartmeteringKeys.java @@ -179,4 +179,7 @@ public class PlatformSmartmeteringKeys public static final String PUSH_OBJECT_OBIS_CODES = "PushObjectObisCodes"; public static final String PUSH_OBJECT_ATTRIBUTE_IDS = "PushObjectAttributeIds"; public static final String PUSH_OBJECT_DATA_INDEXES = "PushObjectDataIndexes"; + + public static final String OBJECT_TYPE = "ObjectType"; + public static final String INT_VALUE = "IntValue"; } diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java new file mode 100644 index 00000000000..18e5798d5d7 --- /dev/null +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java @@ -0,0 +1,63 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.cucumber.platform.smartmetering.glue.steps.ws.smartmetering.smartmeteringadhoc; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.util.Map; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncRequest; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncResponse; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueRequest; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueResponse; +import org.opensmartgridplatform.cucumber.core.ScenarioContext; +import org.opensmartgridplatform.cucumber.platform.PlatformKeys; +import org.opensmartgridplatform.cucumber.platform.smartmetering.PlatformSmartmeteringKeys; +import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc.SetSpecificAttributeValueRequestFactory; +import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc.SmartMeteringAdHocRequestClient; +import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc.SmartMeteringAdHocResponseClient; +import org.springframework.beans.factory.annotation.Autowired; + +public class SetSpecificAttributeValue { + + @Autowired + private SmartMeteringAdHocRequestClient< + SetSpecificAttributeValueAsyncResponse, SetSpecificAttributeValueRequest> + requestClient; + + @Autowired + private SmartMeteringAdHocResponseClient< + SetSpecificAttributeValueResponse, SetSpecificAttributeValueAsyncRequest> + responseClient; + + @When("^the Set Specific Attribute value request is received$") + public void whenTheSetSpecificAttributeValueRequestIsReceived(final Map settings) + throws Throwable { + + final SetSpecificAttributeValueRequest request = + SetSpecificAttributeValueRequestFactory.fromParameterMap(settings); + final SetSpecificAttributeValueAsyncResponse asyncResponse = + this.requestClient.doRequest(request); + + assertThat(asyncResponse).as("AsyncResponse should not be null").isNotNull(); + ScenarioContext.current() + .put(PlatformKeys.KEY_CORRELATION_UID, asyncResponse.getCorrelationUid()); + } + + @Then("^the Set Specific Attribute value response should be returned$") + public void thenTheValueShouldBeSetOnTheDevice(final Map settings) + throws Throwable { + + final SetSpecificAttributeValueAsyncRequest asyncRequest = + SetSpecificAttributeValueRequestFactory.fromScenarioContext(); + final SetSpecificAttributeValueResponse response = + this.responseClient.getResponse(asyncRequest); + + assertThat(response.getResult().name()) + .as("Result is not as expected.") + .isEqualTo(settings.get(PlatformSmartmeteringKeys.RESULT)); + } +} diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java new file mode 100644 index 00000000000..95eaa88424e --- /dev/null +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java @@ -0,0 +1,41 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.adhoc; + +import java.math.BigInteger; +import java.util.Map; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ObjectType; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncRequest; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueRequest; +import org.opensmartgridplatform.cucumber.platform.smartmetering.PlatformSmartmeteringKeys; +import org.opensmartgridplatform.cucumber.platform.smartmetering.support.ws.smartmetering.RequestFactoryHelper; + +public class SetSpecificAttributeValueRequestFactory { + + private SetSpecificAttributeValueRequestFactory() { + // Private constructor for utility class + } + + public static SetSpecificAttributeValueRequest fromParameterMap( + final Map parameters) { + final SetSpecificAttributeValueRequest request = new SetSpecificAttributeValueRequest(); + request.setDeviceIdentification( + parameters.get(PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION)); + request.setObjectType( + ObjectType.valueOf(parameters.get(PlatformSmartmeteringKeys.OBJECT_TYPE))); + request.setAttribute(new BigInteger(parameters.get(PlatformSmartmeteringKeys.ATTRIBUTE))); + request.setIntValue(new BigInteger(parameters.get(PlatformSmartmeteringKeys.INT_VALUE))); + return request; + } + + public static SetSpecificAttributeValueAsyncRequest fromScenarioContext() { + final SetSpecificAttributeValueAsyncRequest asyncRequest = + new SetSpecificAttributeValueAsyncRequest(); + asyncRequest.setCorrelationUid(RequestFactoryHelper.getCorrelationUidFromScenarioContext()); + asyncRequest.setDeviceIdentification( + RequestFactoryHelper.getDeviceIdentificationFromScenarioContext()); + return asyncRequest; + } +} diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature b/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature new file mode 100644 index 00000000000..20c1be15e34 --- /dev/null +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature @@ -0,0 +1,37 @@ +# SPDX-FileCopyrightText: Contributors to the GXF project +# +# SPDX-License-Identifier: Apache-2.0 + +@SmartMetering @Platform @SmartMeteringAdHoc +Feature: SmartMetering AdHoc + As a grid operator + I want to be able to set a specific attribute value in a device + So I can change the configuration of a device + + Scenario Outline: Set watchdog timer for a device + Given a dlms device + | DeviceIdentification | | + | DeviceType | SMART_METER_E | + | Protocol | | + | ProtocolVersion | | + When the Set Specific Attribute value request is received + | DeviceIdentification | | + | ObjectType | WATCHDOG_TIMER | + | Attribute | 2 | + | IntValue | 42 | + Then the Set Specific Attribute value response should be returned + | DeviceIdentification | | + | Result | | + + Examples: + | deviceIdentification | protocol | version | response | + | TEST1024000000001 | DSMR | 4.2.2 | OK | + @NightlyBuildOnly + Examples: + | deviceIdentification | protocol | version | response | + | TEST1024000000001 | DSMR | 2.2 | NOT_OK | + | TEST1031000000001 | SMR | 4.3 | OK | + | TEST1027000000001 | SMR | 5.0.0 | OK | + | TEST1028000000001 | SMR | 5.1 | OK | + | TEST1029000000001 | SMR | 5.2 | OK | + | TEST1030000000001 | SMR | 5.5 | OK | diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java index 6e70d8435a5..fb82108b36b 100644 --- a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/application/services/AdhocService.java @@ -264,7 +264,7 @@ public void setSpecificAttributeValue( final SetSpecificAttributeValueRequestDto requestDto = new SetSpecificAttributeValueRequestDto( - request.getDlmsObjectTag(), request.getAttributeId(), request.getIntValue()); + request.getObjectType(), request.getAttribute(), request.getIntValue()); this.osgpCoreRequestMessageSender.send( requestDto, diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java index 77435186b5c..3abf2fe04bf 100644 --- a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java @@ -39,7 +39,9 @@ public SetSpecificAttributeValueResponseMessageProcessor( @Override protected boolean hasRegularResponseObject(final ResponseMessage responseMessage) { - return responseMessage.getDataObject() instanceof String; + // Only the Result (OK/NOK/Exception) is returned, no need to check the (contents of the + // dataObject). + return true; } @Override diff --git a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java index 1c1f6c70c59..cfab960971e 100644 --- a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java +++ b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/application/services/ActionMapperService.java @@ -239,7 +239,7 @@ public class ActionMapperService { CLASS_MAP.put( org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc .SetSpecificAttributeValueRequestData.class, - SpecificAttributeValueRequestData.class); + SetSpecificAttributeValueRequestData.class); CLASS_MAP.put( org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration .SetClockConfigurationRequestData.class, diff --git a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java index 020dfbaf73b..4664c1e9e03 100644 --- a/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java +++ b/osgp/platform/osgp-adapter-ws-smartmetering/src/main/java/org/opensmartgridplatform/adapter/ws/smartmetering/endpoints/SmartMeteringAdhocEndpoint.java @@ -340,19 +340,19 @@ public SetSpecificAttributeValueAsyncResponse setSpecificAttributeValue( throws OsgpException { final org.opensmartgridplatform.domain.core.valueobjects.smartmetering - .SpecificAttributeValueRequest + .SetSpecificAttributeValueRequest setSpecificAttributeValueRequest = this.adhocMapper.map( request, org.opensmartgridplatform.domain.core.valueobjects.smartmetering - .SpecificAttributeValueRequest.class); + .SetSpecificAttributeValueRequest.class); final RequestMessageMetadata requestMessageMetadata = RequestMessageMetadata.newBuilder() .withOrganisationIdentification(organisationIdentification) .withDeviceIdentification(request.getDeviceIdentification()) - .withDeviceFunction(DeviceFunction.GET_SPECIFIC_ATTRIBUTE_VALUE) - .withMessageType(MessageType.GET_SPECIFIC_ATTRIBUTE_VALUE) + .withDeviceFunction(DeviceFunction.SET_SPECIFIC_ATTRIBUTE_VALUE) + .withMessageType(MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE) .withMessagePriority(messagePriority) .withScheduleTime(scheduleTime) .withBypassRetry(bypassRetry) @@ -382,21 +382,6 @@ public SetSpecificAttributeValueResponse setSpecificAttributeValueResponse( request.getCorrelationUid(), ComponentType.WS_SMART_METERING); response.setResult(OsgpResultType.fromValue(responseData.getResultType().getValue())); - if (ResponseMessageResultType.OK == responseData.getResultType()) { - response.setAttributeValueData((String) responseData.getMessageData()); - } else if (responseData.getMessageData() instanceof OsgpException) { - throw (OsgpException) responseData.getMessageData(); - } else if (responseData.getMessageData() instanceof Exception) { - throw new TechnicalException( - ComponentType.WS_SMART_METERING, - "An exception occurred: Set specific attribute value", - (Exception) responseData.getMessageData()); - } else { - throw new TechnicalException( - ComponentType.WS_SMART_METERING, - "An exception occurred: Set specific attribute value", - null); - } } catch (final Exception e) { this.handleException(e); } diff --git a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java index f17ec94d035..1c4c9bfc234 100644 --- a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java +++ b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequest.java @@ -11,11 +11,11 @@ public class SetSpecificAttributeValueRequest extends SetSpecificAttributeValueR private final String deviceIdentification; public SetSpecificAttributeValueRequest( - final String dlmsObjectTag, - final int attributeId, + final String objectType, + final int attribute, final int intValue, final String deviceIdentification) { - super(dlmsObjectTag, attributeId, intValue); + super(objectType, attribute, intValue); this.deviceIdentification = deviceIdentification; } diff --git a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java index 81846cd9955..75abcc10429 100644 --- a/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java +++ b/osgp/platform/osgp-domain-core/src/main/java/org/opensmartgridplatform/domain/core/valueobjects/smartmetering/SetSpecificAttributeValueRequestData.java @@ -12,24 +12,24 @@ public class SetSpecificAttributeValueRequestData implements Serializable, Actio private static final long serialVersionUID = -7326169764207317011L; - private final String dlmsObjectTag; - private final int attributeId; + private final String objectType; + private final int attribute; private final int intValue; public SetSpecificAttributeValueRequestData( - final String dlmsObjectType, final int attributeId, final int intValue) { + final String objectType, final int attribute, final int intValue) { super(); - this.dlmsObjectTag = dlmsObjectType; - this.attributeId = attributeId; + this.objectType = objectType; + this.attribute = attribute; this.intValue = intValue; } - public String getDlmsObjectTag() { - return this.dlmsObjectTag; + public String getObjectType() { + return this.objectType; } - public int getAttributeId() { - return this.attributeId; + public int getAttribute() { + return this.attribute; } public int getIntValue() { @@ -45,9 +45,9 @@ public void validate() throws FunctionalException { public int hashCode() { final int prime = 31; int result = 1; - result = (prime * result) + this.attributeId; + result = (prime * result) + this.attribute; result = (prime * result) + this.intValue; - result = (prime * result) + this.dlmsObjectTag.hashCode(); + result = (prime * result) + this.objectType.hashCode(); return result; } @@ -63,17 +63,17 @@ public boolean equals(final Object obj) { return false; } final SetSpecificAttributeValueRequestData other = (SetSpecificAttributeValueRequestData) obj; - if (this.attributeId != other.attributeId) { + if (this.attribute != other.attribute) { return false; } if (this.intValue != other.intValue) { return false; } - if (this.dlmsObjectTag == null) { - if (other.dlmsObjectTag != null) { + if (this.objectType == null) { + if (other.objectType != null) { return false; } - } else if (!this.dlmsObjectTag.equals(other.dlmsObjectTag)) { + } else if (!this.objectType.equals(other.objectType)) { return false; } return true; diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java index 499b755f8e9..0a85438e212 100644 --- a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java @@ -57,7 +57,7 @@ public Void execute( final MessageMetadata messageMetadata) throws FunctionalException, ProtocolAdapterException { - final DlmsObjectType objectType = DlmsObjectType.valueOf(requestData.getDlmsObjectTag()); + final DlmsObjectType objectType = DlmsObjectType.valueOf(requestData.getObjectType()); final CosemObject cosemObject; try { cosemObject = @@ -67,7 +67,7 @@ public Void execute( throw new ProtocolAdapterException(AbstractCommandExecutor.ERROR_IN_OBJECT_CONFIG, e); } - final Attribute attribute = cosemObject.getAttribute(requestData.getAttributeId()); + final Attribute attribute = cosemObject.getAttribute(requestData.getAttribute()); final DlmsDataType dataType = attribute.getDatatype(); @@ -90,22 +90,22 @@ public Void execute( new AttributeAddress( cosemObject.getClassId(), new ObisCode(cosemObject.getObis()), - requestData.getAttributeId()); + requestData.getAttribute()); final SetParameter setParameter = new SetParameter(attributeAddress, data); log.debug( "Set specific attribute value, class id: {}, obis code: {}, attribute id: {}, value: {}", cosemObject.getClassId(), cosemObject.getObis(), - requestData.getAttributeId(), + requestData.getAttribute(), requestData.getIntValue()); final List resultCodes = this.dlmsHelper.setWithList(conn, device, List.of(setParameter)); if (!resultCodes.stream().allMatch(code -> code.equals(AccessResultCode.SUCCESS))) { - log.debug("Result of THD configuration is {}", resultCodes); - throw new ProtocolAdapterException("THD configuration resulted in: " + resultCodes); + log.debug("Result of Set specific value is {}", resultCodes); + throw new ProtocolAdapterException("Set specific value resulted in: " + resultCodes); } return null; diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java index ec29e96aeaa..926ae247c51 100644 --- a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/infra/messaging/processors/SetSpecificAttributeValueRequestMessageProcessor.java @@ -11,7 +11,6 @@ import org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException; import org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DeviceRequestMessageProcessor; import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto; -import org.opensmartgridplatform.dto.valueobjects.smartmetering.SpecificAttributeValueRequestDto; import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException; import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; import org.opensmartgridplatform.shared.infra.jms.MessageType; @@ -24,7 +23,7 @@ public class SetSpecificAttributeValueRequestMessageProcessor private final AdhocService adhocService; protected SetSpecificAttributeValueRequestMessageProcessor(final AdhocService adhocService) { - super(MessageType.GET_SPECIFIC_ATTRIBUTE_VALUE); + super(MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE); this.adhocService = adhocService; } @@ -36,7 +35,7 @@ protected Serializable handleMessage( final MessageMetadata messageMetadata) throws ProtocolAdapterException, FunctionalException { - this.assertRequestObjectType(SpecificAttributeValueRequestDto.class, requestObject); + this.assertRequestObjectType(SetSpecificAttributeValueRequestDto.class, requestObject); final SetSpecificAttributeValueRequestDto request = (SetSpecificAttributeValueRequestDto) requestObject; diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Smr5Profile.java b/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Smr5Profile.java index 875b67f86b2..e199d518edd 100644 --- a/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Smr5Profile.java +++ b/osgp/protocol-adapter-dlms/osgp-protocol-simulator-dlms/simulator/dlms-device-simulator/src/main/java/org/opensmartgridplatform/simulator/protocol/dlms/server/profile/Smr5Profile.java @@ -27,6 +27,7 @@ import org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic; import org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.AdjacentCellInfo; import org.opensmartgridplatform.simulator.protocol.dlms.cosem.GsmDiagnostic.CellInfo; +import org.opensmartgridplatform.simulator.protocol.dlms.cosem.LongUnsignedData; import org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusDailyBillingValuesPeriod1SMR5; import org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusDriverActiveFirmwareIdentifier; import org.opensmartgridplatform.simulator.protocol.dlms.cosem.MBusDriverActiveFirmwareSignature; @@ -712,4 +713,10 @@ public GsmDiagnostic gsmGprsDiagnostic() { adjacentCellInfos, captureTime); } + + @Bean + public LongUnsignedData watchdogTimer() { + final String obisCode = "0.1.94.31.2.255"; + return new LongUnsignedData(obisCode, 72); // Default timer is 72 hours + } } diff --git a/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java index 0a46c848bc2..aa09864e6d1 100644 --- a/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java +++ b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/SetSpecificAttributeValueRequestDto.java @@ -12,15 +12,15 @@ public class SetSpecificAttributeValueRequestDto implements ActionRequestDto { @Serial private static final long serialVersionUID = 6091630820323702494L; - private final String dlmsObjectTag; - private final int attributeId; + private final String objectType; + private final int attribute; private final Integer intValue; public SetSpecificAttributeValueRequestDto( - final String dlmsObjectTag, final int attributeId, final Integer intValue) { + final String objectType, final int attribute, final Integer intValue) { super(); - this.dlmsObjectTag = dlmsObjectTag; - this.attributeId = attributeId; + this.objectType = objectType; + this.attribute = attribute; this.intValue = intValue; } } diff --git a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd index 55e44d29625..3c4ff1c1fa3 100644 --- a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd +++ b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd @@ -235,9 +235,6 @@ - - - @@ -247,7 +244,7 @@ - + diff --git a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd index 6bf4e132795..cec39293040 100644 --- a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd +++ b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/bundle-ws-smartmetering.xsd @@ -579,7 +579,7 @@ + base="adhoc:SetSpecificAttributeValueResponseData" /> diff --git a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/notification-ws-smartmetering.xsd b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/notification-ws-smartmetering.xsd index 90fb427a76a..618802a4378 100644 --- a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/notification-ws-smartmetering.xsd +++ b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/notification-ws-smartmetering.xsd @@ -56,6 +56,7 @@ + From c34dd780cd8c6b8ddefc6764c9a397d183bf7fad Mon Sep 17 00:00:00 2001 From: stefanermens Date: Mon, 17 Feb 2025 16:04:20 +0100 Subject: [PATCH 06/10] SMHE-2164: Add unit test for SetSpecificAttributeValueCommandExecutor Signed-off-by: stefanermens --- ...SpecificAttributeValueCommandExecutor.java | 28 +++-- ...ificAttributeValueCommandExecutorTest.java | 112 ++++++++++++++++++ 2 files changed, 127 insertions(+), 13 deletions(-) create mode 100644 osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java index 0a85438e212..cf61ae914db 100644 --- a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/main/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutor.java @@ -4,17 +4,17 @@ package org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc; -import java.util.List; +import java.io.IOException; import lombok.extern.slf4j.Slf4j; -import org.openmuc.jdlms.AccessResultCode; import org.openmuc.jdlms.AttributeAddress; import org.openmuc.jdlms.ObisCode; import org.openmuc.jdlms.SetParameter; import org.openmuc.jdlms.datatypes.DataObject; import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.AbstractCommandExecutor; -import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.JdlmsObjectToStringUtil; import org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice; import org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager; +import org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException; import org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException; import org.opensmartgridplatform.dlms.exceptions.ObjectConfigException; import org.opensmartgridplatform.dlms.objectconfig.Attribute; @@ -33,14 +33,11 @@ public class SetSpecificAttributeValueCommandExecutor extends AbstractCommandExecutor { - private final DlmsHelper dlmsHelper; private final ObjectConfigService objectConfigService; - public SetSpecificAttributeValueCommandExecutor( - final DlmsHelper dlmsHelper, final ObjectConfigService objectConfigService) { + public SetSpecificAttributeValueCommandExecutor(final ObjectConfigService objectConfigService) { super(SetSpecificAttributeValueRequestDto.class); this.objectConfigService = objectConfigService; - this.dlmsHelper = dlmsHelper; } @Override @@ -93,6 +90,13 @@ public Void execute( requestData.getAttribute()); final SetParameter setParameter = new SetParameter(attributeAddress, data); + conn.getDlmsMessageListener() + .setDescription( + "Setting value in " + + requestData.getObjectType() + + ", set attribute: " + + JdlmsObjectToStringUtil.describeAttributes(attributeAddress)); + log.debug( "Set specific attribute value, class id: {}, obis code: {}, attribute id: {}, value: {}", cosemObject.getClassId(), @@ -100,12 +104,10 @@ public Void execute( requestData.getAttribute(), requestData.getIntValue()); - final List resultCodes = - this.dlmsHelper.setWithList(conn, device, List.of(setParameter)); - - if (!resultCodes.stream().allMatch(code -> code.equals(AccessResultCode.SUCCESS))) { - log.debug("Result of Set specific value is {}", resultCodes); - throw new ProtocolAdapterException("Set specific value resulted in: " + resultCodes); + try { + conn.getConnection().set(setParameter); + } catch (final IOException e) { + throw new ConnectionException(e); } return null; diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java new file mode 100644 index 00000000000..1d64716c9bf --- /dev/null +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java @@ -0,0 +1,112 @@ +// SPDX-FileCopyrightText: Copyright Contributors to the GXF project +// +// SPDX-License-Identifier: Apache-2.0 + +package org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.misc; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.openmuc.jdlms.AccessResultCode; +import org.openmuc.jdlms.AttributeAddress; +import org.openmuc.jdlms.DlmsConnection; +import org.openmuc.jdlms.SetParameter; +import org.openmuc.jdlms.datatypes.DataObject; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol; +import org.opensmartgridplatform.adapter.protocol.dlms.domain.factories.DlmsConnectionManager; +import org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.DlmsMessageListener; +import org.opensmartgridplatform.dlms.exceptions.ObjectConfigException; +import org.opensmartgridplatform.dlms.services.ObjectConfigService; +import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetSpecificAttributeValueRequestDto; +import org.opensmartgridplatform.shared.infra.jms.MessageMetadata; + +@ExtendWith(MockitoExtension.class) +class SetSpecificAttributeValueCommandExecutorTest { + + private SetSpecificAttributeValueCommandExecutor executor; + + @Mock private DlmsMessageListener dlmsMessageListener; + + @Mock private DlmsConnectionManager connectionManager; + + @Mock private DlmsConnection dlmsConnection; + + @Captor private ArgumentCaptor setParameterArgumentCaptor; + + private static final String WATCHDOG_OBJECT_TYPE = "WATCHDOG_TIMER"; + private static final String WATCHDOG_TIMER_OBIS = "0.1.94.31.2.255"; + private static final int CLASS_ID = 1; + private static final int ATTRIBUTE_ID = 2; + private static final int VALUE = 25; + + @BeforeEach + public void setUp() throws IOException, ObjectConfigException { + final ObjectConfigService objectConfigService = new ObjectConfigService(); + this.executor = new SetSpecificAttributeValueCommandExecutor(objectConfigService); + } + + @ParameterizedTest + @EnumSource( + value = Protocol.class, + names = {"DSMR_2_2", "OTHER_PROTOCOL"}, + mode = EnumSource.Mode.EXCLUDE) + void testExecute(final Protocol protocol) throws Exception { + + final DlmsDevice testDevice = new DlmsDevice(); + testDevice.setProtocol(protocol); + testDevice.setWithListMax(1); + + final SetSpecificAttributeValueRequestDto requestData = + new SetSpecificAttributeValueRequestDto(WATCHDOG_OBJECT_TYPE, ATTRIBUTE_ID, VALUE); + + final AttributeAddress attributeAddress = + new AttributeAddress(CLASS_ID, this.WATCHDOG_TIMER_OBIS, ATTRIBUTE_ID, null); + final SetParameter expectedSetParameter = + new SetParameter(attributeAddress, DataObject.newUInteger16Data(VALUE)); + + when(this.connectionManager.getDlmsMessageListener()).thenReturn(this.dlmsMessageListener); + when(this.connectionManager.getConnection()).thenReturn(this.dlmsConnection); + when(this.dlmsConnection.set(this.setParameterArgumentCaptor.capture())) + .thenReturn(AccessResultCode.SUCCESS); + + // CALL + this.executor.execute( + this.connectionManager, testDevice, requestData, mock(MessageMetadata.class)); + + // VERIFY + assertThat(this.setParameterArgumentCaptor.getValue()) + .usingRecursiveComparison() + .isEqualTo(expectedSetParameter); + } + + @Test + void testExecuteNoObject() { + + final DlmsDevice testDevice = new DlmsDevice(); + testDevice.setProtocol(Protocol.DSMR_2_2); + + final SetSpecificAttributeValueRequestDto requestData = + new SetSpecificAttributeValueRequestDto(WATCHDOG_OBJECT_TYPE, ATTRIBUTE_ID, VALUE); + + // CALL + assertThrows( + IllegalArgumentException.class, + () -> { + this.executor.execute( + this.connectionManager, testDevice, requestData, mock(MessageMetadata.class)); + }); + } +} From 295b7a78642ce47357b37dbd2b0bc070a11f4934 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Mon, 17 Feb 2025 16:08:52 +0100 Subject: [PATCH 07/10] SMHE-2164: Solve sonar issues Signed-off-by: stefanermens --- ...SetSpecificAttributeValueResponseMessageProcessor.java | 8 ++++---- .../SetSpecificAttributeValueRequestMessageProcessor.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java index 3abf2fe04bf..d8eb434bb62 100644 --- a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/core/messageprocessors/SetSpecificAttributeValueResponseMessageProcessor.java @@ -21,20 +21,20 @@ public class SetSpecificAttributeValueResponseMessageProcessor extends OsgpCoreResponseMessageProcessor { - @Autowired - @Qualifier("domainSmartMeteringAdhocService") - private AdhocService adhocService; + private final AdhocService adhocService; @Autowired public SetSpecificAttributeValueResponseMessageProcessor( final WebServiceResponseMessageSender responseMessageSender, @Qualifier("domainSmartMeteringInboundOsgpCoreResponsesMessageProcessorMap") - final MessageProcessorMap messageProcessorMap) { + final MessageProcessorMap messageProcessorMap, + @Qualifier("domainSmartMeteringAdhocService") final AdhocService adhocService) { super( responseMessageSender, messageProcessorMap, MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE, ComponentType.DOMAIN_SMART_METERING); + this.adhocService = adhocService; } @Override diff --git a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java index 494b678cf22..34d924326bb 100644 --- a/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java +++ b/osgp/platform/osgp-adapter-domain-smartmetering/src/main/java/org/opensmartgridplatform/adapter/domain/smartmetering/infra/jms/ws/messageprocessors/SetSpecificAttributeValueRequestMessageProcessor.java @@ -18,15 +18,15 @@ @Component public class SetSpecificAttributeValueRequestMessageProcessor extends BaseRequestMessageProcessor { - @Autowired - @Qualifier("domainSmartMeteringAdhocService") - private AdhocService adhocService; + private final AdhocService adhocService; @Autowired protected SetSpecificAttributeValueRequestMessageProcessor( @Qualifier("domainSmartMeteringInboundWebServiceRequestsMessageProcessorMap") - final MessageProcessorMap messageProcessorMap) { + final MessageProcessorMap messageProcessorMap, + @Qualifier("domainSmartMeteringAdhocService") final AdhocService adhocService) { super(messageProcessorMap, MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE); + this.adhocService = adhocService; } @Override From 10ecfb83949162fe7d218331267f3484ba9d5da5 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Thu, 20 Feb 2025 09:47:02 +0100 Subject: [PATCH 08/10] SMHE-2164: Rename to AllowedObjectType Signed-off-by: stefanermens --- .../smartmeteringadhoc/SetSpecificAttributeValue.java | 4 ++-- .../adhoc/SetSpecificAttributeValueRequestFactory.java | 4 ++-- .../ad-hoc/SetSpecificAttributeValue.feature | 4 ++-- .../src/main/resources/schemas/adhoc-ws-smartmetering.xsd | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java index 18e5798d5d7..939b6796cf3 100644 --- a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/glue/steps/ws/smartmetering/smartmeteringadhoc/SetSpecificAttributeValue.java @@ -33,7 +33,7 @@ public class SetSpecificAttributeValue { SetSpecificAttributeValueResponse, SetSpecificAttributeValueAsyncRequest> responseClient; - @When("^the Set Specific Attribute value request is received$") + @When("^the Set Specific Attribute Value request is received$") public void whenTheSetSpecificAttributeValueRequestIsReceived(final Map settings) throws Throwable { @@ -47,7 +47,7 @@ public void whenTheSetSpecificAttributeValueRequestIsReceived(final Map settings) throws Throwable { diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java index 95eaa88424e..5eba6bb7f74 100644 --- a/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/java/org/opensmartgridplatform/cucumber/platform/smartmetering/support/ws/smartmetering/adhoc/SetSpecificAttributeValueRequestFactory.java @@ -6,7 +6,7 @@ import java.math.BigInteger; import java.util.Map; -import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.ObjectType; +import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.AllowedObjectType; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueAsyncRequest; import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.SetSpecificAttributeValueRequest; import org.opensmartgridplatform.cucumber.platform.smartmetering.PlatformSmartmeteringKeys; @@ -24,7 +24,7 @@ public static SetSpecificAttributeValueRequest fromParameterMap( request.setDeviceIdentification( parameters.get(PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION)); request.setObjectType( - ObjectType.valueOf(parameters.get(PlatformSmartmeteringKeys.OBJECT_TYPE))); + AllowedObjectType.valueOf(parameters.get(PlatformSmartmeteringKeys.OBJECT_TYPE))); request.setAttribute(new BigInteger(parameters.get(PlatformSmartmeteringKeys.ATTRIBUTE))); request.setIntValue(new BigInteger(parameters.get(PlatformSmartmeteringKeys.INT_VALUE))); return request; diff --git a/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature b/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature index 20c1be15e34..50f595bfaa0 100644 --- a/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature +++ b/integration-tests/cucumber-tests-platform-smartmetering/src/test/resources/features/osgp-adapter-ws-smartmetering/ad-hoc/SetSpecificAttributeValue.feature @@ -14,12 +14,12 @@ Feature: SmartMetering AdHoc | DeviceType | SMART_METER_E | | Protocol | | | ProtocolVersion | | - When the Set Specific Attribute value request is received + When the Set Specific Attribute Value request is received | DeviceIdentification | | | ObjectType | WATCHDOG_TIMER | | Attribute | 2 | | IntValue | 42 | - Then the Set Specific Attribute value response should be returned + Then the Set Specific Attribute Value response should be returned | DeviceIdentification | | | Result | | diff --git a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd index 3c4ff1c1fa3..b7e86114ea5 100644 --- a/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd +++ b/osgp/shared/osgp-ws-smartmetering/src/main/resources/schemas/adhoc-ws-smartmetering.xsd @@ -243,7 +243,7 @@ - + @@ -259,7 +259,7 @@ - + From 63eb0fbde27e0fd7072d32de9b3d98a2ea241862 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Thu, 20 Feb 2025 09:53:49 +0100 Subject: [PATCH 09/10] SMHE-2164: Remove comma Signed-off-by: stefanermens --- .../dto/valueobjects/smartmetering/NotificationTypeDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java index 16cc3d6544a..f7d2eb1803a 100644 --- a/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java +++ b/osgp/shared/osgp-dto/src/main/java/org/opensmartgridplatform/dto/valueobjects/smartmetering/NotificationTypeDto.java @@ -59,5 +59,5 @@ public enum NotificationTypeDto { SYSTEM_EVENT, CLEAR_MBUS_STATUS_ON_ALL_CHANNELS, SET_THD_CONFIGURATION, - GET_THD_FINGERPRINT, + GET_THD_FINGERPRINT } From 941f19b6a90976c621688980de0dc801f5c211a5 Mon Sep 17 00:00:00 2001 From: stefanermens Date: Thu, 20 Feb 2025 10:36:19 +0100 Subject: [PATCH 10/10] SMHE-2164: Solve sonar issue Signed-off-by: stefanermens --- .../misc/SetSpecificAttributeValueCommandExecutorTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java index 1d64716c9bf..8854ea56641 100644 --- a/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java +++ b/osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/src/test/java/org/opensmartgridplatform/adapter/protocol/dlms/domain/commands/misc/SetSpecificAttributeValueCommandExecutorTest.java @@ -53,7 +53,7 @@ class SetSpecificAttributeValueCommandExecutorTest { private static final int VALUE = 25; @BeforeEach - public void setUp() throws IOException, ObjectConfigException { + void setUp() throws IOException, ObjectConfigException { final ObjectConfigService objectConfigService = new ObjectConfigService(); this.executor = new SetSpecificAttributeValueCommandExecutor(objectConfigService); }