Search in sources :

Example 76 with FunctionalException

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);
}
Also used : LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) NotAuthorizedException(org.opensmartgridplatform.domain.core.exceptions.NotAuthorizedException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with FunctionalException

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());
}
Also used : ChannelElementValuesDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.ChannelElementValuesDto) SetDeviceLifecycleStatusByChannelResponseDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetDeviceLifecycleStatusByChannelResponseDto) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) GetMBusDeviceOnChannelRequestDataDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.GetMBusDeviceOnChannelRequestDataDto)

Example 78 with FunctionalException

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);
    }
}
Also used : AttributeAddress(org.openmuc.jdlms.AttributeAddress) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) ObisCode(org.openmuc.jdlms.ObisCode) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 79 with FunctionalException

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);
    }
}
Also used : SetKeysRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.SetKeysRequestDto) EncrypterException(org.opensmartgridplatform.shared.exceptionhandling.EncrypterException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType)

Example 80 with FunctionalException

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);
}
Also used : UnknownHostException(java.net.UnknownHostException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) InetAddress(java.net.InetAddress)

Aggregations

FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)155 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)63 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)54 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)54 ConstraintViolationException (javax.validation.ConstraintViolationException)51 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)47 Device (org.opensmartgridplatform.domain.core.entities.Device)32 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)31 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)22 Transactional (org.springframework.transaction.annotation.Transactional)19 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)15 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)12 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)11 ArrayList (java.util.ArrayList)10 Test (org.junit.jupiter.api.Test)10 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)10 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)9 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)9