Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle requests for G-meter devices without a gateway device are not … #1159

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeviceType is een String hier......

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);
}
}
Loading