Search in sources :

Example 1 with LightMeasurementDevice

use of org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class LightMeasurementDeviceSteps method aLightMeasurementDevice.

@Given("^a light measurement device$")
@Transactional("txMgrCore")
public LightMeasurementDevice aLightMeasurementDevice(final Map<String, String> settings) {
    final String deviceIdentification = getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION);
    final LightMeasurementDevice lmd = new LightMeasurementDevice(deviceIdentification);
    final List<DeviceModel> deviceModels = this.deviceModelRepository.findByModelCode(getString(settings, PlatformKeys.KEY_DEVICE_MODEL, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE));
    final DeviceModel deviceModel = deviceModels.get(0);
    lmd.setDeviceModel(deviceModel);
    if (settings.containsKey(PlatformKeys.KEY_DEVICE_TYPE)) {
        InetAddress inetAddress;
        try {
            inetAddress = InetAddress.getByName(getString(settings, PlatformKeys.IP_ADDRESS, this.configuration.getDeviceNetworkAddress()));
        } catch (final UnknownHostException e) {
            inetAddress = InetAddress.getLoopbackAddress();
        }
        lmd.updateRegistrationData(inetAddress, getString(settings, PlatformKeys.KEY_DEVICE_TYPE));
    }
    lmd.updateMetaData(getString(settings, PlatformKeys.ALIAS, PlatformDefaults.DEFAULT_ALIAS), new Address(getString(settings, PlatformKeys.KEY_CITY, PlatformDefaults.DEFAULT_CONTAINER_CITY), getString(settings, PlatformKeys.KEY_POSTCODE, PlatformDefaults.DEFAULT_CONTAINER_POSTALCODE), getString(settings, PlatformKeys.KEY_STREET, PlatformDefaults.DEFAULT_CONTAINER_STREET), getInteger(settings, PlatformKeys.KEY_NUMBER, PlatformDefaults.DEFAULT_CONTAINER_NUMBER), getString(settings, PlatformKeys.KEY_NUMBER_ADDITION, PlatformDefaults.DEFAULT_CONTAINER_NUMBER_ADDITION), getString(settings, PlatformKeys.KEY_MUNICIPALITY, PlatformDefaults.DEFAULT_CONTAINER_MUNICIPALITY)), new GpsCoordinates(settings.containsKey(PlatformKeys.KEY_LATITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LATITUDE)) ? getFloat(settings, PlatformKeys.KEY_LATITUDE, PlatformDefaults.DEFAULT_LATITUDE) : null, settings.containsKey(PlatformKeys.KEY_LONGITUDE) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_LONGITUDE)) ? getFloat(settings, PlatformKeys.KEY_LONGITUDE, PlatformDefaults.DEFAULT_LONGITUDE) : null));
    lmd.setActivated(getBoolean(settings, PlatformKeys.KEY_ACTIVATED, PlatformDefaults.DEFAULT_ACTIVATED));
    lmd.setDescription(getString(settings, PlatformKeys.KEY_LMD_DESCRIPTION, PlatformDefaults.DEFAULT_LMD_DESCRIPTION));
    lmd.setCode(getString(settings, PlatformKeys.KEY_LMD_CODE, PlatformDefaults.DEFAULT_LMD_CODE));
    lmd.setColor(getString(settings, PlatformKeys.KEY_LMD_COLOR, PlatformDefaults.DEFAULT_LMD_COLOR));
    lmd.setDigitalInput(getShort(settings, PlatformKeys.KEY_LMD_DIGITAL_INPUT, PlatformDefaults.DEFAULT_LMD_DIGITAL_INPUT));
    this.setDefaultDeviceAuthorizationForDevice(lmd);
    return this.lightMeasurementDeviceRepository.findByDeviceIdentification(deviceIdentification);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) UnknownHostException(java.net.UnknownHostException) InetAddress(java.net.InetAddress) Address(org.opensmartgridplatform.domain.core.valueobjects.Address) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) InetAddress(java.net.InetAddress) GpsCoordinates(org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LightMeasurementDevice

use of org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class LightMeasurementDeviceSteps method createLightMeasurementDevices.

/**
 * Create the 4 light measurement devices and {@link DeviceAuthorization}s for the default
 * organization.
 */
public void createLightMeasurementDevices() {
    final LightMeasurementDevice lmd01 = this.createLightMeasurementDevice("LMD-01", "N-01", "#c9eec9", (short) 1);
    // Set the last communication time to 2017-08-01 at 13:00 UTC
    final Instant lastCommunicationTimeLmd01 = ZonedDateTime.of(2017, 8, 1, 13, 0, 0, 0, ZoneOffset.UTC).toInstant();
    lmd01.setLastCommunicationTime(lastCommunicationTimeLmd01);
    this.lightMeasurementDeviceRepository.save(lmd01);
    this.createLightMeasurementDevice("LMD-02", "E-01", "#eec9c9", (short) 2);
    this.createLightMeasurementDevice("LMD-03", "S-01", "#c9c9ee", (short) 3);
    this.createLightMeasurementDevice("LMD-04", "W-01", "#eeeec9", (short) 4);
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Instant(java.time.Instant)

Example 3 with LightMeasurementDevice

use of org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class PublicLightingAdHocManagementEndpoint method findAllDevices.

@PayloadRoot(localPart = "FindAllDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public FindAllDevicesResponse findAllDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindAllDevicesRequest request) throws OsgpException {
    LOGGER.info("Finding All Devices Request received from organisation: {}.", organisationIdentification);
    final FindAllDevicesResponse response = new FindAllDevicesResponse();
    try {
        final PageSpecifier pageSpecifier = new PageSpecifier(request.getPageSize(), request.getPage());
        final Page<Device> page = this.adHocManagementService.findAllDevices(organisationIdentification, pageSpecifier);
        if (page != null && !page.isEmpty()) {
            final List<Ssld> sslds = listOfType(page, Ssld.class);
            final List<LightMeasurementDevice> lmds = listOfType(page, LightMeasurementDevice.class);
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setPageSize(page.getSize());
            devicePage.getPage().setTotalPages(page.getTotalPages());
            devicePage.getPage().setCurrentPage(page.getNumber());
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(sslds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld.class));
            devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(lmds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice.class));
            response.setDevicePage(devicePage);
        } else {
            final DevicePage devicePage = new DevicePage();
            devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
            devicePage.getPage().setCurrentPage(0);
            devicePage.getPage().setPageSize(request.getPageSize() == null ? 0 : request.getPageSize());
            devicePage.getPage().setTotalPages(0);
            response.setDevicePage(devicePage);
        }
    } catch (final ConstraintViolationException e) {
        LOGGER.error(EXCEPTION_OCCURRED, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : PageSpecifier(org.opensmartgridplatform.shared.application.config.PageSpecifier) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) ConstraintViolationException(javax.validation.ConstraintViolationException) DevicePage(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.DevicePage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FindAllDevicesResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.FindAllDevicesResponse) Ssld(org.opensmartgridplatform.domain.core.entities.Ssld) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 4 with LightMeasurementDevice

use of org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class DeviceMappingTest method coreLmd.

private LightMeasurementDevice coreLmd() {
    final LightMeasurementDevice lmd = new LightMeasurementDevice(DEVICE_IDENTIFICATION, null, this.address(), this.gpsCoordinates(), null);
    lmd.updateRegistrationData(null, DEVICE_TYPE);
    lmd.setDescription(LMD_DESCRIPTION);
    lmd.setCode(LMD_CODE);
    lmd.setColor(LMD_COLOR);
    lmd.setDigitalInput(LMD_DIGITAL_INPUT);
    return lmd;
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)

Example 5 with LightMeasurementDevice

use of org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice in project open-smart-grid-platform by OSGP.

the class DeviceMappingTest method testConvertLmdToCore.

@Test
void testConvertLmdToCore() {
    final LightMeasurementDevice lmd = mapper.map(this.adhocManagementLmd(), LightMeasurementDevice.class);
    assertThat(lmd).usingRecursiveComparison().ignoringFields("creationTime", "modificationTime").isEqualTo(this.coreLmd());
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Test(org.junit.jupiter.api.Test)

Aggregations

LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)21 Device (org.opensmartgridplatform.domain.core.entities.Device)6 Instant (java.time.Instant)5 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)5 Transactional (org.springframework.transaction.annotation.Transactional)4 InetAddress (java.net.InetAddress)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 ConstraintViolationException (javax.validation.ConstraintViolationException)3 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)3 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)3 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)3 Address (org.opensmartgridplatform.domain.core.valueobjects.Address)3 GpsCoordinates (org.opensmartgridplatform.domain.core.valueobjects.GpsCoordinates)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)3 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)3 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)3 HashSet (java.util.HashSet)2 DateTime (org.joda.time.DateTime)2