Search in sources :

Example 6 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DetailSoapFaultMappingExceptionResolver method customizeFault.

@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
    final SoapFaultDetail detail = fault.addFaultDetail();
    final Result result = detail.getResult();
    FunctionalException fex = null;
    TechnicalException tex = null;
    ConnectionFailureException cex = null;
    if (ex instanceof FunctionalException) {
        fex = (FunctionalException) ex;
    } else if (ex instanceof TechnicalException) {
        tex = (TechnicalException) ex;
    } else if (ex instanceof ConnectionFailureException) {
        cex = (ConnectionFailureException) ex;
    }
    if (fex != null) {
        try {
            this.marshalFunctionalException(fex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Functional Exception", e);
        }
    }
    if (tex != null) {
        try {
            this.marshalTechnicalException(tex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Technical Exception", e);
        }
    }
    if (cex != null) {
        try {
            this.marshalConnectionFailureException(cex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Connection Failure Exception", e);
        }
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) SoapFaultDetail(org.springframework.ws.soap.SoapFaultDetail) ConnectionFailureException(org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException) JAXBException(javax.xml.bind.JAXBException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Result(javax.xml.transform.Result)

Example 7 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DeviceKeyProcessingService method startProcessing.

public void startProcessing(final String deviceIdentification) throws DeviceKeyProcessAlreadyRunningException, FunctionalException {
    final DlmsDevice dlmsDevice = this.dlmsDeviceRepository.findByDeviceIdentification(deviceIdentification);
    if (dlmsDevice == null) {
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, ComponentType.PROTOCOL_DLMS, new ProtocolAdapterException("Unable to start key changing process with unknown device: " + deviceIdentification));
    }
    final Instant oldestStartTimeNotConsiderTimedOut = Instant.now().minus(this.deviceKeyProcessingTimeout);
    final int updatedRecords = this.dlmsDeviceRepository.setProcessingStartTime(dlmsDevice.getDeviceIdentification(), oldestStartTimeNotConsiderTimedOut);
    if (updatedRecords == 0) {
        throw new DeviceKeyProcessAlreadyRunningException();
    }
}
Also used : DeviceKeyProcessAlreadyRunningException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException) Instant(java.time.Instant) DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)

Example 8 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class InstallationService method addMeter.

public void addMeter(final MessageMetadata messageMetadata, final SmartMeteringDeviceDto smartMeteringDevice) throws FunctionalException {
    if (smartMeteringDevice.getDeviceIdentification() == null) {
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, ComponentType.PROTOCOL_DLMS, new IllegalArgumentException("Provided device does not contain device identification"));
    }
    this.storeAndActivateKeys(messageMetadata, smartMeteringDevice);
    final DlmsDevice dlmsDevice = this.installationMapper.map(smartMeteringDevice, DlmsDevice.class);
    this.dlmsDeviceRepository.save(dlmsDevice);
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 9 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class InstallationService method storeAndActivateKeys.

private void storeAndActivateKeys(final MessageMetadata messageMetadata, final SmartMeteringDeviceDto deviceDto) throws FunctionalException {
    final Map<SecurityKeyType, byte[]> keysByType = new EnumMap<>(SecurityKeyType.class);
    final List<SecurityKeyType> keyTypesToStore = this.determineKeyTypesToStore(deviceDto);
    for (final SecurityKeyType keyType : keyTypesToStore) {
        final byte[] key = this.getKeyFromDeviceDto(deviceDto, keyType);
        if (ArrayUtils.isNotEmpty(key)) {
            keysByType.put(keyType, this.decrypterForGxfSmartMetering.decrypt(key));
        } else {
            final Exception rootCause = new NoSuchElementException(keyType.name());
            throw new FunctionalException(FunctionalExceptionType.KEY_NOT_PRESENT, ComponentType.PROTOCOL_DLMS, rootCause);
        }
    }
    this.secretManagementService.storeNewKeys(messageMetadata, deviceDto.getDeviceIdentification(), keysByType);
    this.secretManagementService.activateNewKeys(messageMetadata, deviceDto.getDeviceIdentification(), keyTypesToStore);
}
Also used : FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SecurityKeyType(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.SecurityKeyType) EnumMap(java.util.EnumMap) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) NoSuchElementException(java.util.NoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DomainHelperService method getDeviceIpAddressFromSessionProvider.

public String getDeviceIpAddressFromSessionProvider(final DlmsDevice dlmsDevice) throws OsgpException {
    final SessionProvider sessionProvider = this.sessionProviderService.getSessionProvider(dlmsDevice.getCommunicationProvider());
    String deviceIpAddress;
    try {
        deviceIpAddress = sessionProvider.getIpAddress(dlmsDevice.getIccId());
        if (deviceIpAddress != null) {
            return deviceIpAddress;
        }
        // If the result is null then the meter is not in session (not
        // awake).
        // So wake up the meter and start polling for the session
        this.jasperWirelessSmsClient.sendWakeUpSMS(dlmsDevice.getIccId());
        deviceIpAddress = this.pollForSession(sessionProvider, dlmsDevice);
    } catch (final SessionProviderException e) {
        LOGGER.error("IccId is probably not supported in this session provider", e);
        throw new FunctionalException(FunctionalExceptionType.INVALID_ICCID, ComponentType.PROTOCOL_DLMS, e);
    }
    if ((deviceIpAddress == null) || "".equals(deviceIpAddress)) {
        throw new ProtocolAdapterException("Session provider: " + dlmsDevice.getCommunicationProvider() + " did not return an IP address for device: " + dlmsDevice.getDeviceIdentification() + " and iccId: " + dlmsDevice.getIccId());
    }
    return deviceIpAddress;
}
Also used : FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException) SessionProvider(org.opensmartgridplatform.adapter.protocol.jasper.sessionproviders.SessionProvider) SessionProviderException(org.opensmartgridplatform.adapter.protocol.jasper.sessionproviders.exceptions.SessionProviderException)

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