use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method setMaintenanceStatus.
@Transactional(value = "writableTransactionManager")
public void setMaintenanceStatus(@Identification final String organisationIdentification, final String deviceIdentification, final boolean status) throws FunctionalException {
final Device existingDevice = this.writableDeviceRepository.findByDeviceIdentification(deviceIdentification);
if (existingDevice == null) {
// device does not exist
LOGGER.info("Device does not exist, cannot set maintenance status.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE, new UnknownEntityException(Device.class, deviceIdentification));
} else {
// Check to see if the organisation is CONFIGURATION or OWNER
// authorized
boolean isAuthorized = false;
for (final DeviceAuthorization authorizations : existingDevice.getAuthorizations()) {
if (organisationIdentification.equals(authorizations.getOrganisation().getOrganisationIdentification()) && (DeviceFunctionGroup.OWNER.equals(authorizations.getFunctionGroup()) || DeviceFunctionGroup.CONFIGURATION.equals(authorizations.getFunctionGroup()))) {
isAuthorized = true;
existingDevice.updateInMaintenance(status);
this.writableDeviceRepository.save(existingDevice);
break;
}
}
if (!isAuthorized) {
// unauthorized, throwing exception.
throw new FunctionalException(FunctionalExceptionType.UNAUTHORIZED, ComponentType.WS_CORE, new NotAuthorizedException(organisationIdentification));
}
}
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method updateDevice.
@Transactional(value = "writableTransactionManager")
public void updateDevice(@Identification final String organisationIdentification, final String deviceToUpdateIdentification, @Valid final Ssld updateDevice) throws FunctionalException {
final Device existingDevice = this.writableDeviceRepository.findByDeviceIdentification(deviceToUpdateIdentification);
if (existingDevice == null) {
// device does not exist
LOGGER.info("Device does not exist, nothing to update.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE, new UnknownEntityException(Device.class, deviceToUpdateIdentification));
}
final List<DeviceAuthorization> owners = this.writableAuthorizationRepository.findByDeviceAndFunctionGroup(existingDevice, DeviceFunctionGroup.OWNER);
// Check organisation against owner of device
boolean isOwner = false;
for (final DeviceAuthorization owner : owners) {
if (owner.getOrganisation().getOrganisationIdentification().equalsIgnoreCase(organisationIdentification)) {
isOwner = true;
}
}
if (!isOwner) {
LOGGER.info("Device has no owner yet, or organisation is not the owner.");
throw new FunctionalException(FunctionalExceptionType.UNAUTHORIZED, ComponentType.WS_CORE, new NotAuthorizedException(organisationIdentification));
}
// Update the device
existingDevice.updateMetaData(updateDevice.getAlias(), updateDevice.getContainerAddress(), updateDevice.getGpsCoordinates());
existingDevice.setActivated(updateDevice.isActivated());
if (updateDevice.getDeviceLifecycleStatus() != null) {
existingDevice.setDeviceLifecycleStatus(updateDevice.getDeviceLifecycleStatus());
}
if (updateDevice.getTechnicalInstallationDate() != null) {
existingDevice.setTechnicalInstallationDate(updateDevice.getTechnicalInstallationDate());
}
final Ssld ssld = this.writableSsldRepository.findById(existingDevice.getId()).orElseThrow(() -> new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE));
ssld.updateOutputSettings(updateDevice.receiveOutputSettings());
ssld.setEans(updateDevice.getEans());
for (final Ean ean : updateDevice.getEans()) {
ean.setDevice(ssld);
}
this.writableSsldRepository.save(ssld);
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method enqueueUpdateDeviceSslCertificationRequest.
public String enqueueUpdateDeviceSslCertificationRequest(final String organisationIdentification, final String deviceIdentification, final Certification certification, 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.UPDATE_DEVICE_SSL_CERTIFICATION);
this.domainHelperService.isInMaintenance(device);
LOGGER.debug("enqueueUpdateDeviceSslCertificationRequest 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.UPDATE_DEVICE_SSL_CERTIFICATION.name()).withMessagePriority(messagePriority).build();
final CommonRequestMessage message = new CommonRequestMessage.Builder().messageMetadata(messageMetadata).request(certification).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 FirmwareManagementService method getDeviceFirmwareFiles.
/**
* Returns a list of all {@link DeviceFirmwareFile}s in the Platform
*/
public List<DeviceFirmwareFile> getDeviceFirmwareFiles(final String organisationIdentification, final String deviceIdentification) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.GET_FIRMWARE);
final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
return this.deviceFirmwareFileRepository.findByDeviceOrderByInstallationDateAsc(device);
}
use of org.opensmartgridplatform.domain.core.entities.Device in project open-smart-grid-platform by OSGP.
the class DeviceConverterTest method testSmartMeterConversion.
@Test
public void testSmartMeterConversion() throws UnknownHostException {
final Device device = new SmartMeter("id", "alias", new Address("city", "postal", "street", 42, "nr", "munic"), new GpsCoordinates(12f, 13f));
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 SmartMeter mappedBack = this.deviceManagementMapper.map(jaxbDevice, SmartMeter.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");
}
Aggregations