use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceConverterTest method testDeviceConversion.
@Test
public void testDeviceConversion() throws UnknownHostException {
final Device device = new Device("id", "alias", new Address("city", "postal", "street", 42, "nr", "munic"), new GpsCoordinates(12f, 13f), null);
device.updateRegistrationData(InetAddress.getByName("localhost"), "type");
final org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device jaxbDevice = this.deviceManagementMapper.map(device, org.opensmartgridplatform.adapter.ws.schema.core.devicemanagement.Device.class);
assertThat(jaxbDevice.getDeviceIdentification()).isEqualTo("id");
assertThat(jaxbDevice.getAlias()).isEqualTo("alias");
assertThat(jaxbDevice.getContainerAddress().getCity()).isEqualTo("city");
assertThat(jaxbDevice.getContainerAddress().getPostalCode()).isEqualTo("postal");
assertThat(jaxbDevice.getContainerAddress().getStreet()).isEqualTo("street");
assertThat(jaxbDevice.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
assertThat(jaxbDevice.getContainerAddress().getNumberAddition()).isEqualTo("nr");
assertThat(jaxbDevice.getContainerAddress().getMunicipality()).isEqualTo("munic");
assertThat(jaxbDevice.getGpsLatitude()).isEqualTo("12.0");
assertThat(jaxbDevice.getGpsLongitude()).isEqualTo("13.0");
assertThat(jaxbDevice.getNetworkAddress()).isEqualTo("localhost/127.0.0.1");
assertThat(jaxbDevice.getDeviceType()).isEqualTo("type");
final Device mappedBack = this.deviceManagementMapper.map(jaxbDevice, Device.class);
assertThat(mappedBack.getDeviceIdentification()).isEqualTo("id");
assertThat(mappedBack.getAlias()).isEqualTo("alias");
assertThat(mappedBack.getContainerAddress().getCity()).isEqualTo("city");
assertThat(mappedBack.getContainerAddress().getPostalCode()).isEqualTo("postal");
assertThat(mappedBack.getContainerAddress().getStreet()).isEqualTo("street");
assertThat(mappedBack.getContainerAddress().getNumber()).isEqualTo(new Integer(42));
assertThat(mappedBack.getContainerAddress().getNumberAddition()).isEqualTo("nr");
assertThat(mappedBack.getContainerAddress().getMunicipality()).isEqualTo("munic");
assertThat(mappedBack.getGpsCoordinates().getLatitude()).isEqualTo(12);
assertThat(mappedBack.getGpsCoordinates().getLongitude()).isEqualTo(13);
// alas networkaddress in jaxb device is just a string, need parsing to
// convert that to InetAddress
assertThat(mappedBack.getNetworkAddress()).isEqualTo(null);
assertThat(mappedBack.getDeviceType()).isEqualTo("type");
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceManagementServiceTest method generalMockForHandleDescriptionTests.
private void generalMockForHandleDescriptionTests() throws FunctionalException {
when(this.criteria.getOrganisationIdentification()).thenReturn("orgIdentification");
when(this.criteria.getDeviceIdentification()).thenReturn("deviceIdentification");
when(this.domainHelperService.findOrganisation(any())).thenReturn(new Organisation());
doNothing().when(this.pagingSettings).updatePagingSettings(any());
when(this.domainHelperService.findDevice(any())).thenReturn(new Device());
doNothing().when(this.domainHelperService).isAllowed(any(), any(), any());
when(this.eventSpecifications.isFromDevice(any())).thenReturn(this.specification);
when(this.pagingSettings.getPageNumber()).thenReturn(1);
when(this.pagingSettings.getPageSize()).thenReturn(1);
when(this.eventRepository.findAll((Specification<Event>) any(), any(Pageable.class))).thenReturn(null);
when(this.eventSpecifications.hasEventTypes(any())).thenReturn(null);
when(this.specification.and(null)).thenReturn(this.specification);
when(this.eventSpecifications.withDescription(any())).thenReturn(this.descriptionSpecification);
when(this.eventSpecifications.startsWithDescription(any())).thenReturn(this.descriptionStartsWithSpecification);
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method enqueueSetRebootRequest.
public String enqueueSetRebootRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final int messagePriority) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
this.domainHelperService.isAllowed(organisation, device, DeviceFunction.SET_REBOOT);
this.domainHelperService.isInMaintenance(device);
LOGGER.debug("enqueueSetRebootRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.SET_REBOOT.name()).withMessagePriority(messagePriority).build();
final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(deviceMessageMetadata).build();
this.commonRequestMessageSender.send(message);
return correlationUid;
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementService method enqueueGetConfigurationRequest.
public String enqueueGetConfigurationRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final int messagePriority) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
this.domainHelperService.isAllowed(organisation, device, DeviceFunction.GET_CONFIGURATION);
this.domainHelperService.isInMaintenance(device);
LOGGER.debug("enqueueGetConfigurationRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
final MessageMetadata messageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.GET_CONFIGURATION.name()).withMessagePriority(messagePriority).build();
final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).build();
this.commonRequestMessageSender.send(message);
return correlationUid;
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceInstallationService method addLightMeasurementDevice.
@Transactional(value = "writableTransactionManager")
public void addLightMeasurementDevice(@Identification final String organisationIdentification, @Valid final LightMeasurementDevice newLightMeasurementDevice, @Identification final String ownerOrganisationIdentification) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.GET_ORGANISATIONS);
this.domainHelperService.isOrganisationEnabled(organisation);
// If the device already exists, throw an exception.
final Device existingDevice = this.writableDeviceRepository.findByDeviceIdentification(newLightMeasurementDevice.getDeviceIdentification());
// field
if (existingDevice != null && StringUtils.isNotBlank(existingDevice.getDeviceType())) {
throw new FunctionalException(FunctionalExceptionType.EXISTING_DEVICE, ComponentType.WS_CORE, new ExistingEntityException(Device.class, newLightMeasurementDevice.getDeviceIdentification()));
}
LightMeasurementDevice lmd;
if (existingDevice != null) {
// Update existing light measurement device
lmd = this.writableLightMeasurementDeviceRepository.findByDeviceIdentification(newLightMeasurementDevice.getDeviceIdentification());
lmd.updateMetaData(newLightMeasurementDevice.getAlias(), newLightMeasurementDevice.getContainerAddress(), newLightMeasurementDevice.getGpsCoordinates());
lmd.getAuthorizations().clear();
} else {
// Create a new LMD instance.
lmd = new LightMeasurementDevice(newLightMeasurementDevice.getDeviceIdentification(), newLightMeasurementDevice.getAlias(), newLightMeasurementDevice.getContainerAddress(), newLightMeasurementDevice.getGpsCoordinates(), null);
}
lmd.setDeviceModel(newLightMeasurementDevice.getDeviceModel());
lmd.setDescription(newLightMeasurementDevice.getDescription());
lmd.setCode(newLightMeasurementDevice.getCode());
lmd.setColor(newLightMeasurementDevice.getColor());
lmd.setDigitalInput(newLightMeasurementDevice.getDigitalInput());
final Organisation ownerOrganisation = this.domainHelperService.findOrganisation(ownerOrganisationIdentification);
lmd = this.writableLightMeasurementDeviceRepository.save(lmd);
final DeviceAuthorization authorization = lmd.addAuthorization(ownerOrganisation, DeviceFunctionGroup.OWNER);
this.writableAuthorizationRepository.save(authorization);
LOGGER.info("Created new light measurement device {} with owner {}", newLightMeasurementDevice.getDeviceIdentification(), ownerOrganisationIdentification);
}
Aggregations