Skip to content

Commit

Permalink
SMHE-2164: Add SetSpecificAttributeValue
Browse files Browse the repository at this point in the history
SMHE-2164: Set watchdog value
  • Loading branch information
stefanermens authored Feb 21, 2025
2 parents 670eaeb + 941f19b commit a92a8f4
Show file tree
Hide file tree
Showing 31 changed files with 1,072 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<String, String> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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.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;
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<String, String> parameters) {
final SetSpecificAttributeValueRequest request = new SetSpecificAttributeValueRequest();
request.setDeviceIdentification(
parameters.get(PlatformSmartmeteringKeys.DEVICE_IDENTIFICATION));
request.setObjectType(
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;
}

public static SetSpecificAttributeValueAsyncRequest fromScenarioContext() {
final SetSpecificAttributeValueAsyncRequest asyncRequest =
new SetSpecificAttributeValueAsyncRequest();
asyncRequest.setCorrelationUid(RequestFactoryHelper.getCorrelationUidFromScenarioContext());
asyncRequest.setDeviceIdentification(
RequestFactoryHelper.getDeviceIdentificationFromScenarioContext());
return asyncRequest;
}
}
Original file line number Diff line number Diff line change
@@ -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 <protocol> <version> device
Given a dlms device
| DeviceIdentification | <deviceIdentification> |
| DeviceType | SMART_METER_E |
| Protocol | <protocol> |
| ProtocolVersion | <version> |
When the Set Specific Attribute Value request is received
| DeviceIdentification | <deviceIdentification> |
| ObjectType | WATCHDOG_TIMER |
| Attribute | 2 |
| IntValue | 42 |
Then the Set Specific Attribute Value response should be returned
| DeviceIdentification | <deviceIdentification> |
| Result | <response> |

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 |
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.getObjectType(), request.getAttribute(), 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(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 {

private final AdhocService adhocService;

@Autowired
public SetSpecificAttributeValueResponseMessageProcessor(
final WebServiceResponseMessageSender responseMessageSender,
@Qualifier("domainSmartMeteringInboundOsgpCoreResponsesMessageProcessorMap")
final MessageProcessorMap messageProcessorMap,
@Qualifier("domainSmartMeteringAdhocService") final AdhocService adhocService) {
super(
responseMessageSender,
messageProcessorMap,
MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE,
ComponentType.DOMAIN_SMART_METERING);
this.adhocService = adhocService;
}

@Override
protected boolean hasRegularResponseObject(final ResponseMessage responseMessage) {
// Only the Result (OK/NOK/Exception) is returned, no need to check the (contents of the
// dataObject).
return true;
}

@Override
protected void handleMessage(
final MessageMetadata deviceMessageMetadata,
final ResponseMessage responseMessage,
final OsgpException osgpException) {
this.adhocService.handleSetSpecificAttributeValueResponse(
deviceMessageMetadata,
responseMessage.getResult(),
osgpException,
(String) responseMessage.getDataObject());
}
}
Original file line number Diff line number Diff line change
@@ -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 {

private final AdhocService adhocService;

@Autowired
protected SetSpecificAttributeValueRequestMessageProcessor(
@Qualifier("domainSmartMeteringInboundWebServiceRequestsMessageProcessorMap")
final MessageProcessorMap messageProcessorMap,
@Qualifier("domainSmartMeteringAdhocService") final AdhocService adhocService) {
super(messageProcessorMap, MessageType.SET_SPECIFIC_ATTRIBUTE_VALUE);
this.adhocService = adhocService;
}

@Override
protected void handleMessage(final MessageMetadata deviceMessageMetadata, final Object dataObject)
throws FunctionalException {

final SetSpecificAttributeValueRequest request = (SetSpecificAttributeValueRequest) dataObject;

this.adhocService.setSpecificAttributeValue(deviceMessageMetadata, request);
}
}
Loading

0 comments on commit a92a8f4

Please sign in to comment.