use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException 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.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class SetDeviceLifecycleStatusByChannelCommandExecutor method execute.
@Override
public SetDeviceLifecycleStatusByChannelResponseDto execute(final DlmsConnectionManager conn, final DlmsDevice gatewayDevice, final SetDeviceLifecycleStatusByChannelRequestDataDto request, final MessageMetadata messageMetadata) throws OsgpException {
final GetMBusDeviceOnChannelRequestDataDto mbusDeviceOnChannelRequest = new GetMBusDeviceOnChannelRequestDataDto(gatewayDevice.getDeviceIdentification(), request.getChannel());
final ChannelElementValuesDto channelElementValues = this.getMBusDeviceOnChannelCommandExecutor.execute(conn, gatewayDevice, mbusDeviceOnChannelRequest, messageMetadata);
if (!channelElementValues.hasChannel() || !channelElementValues.hasDeviceTypeIdentification() || !channelElementValues.hasManufacturerIdentification()) {
throw new FunctionalException(FunctionalExceptionType.NO_DEVICE_FOUND_ON_CHANNEL, ComponentType.PROTOCOL_DLMS);
}
final DlmsDevice mbusDevice = this.dlmsDeviceRepository.findByMbusIdentificationNumberAndMbusManufacturerIdentification(channelElementValues.getIdentificationNumber(), channelElementValues.getManufacturerIdentification());
if (mbusDevice == null) {
throw new FunctionalException(FunctionalExceptionType.NO_MATCHING_MBUS_DEVICE_FOUND, ComponentType.PROTOCOL_DLMS);
}
return new SetDeviceLifecycleStatusByChannelResponseDto(gatewayDevice.getDeviceIdentification(), request.getChannel(), mbusDevice.getDeviceIdentification(), request.getDeviceLifecycleStatus());
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class SetPushSetupAlarmCommandExecutor method verifyPushObject.
private void verifyPushObject(final CosemObjectDefinitionDto pushObject, final DlmsConnectionManager conn) throws ProtocolAdapterException {
final int dataIndex = pushObject.getDataIndex();
if (dataIndex != 0) {
throw new ProtocolAdapterException("PushObject contains non-zero data index: " + dataIndex + ". Using data index is not implemented.");
}
final ObisCode obisCode = new ObisCode(pushObject.getLogicalName().toByteArray());
final AttributeAddress attributeAddress = new AttributeAddress(pushObject.getClassId(), obisCode, pushObject.getAttributeIndex());
try {
this.dlmsHelper.getAttributeValue(conn, attributeAddress);
} catch (final FunctionalException e) {
throw new ProtocolAdapterException("Verification of push object failed. Object " + obisCode.asDecimalString() + " could not be retrieved using a get request.", e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class GenerateAndReplaceKeyCommandExecutor method generateSetKeysRequest.
private SetKeysRequestDto generateSetKeysRequest(final MessageMetadata messageMetadata, final String deviceIdentification) throws FunctionalException {
try {
final List<SecurityKeyType> keyTypes = Arrays.asList(E_METER_AUTHENTICATION, E_METER_ENCRYPTION);
final Map<SecurityKeyType, byte[]> generatedKeys = this.secretManagementService.generate128BitsKeysAndStoreAsNewKeys(messageMetadata, deviceIdentification, keyTypes);
final SetKeysRequestDto setKeysRequest = new SetKeysRequestDto(generatedKeys.get(E_METER_AUTHENTICATION), generatedKeys.get(E_METER_ENCRYPTION));
setKeysRequest.setGeneratedKeys(true);
return setKeysRequest;
} catch (final EncrypterException e) {
throw new FunctionalException(FunctionalExceptionType.ENCRYPTION_EXCEPTION, ComponentType.PROTOCOL_DLMS, e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.
the class RtuDeviceService method addRegistrationData.
private void addRegistrationData(final RtuDevice rtuDevice, final org.opensmartgridplatform.domain.core.entities.RtuDevice rtuDeviceEntity) throws FunctionalException {
final String networkAddress = rtuDevice.getNetworkAddress();
final InetAddress inetAddress;
try {
inetAddress = LOCAL_HOST.equals(networkAddress) ? InetAddress.getLoopbackAddress() : InetAddress.getByName(networkAddress);
} catch (final UnknownHostException e) {
throw new FunctionalException(FunctionalExceptionType.INVALID_IP_ADDRESS, ComponentType.DOMAIN_DISTRIBUTION_AUTOMATION, e);
}
rtuDeviceEntity.updateRegistrationData(inetAddress, RtuDevice.PSD_TYPE);
}
Aggregations