Search in sources :

Example 16 with ProtocolAdapterException

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()));
}
Also used : CommunicationMethod(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.CommunicationMethod) DlmsProfile(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsProfile) Arrays(java.util.Arrays) DlmsHelper(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DlmsHelper) DateTime(org.joda.time.DateTime) DataObject(org.openmuc.jdlms.datatypes.DataObject) Autowired(org.springframework.beans.factory.annotation.Autowired) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) ArrayList(java.util.ArrayList) AttributeAddress(org.openmuc.jdlms.AttributeAddress) List(java.util.List) DlmsRegister(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsRegister) ObisCode(org.openmuc.jdlms.ObisCode) CommunicationMethod(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.CommunicationMethod) Medium(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.Medium) SelectiveAccessDescription(org.openmuc.jdlms.SelectiveAccessDescription) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Protocol(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.Protocol)

Example 17 with ProtocolAdapterException

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;
}
Also used : DataObjectAttrExecutors(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutors) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SeasonProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SeasonProfileDto) WeekProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.WeekProfileDto) DayProfileDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.DayProfileDto) DataObjectAttrExecutor(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.utils.DataObjectAttrExecutor)

Example 18 with ProtocolAdapterException

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());
    }
}
Also used : GetResult(org.openmuc.jdlms.GetResult) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) DlmsObject(org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.model.DlmsObject) Test(org.junit.jupiter.api.Test)

Example 19 with ProtocolAdapterException

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");
    }
}
Also used : ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Example 20 with ProtocolAdapterException

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");
    }
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) Test(org.junit.jupiter.api.Test)

Aggregations

ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)95 DataObject (org.openmuc.jdlms.datatypes.DataObject)32 Test (org.junit.jupiter.api.Test)22 AccessResultCode (org.openmuc.jdlms.AccessResultCode)15 GetResult (org.openmuc.jdlms.GetResult)15 AttributeAddress (org.openmuc.jdlms.AttributeAddress)14 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)10 DlmsDevice (org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice)9 ConnectionException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionException)9 BitString (org.openmuc.jdlms.datatypes.BitString)7 CosemDateTimeDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.CosemDateTimeDto)7 ObisCode (org.openmuc.jdlms.ObisCode)6 SetParameter (org.openmuc.jdlms.SetParameter)5 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)5 DateTime (org.joda.time.DateTime)4 DlmsObjectType (org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.dlmsobjectconfig.DlmsObjectType)4 ConfigurationFlagsDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.ConfigurationFlagsDto)4 Date (java.util.Date)3 List (java.util.List)3