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;
}
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;
}
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();
}
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());
}
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());
}
Aggregations