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);
}
}
}
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();
}
}
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);
}
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);
}
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;
}
Aggregations