Search in sources :

Example 1 with SendDestinationAndMethod

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod in project open-smart-grid-platform by OSGP.

the class PushSetupSmsConverter method convertTo.

@Override
public org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupSms convertTo(final PushSetupSms source, final Type<org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupSms> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    if (!source.hasSendDestinationAndMethod()) {
        throw new IllegalArgumentException("Unable to map PushSetup Sms without SendDestinationAndMethod.");
    }
    final SendDestinationAndMethod sendDestinationAndMethod = source.getSendDestinationAndMethod();
    final String destination = sendDestinationAndMethod.getDestination();
    if (!destination.matches("\\S++:\\d++")) {
        throw new IllegalArgumentException("Unable to parse destination as \"<host>:<port>\": " + destination);
    }
    final String[] hostAndPort = destination.split(":");
    final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupSms pushSetup = new org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupSms();
    pushSetup.setHost(hostAndPort[0]);
    pushSetup.setPort(new BigInteger(hostAndPort[1]));
    return pushSetup;
}
Also used : SendDestinationAndMethod(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod) PushSetupSms(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupSms) BigInteger(java.math.BigInteger)

Example 2 with SendDestinationAndMethod

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod in project open-smart-grid-platform by OSGP.

the class PushSetupAlarmConverter method convertTo.

@Override
public org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm convertTo(final PushSetupAlarm source, final Type<org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm pushSetupAlarm = new org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm();
    if (source.hasSendDestinationAndMethod()) {
        final SendDestinationAndMethod sendDestinationAndMethod = source.getSendDestinationAndMethod();
        final String destination = sendDestinationAndMethod.getDestination();
        if (!destination.matches("\\S++:\\d++")) {
            throw new IllegalArgumentException("Unable to parse destination as \"<host>:<port>\": " + destination);
        }
        final String[] hostAndPort = destination.split(":");
        pushSetupAlarm.setHost(hostAndPort[0]);
        pushSetupAlarm.setPort(new BigInteger(hostAndPort[1]));
    }
    if (source.hasPushObjectList()) {
        final List<PushObject> convertedPushObjectList = this.mapperFacade.mapAsList(source.getPushObjectList(), PushObject.class);
        pushSetupAlarm.getPushObjectList().addAll(convertedPushObjectList);
    }
    return pushSetupAlarm;
}
Also used : SendDestinationAndMethod(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod) PushSetupAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm) PushObject(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushObject) BigInteger(java.math.BigInteger)

Example 3 with SendDestinationAndMethod

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod in project open-smart-grid-platform by OSGP.

the class PushSetupAlarmConverter method convertFrom.

@Override
public PushSetupAlarm convertFrom(final org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushSetupAlarm source, final Type<PushSetupAlarm> destinationType, final MappingContext context) {
    if (source == null) {
        return null;
    }
    final PushSetupAlarm.Builder builder = new PushSetupAlarm.Builder();
    if (source.getHost() != null && source.getPort() != null) {
        final String destination = source.getHost() + ":" + source.getPort();
        final SendDestinationAndMethod sendDestinationAndMethod = new SendDestinationAndMethod(TransportServiceType.TCP, destination, MessageType.A_XDR_ENCODED_X_DLMS_APDU);
        builder.withSendDestinationAndMethod(sendDestinationAndMethod);
    }
    final List<PushObject> sourcePushObjects = source.getPushObjectList();
    if (sourcePushObjects != null) {
        final List<CosemObjectDefinition> convertedPushObjectList = this.mapperFacade.mapAsList(source.getPushObjectList(), CosemObjectDefinition.class);
        builder.withPushObjectList(convertedPushObjectList);
    }
    return builder.build();
}
Also used : SendDestinationAndMethod(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod) PushSetupAlarm(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm) PushObject(org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushObject) CosemObjectDefinition(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition)

Example 4 with SendDestinationAndMethod

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod in project open-smart-grid-platform by OSGP.

the class PushSetupSmsMappingTest method checkSendDestinationAndMethodMapping.

// method to test SendDestinationAndMethod mapping
private void checkSendDestinationAndMethodMapping(final PushSetupSms pushSetupSms, final PushSetupSmsDto pushSetupSmsDto) {
    final SendDestinationAndMethod sendDestinationAndMethod = pushSetupSms.getSendDestinationAndMethod();
    final SendDestinationAndMethodDto sendDestinationAndMethodDto = pushSetupSmsDto.getSendDestinationAndMethod();
    // make sure neither is null
    assertThat(sendDestinationAndMethod).isNotNull();
    assertThat(sendDestinationAndMethodDto).isNotNull();
    // make sure all instance variables are equal
    assertThat(sendDestinationAndMethodDto.getTransportService().name()).isEqualTo(sendDestinationAndMethod.getTransportService().name());
    assertThat(sendDestinationAndMethodDto.getMessage().name()).isEqualTo(sendDestinationAndMethod.getMessage().name());
    assertThat(sendDestinationAndMethodDto.getDestination()).isEqualTo(sendDestinationAndMethod.getDestination());
}
Also used : SendDestinationAndMethod(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod) SendDestinationAndMethodDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SendDestinationAndMethodDto)

Example 5 with SendDestinationAndMethod

use of org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod in project open-smart-grid-platform by OSGP.

the class PushSetupAlarmMappingTest method checkSendDestinationAndMethodMapping.

// method to test SendDestinationAndMethod mapping
private void checkSendDestinationAndMethodMapping(final PushSetupAlarm pushSetupAlarm, final PushSetupAlarmDto pushSetupAlarmDto) {
    final SendDestinationAndMethod sendDestinationAndMethod = pushSetupAlarm.getSendDestinationAndMethod();
    final SendDestinationAndMethodDto sendDestinationAndMethodDto = pushSetupAlarmDto.getSendDestinationAndMethod();
    // make sure neither is null
    assertThat(sendDestinationAndMethod).isNotNull();
    assertThat(sendDestinationAndMethodDto).isNotNull();
    // make sure all instance variables are equal
    assertThat(sendDestinationAndMethodDto.getTransportService().name()).isEqualTo(sendDestinationAndMethod.getTransportService().name());
    assertThat(sendDestinationAndMethodDto.getMessage().name()).isEqualTo(sendDestinationAndMethod.getMessage().name());
    assertThat(sendDestinationAndMethodDto.getDestination()).isEqualTo(sendDestinationAndMethod.getDestination());
}
Also used : SendDestinationAndMethod(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod) SendDestinationAndMethodDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SendDestinationAndMethodDto)

Aggregations

SendDestinationAndMethod (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SendDestinationAndMethod)6 BigInteger (java.math.BigInteger)2 PushObject (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.PushObject)2 PushSetupAlarm (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupAlarm)2 PushSetupSms (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.PushSetupSms)2 SendDestinationAndMethodDto (org.opensmartgridplatform.dto.valueobjects.smartmetering.SendDestinationAndMethodDto)2 CosemObjectDefinition (org.opensmartgridplatform.domain.core.valueobjects.smartmetering.CosemObjectDefinition)1