use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method setDeviceAlias.
@Transactional(value = "writableTransactionManager")
public void setDeviceAlias(@Identification final String organisationIdentification, final String deviceIdentification, final String deviceAlias, final List<DeviceOutputSetting> newDeviceOutputSettings) throws FunctionalException {
final Ssld existingSsld = this.writableSsldRepository.findByDeviceIdentification(deviceIdentification);
if (existingSsld == null) {
// device does not exist
LOGGER.info("Device does not exist, cannot set Alias.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.WS_CORE, new UnknownEntityException(Device.class, deviceIdentification));
}
// Check to see if the organization is authorized for SET_DEVICE_ALIASES
final Organisation organisation = this.organisationRepository.findByOrganisationIdentification(organisationIdentification);
this.domainHelperService.isAllowed(organisation, existingSsld, DeviceFunction.SET_DEVICE_ALIASES);
if (deviceAlias != null) {
existingSsld.setAlias(deviceAlias);
this.writableDeviceRepository.save(existingSsld);
}
if (newDeviceOutputSettings != null && !newDeviceOutputSettings.isEmpty()) {
this.updateRelayAliases(newDeviceOutputSettings, existingSsld);
}
}
use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException 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.exceptions.UnknownEntityException 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.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class DeviceInstallationService method updateLightMeasurementDevice.
@Transactional(value = "writableTransactionManager")
public void updateLightMeasurementDevice(@Identification final String organisationIdentification, @Valid final LightMeasurementDevice updateLightMeasurementDevice) throws FunctionalException {
final LightMeasurementDevice existingLmd = this.writableLightMeasurementDeviceRepository.findByDeviceIdentification(updateLightMeasurementDevice.getDeviceIdentification());
if (existingLmd == 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, updateLightMeasurementDevice.getDeviceIdentification()));
}
final List<DeviceAuthorization> owners = this.writableAuthorizationRepository.findByDeviceAndFunctionGroup(existingLmd, 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 LMD
existingLmd.updateMetaData(updateLightMeasurementDevice.getAlias(), updateLightMeasurementDevice.getContainerAddress(), updateLightMeasurementDevice.getGpsCoordinates());
existingLmd.setDeviceModel(updateLightMeasurementDevice.getDeviceModel());
existingLmd.setDescription(updateLightMeasurementDevice.getDescription());
existingLmd.setCode(updateLightMeasurementDevice.getCode());
existingLmd.setColor(updateLightMeasurementDevice.getColor());
existingLmd.setDigitalInput(updateLightMeasurementDevice.getDigitalInput());
this.writableLightMeasurementDeviceRepository.save(existingLmd);
}
use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method updateKey.
// === UPDATE KEY ===
public void updateKey(final String organisationIdentification, @Identification final String deviceIdentification, final String correlationUid, final String messageType, @PublicKey final String publicKey) throws FunctionalException {
LOGGER.info("MessageType: {}. Updating key for device [{}] on behalf of organisation [{}]", messageType, deviceIdentification, organisationIdentification);
try {
this.organisationDomainService.searchOrganisation(organisationIdentification);
} catch (final UnknownEntityException e) {
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_ORGANISATION, ComponentType.DOMAIN_ADMIN, e);
}
this.osgpCoreRequestMessageSender.send(new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, publicKey), messageType, null);
}
Aggregations