Search in sources :

Example 71 with Device

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");
}
Also used : Address(org.opensmartgridplatform.domain.core.valueobjects.Address) InetAddress(java.net.InetAddress) Device(org.opensmartgridplatform.domain.core.entities.Device) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Test(org.junit.jupiter.api.Test)

Example 72 with Device

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);
}
Also used : Pageable(org.springframework.data.domain.Pageable) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) Event(org.opensmartgridplatform.domain.core.entities.Event)

Example 73 with Device

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;
}
Also used : CommonRequestMessage(org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device)

Example 74 with Device

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;
}
Also used : CommonRequestMessage(org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device)

Example 75 with Device

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);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ExistingEntityException(org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Device (org.opensmartgridplatform.domain.core.entities.Device)179 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)49 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)36 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)35 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)32 Test (org.junit.jupiter.api.Test)27 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)27 Transactional (org.springframework.transaction.annotation.Transactional)24 Then (io.cucumber.java.en.Then)21 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)18 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)17 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)15 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)12 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)11 Date (java.util.Date)10 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)10 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)9