Skip to content

Commit

Permalink
Merge pull request #1159 from OSGP/feature/SMHE-1767_bundle_request_o…
Browse files Browse the repository at this point in the history
…n_gmeter

Bundle requests for G-meter devices without a gateway device are not …
  • Loading branch information
kroesctrl authored Jan 18, 2024
2 parents 15610ea + 25dff49 commit f001c82
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.cucumber.java.Scenario;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import java.util.HashMap;
import java.util.Map;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.GetSpecificAttributeValueAsyncRequest;
import org.opensmartgridplatform.adapter.ws.schema.smartmetering.adhoc.GetSpecificAttributeValueAsyncResponse;
Expand Down Expand Up @@ -238,4 +239,9 @@ public void theBundleRequestGeneratingAnErrorIsReceivedWithHeaders(
ScenarioContext.current().put(PlatformKeys.RESPONSE, exception);
}
}

@When("^the bundle request generating an error is received$")
public void theBundleRequestGeneratingAnErrorIsReceived() throws Throwable {
this.theBundleRequestGeneratingAnErrorIsReceivedWithHeaders(new HashMap<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,36 @@ Feature: SmartMetering Bundle - GetActualMeterReads
| Message | VALIDATION_ERROR |
| InnerMessage | Meter for gas reads should have a channel configured. |

Scenario: Get actual meter reads of a G device without a gateway device
Given a dlms device
| DeviceIdentification | TESTG102400000001 |
| DeviceType | SMART_METER_G |
| Channel | 1 |
And a bundle request
| DeviceIdentification | TESTG102400000001 |
And the bundle request contains a get actual meter reads gas action
| DeviceIdentification | TESTG102400000001 |
When the bundle request is received
When the bundle request generating an error is received
Then a SOAP fault should have been returned
| Code | 401 |
| Message | VALIDATION_ERROR |
| Component | DOMAIN_SMART_METERING |
| InnerMessage | Bundle request is not allowed for gas meter |

Scenario: Get actual meter reads of a G device without a gateway device and bundle device is E meter
Given a dlms device
| DeviceIdentification | TEST1024000000001 |
| DeviceType | SMART_METER_E |
And a dlms device
| DeviceIdentification | TESTG102400000001 |
| DeviceType | SMART_METER_G |
| Channel | 1 |
And a bundle request
| DeviceIdentification | TEST1024000000001 |
And the bundle request contains a get actual meter reads gas action
| DeviceIdentification | TESTG102400000001 |
When the bundle request is received
Then the bundle response should contain a fault response
| Message | VALIDATION_ERROR |
| InnerMessage | Meter for gas reads should have an energy meter as gateway device. |
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.opensmartgridplatform.adapter.domain.smartmetering.application.mapping.ConfigurationMapper;
import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.core.JmsMessageSender;
import org.opensmartgridplatform.adapter.domain.smartmetering.infra.jms.ws.WebServiceResponseMessageSender;
import org.opensmartgridplatform.domain.core.entities.Device;
import org.opensmartgridplatform.domain.core.entities.SmartMeter;
import org.opensmartgridplatform.domain.core.valueobjects.FirmwareVersion;
import org.opensmartgridplatform.domain.core.valueobjects.smartmetering.BundleMessageRequest;
Expand All @@ -23,7 +24,9 @@
import org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionGasResponseDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.FirmwareVersionResponseDto;
import org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto;
import org.opensmartgridplatform.shared.exceptionhandling.ComponentType;
import org.opensmartgridplatform.shared.exceptionhandling.FunctionalException;
import org.opensmartgridplatform.shared.exceptionhandling.FunctionalExceptionType;
import org.opensmartgridplatform.shared.exceptionhandling.OsgpException;
import org.opensmartgridplatform.shared.infra.jms.MessageMetadata;
import org.opensmartgridplatform.shared.infra.jms.ResponseMessage;
Expand All @@ -38,7 +41,7 @@
@Service(value = "domainSmartMeteringBundleService")
@Transactional(value = "transactionManager")
public class BundleService {

private static final String SMART_METER_G = "SMART_METER_G";
private static final Logger LOGGER = LoggerFactory.getLogger(BundleService.class);

@Autowired
Expand Down Expand Up @@ -83,6 +86,8 @@ public void handleBundle(
final SmartMeter smartMeter =
this.domainHelperService.findSmartMeter(messageMetadata.getDeviceIdentification());

this.checkIfBundleRequestIsAllowed(smartMeter);

final List<SmartMeter> smartMeters = this.domainHelperService.searchMBusDevicesFor(smartMeter);
final String deviceModelCodes = createDeviceModelCodes(smartMeter, smartMeters);

Expand Down Expand Up @@ -169,4 +174,17 @@ private void checkIfAdditionalActionIsNeeded(
}
}
}

private void checkIfBundleRequestIsAllowed(final Device smartMeter) throws FunctionalException {
if (this.isGasMeter(smartMeter.getDeviceType())) {
throw new FunctionalException(
FunctionalExceptionType.VALIDATION_ERROR,
ComponentType.DOMAIN_SMART_METERING,
new AssertionError("Bundle request is not allowed for gas meter"));
}
}

private boolean isGasMeter(final String deviceType) {
return SMART_METER_G.equals(deviceType);
}
}

0 comments on commit f001c82

Please sign in to comment.