use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigService method getDlmsObjectForCommunicationMethod.
public DlmsObject getDlmsObjectForCommunicationMethod(final DlmsDevice device, final DlmsObjectType type) throws ProtocolAdapterException {
final Protocol protocol = Protocol.forDevice(device);
final CommunicationMethod method = CommunicationMethod.getCommunicationMethod(device.getCommunicationMethod());
return this.dlmsObjectConfigs.stream().filter(config -> config.contains(protocol)).findAny().flatMap(dlmsObjectConfig -> dlmsObjectConfig.findObjectForCommunicationMethod(type, method)).orElseThrow(() -> new ProtocolAdapterException("Did not find " + type.name() + " object with communication method " + method.getMethodName() + " for device " + device.getDeviceId()));
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class SetActivityCalendarCommandExecutor method execute.
@Override
public AccessResultCode execute(final DlmsConnectionManager conn, final DlmsDevice device, final ActivityCalendarDto activityCalendar, final MessageMetadata messageMetadata) throws ProtocolAdapterException, FunctionalException {
LOGGER.debug("SetActivityCalendarCommandExecutor.execute {} called", activityCalendar.getCalendarName());
ActivityCalendarValidator.validate(activityCalendar);
final List<SeasonProfileDto> seasonProfileList = activityCalendar.getSeasonProfileList();
final Set<WeekProfileDto> weekProfileSet = this.getWeekProfileSet(seasonProfileList);
final Set<DayProfileDto> dayProfileSet = this.getDayProfileSet(weekProfileSet);
final DataObjectAttrExecutors dataObjectExecutors = new DataObjectAttrExecutors("SetActivityCalendar").addExecutor(this.getCalendarNameExecutor(activityCalendar)).addExecutor(this.getSeasonProfileExecutor(seasonProfileList)).addExecutor(this.getWeekProfileTableExecutor(weekProfileSet)).addExecutor(this.getDayProfileTablePassiveExecutor(dayProfileSet));
conn.getDlmsMessageListener().setDescription("SetActivityCalendar for calendar " + activityCalendar.getCalendarName() + ", set attributes: " + dataObjectExecutors.describeAttributes());
dataObjectExecutors.execute(conn);
LOGGER.info("Finished setting the passive activity calendar");
// in the exception to throw
try {
this.setActivityCalendarCommandActivationExecutor.execute(conn, device, null, messageMetadata);
LOGGER.info("Finished activating the passive to the active activity calendar");
} catch (final ProtocolAdapterException e) {
final StringBuilder message = new StringBuilder();
for (final DataObjectAttrExecutor executor : dataObjectExecutors.getDataObjectAttrExecutorList()) {
message.append(executor.createRequestAndResultCodeInfo());
}
throw new ProtocolAdapterException(e.getMessage() + message, e);
}
return AccessResultCode.SUCCESS;
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutorTest method testUnhappy.
@Test
public void testUnhappy() throws Exception {
// SETUP
when(this.dlmsObjectConfigService.getDlmsObjectForCommunicationMethod(this.device, DlmsObjectType.GSM_DIAGNOSTIC)).thenReturn(new DlmsObject(DlmsObjectType.GSM_DIAGNOSTIC, this.classId, this.obisCode));
final GetResult result = mock(GetResult.class);
when(result.getResultCode()).thenReturn(AccessResultCode.HARDWARE_FAULT);
when(this.dlmsHelper.getAndCheck(eq(this.connectionManager), eq(this.device), eq("Get GsmDiagnostic"), any())).thenReturn(Collections.singletonList(result));
// CALL
try {
this.executor.execute(this.connectionManager, this.device, this.request, this.messageMetadata);
fail("When result contains failure, then execute should fail");
} catch (final ProtocolAdapterException e) {
assertThat(e.getMessage()).isEqualTo("Get gsm diagnostic failed for " + this.device.getDeviceId());
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class GetGsmDiagnosticCommandExecutorTest method testExecuteObjectNotFound.
@Test
public void testExecuteObjectNotFound() throws ProtocolAdapterException {
// SETUP
when(this.dlmsObjectConfigService.getDlmsObjectForCommunicationMethod(any(), any())).thenThrow(new ProtocolAdapterException("Object not found"));
// CALL
try {
this.executor.execute(this.connectionManager, this.device, this.request, this.messageMetadata);
fail("When no matching object is found, then execute should fail");
} catch (final ProtocolAdapterException e) {
assertThat(e.getMessage()).isEqualTo("Object not found");
}
}
use of org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException in project open-smart-grid-platform by OSGP.
the class DlmsObjectConfigServiceTest method testNoMatchingDlmsObjectForCommunicationMethod.
@Test
public void testNoMatchingDlmsObjectForCommunicationMethod() throws ProtocolAdapterException {
// SETUP
final DlmsDevice deviceGprs = new DlmsDevice();
deviceGprs.setDeviceIdentification("5151515151");
deviceGprs.setCommunicationMethod("GPRS");
// CALL
try {
this.service.getDlmsObjectForCommunicationMethod(deviceGprs, DlmsObjectType.GSM_DIAGNOSTIC);
fail("Expected ProtocolAdapterException");
} catch (final ProtocolAdapterException e) {
assertThat(e.getMessage()).contains("Did not find GSM_DIAGNOSTIC");
}
}
Aggregations