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