use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method handleUpdateKeyResponse.
public void handleUpdateKeyResponse(final String deviceIdentification, final String organisationIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType deviceResult, final OsgpException exception) {
LOGGER.info("MessageType: {}. Handle update key response for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = exception;
try {
if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
if (device == null) {
// Device not found, create new device
LOGGER.debug("Device [{}] does not exist, creating new device", deviceIdentification);
device = new Ssld(deviceIdentification);
}
device.setPublicKeyPresent(true);
this.ssldRepository.save(device);
LOGGER.info("publicKey has been set for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
} catch (final Exception e) {
LOGGER.error("Unexpected Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while updating key", e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(osgpException).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method handleRevokeKeyResponse.
public void handleRevokeKeyResponse(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType deviceResult, final OsgpException exception) {
LOGGER.info("MessageType: {}. Handle revoke key for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = exception;
try {
if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
if (device == null) {
throw new PlatformException(String.format("Device not found: %s", deviceIdentification));
}
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
ssld.setPublicKeyPresent(false);
this.ssldRepository.save(ssld);
LOGGER.info("publicKey has been revoked for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
} catch (final Exception e) {
LOGGER.error("Unexpected Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while revoking key", e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(osgpException).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException in project open-smart-grid-platform by OSGP.
the class FirmwareManagementServiceTest method testHandleGetFirmwareVersionErrorNotNull.
@Test
void testHandleGetFirmwareVersionErrorNotNull() {
final List<FirmwareVersionDto> versionsOnDevice = new ArrayList<>();
this.firmwareManagementService.handleGetFirmwareVersionResponse(versionsOnDevice, CORRELATION_IDS, "messageType", 1, ResponseMessageResultType.OK, DEFAULT_EXCEPTION);
verify(this.webServiceResponseMessageSender).send(this.responseMessageCaptor.capture());
verify(this.ssldPendingFirmwareUpdateRepository, never()).delete(any());
final ResponseMessage responseMessage = this.responseMessageCaptor.getValue();
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(CORRELATION_IDS).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(new TechnicalException("Exception occurred while getting device firmware version")).withMessagePriority(1).withMessageType(MessageType.GET_FIRMWARE_VERSION.name()).build();
assertThat(responseMessage).usingRecursiveComparison().ignoringFields("dataObject").isEqualTo(expectedResponseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.TechnicalException 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.TechnicalException in project open-smart-grid-platform by OSGP.
the class CommonGetConfigurationRequestMessageProcessor method handleGetConfigurationDeviceResponse.
private void handleGetConfigurationDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final DomainInformation domainInformation, final String messageType, final int retryCount, final boolean isScheduled) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
ConfigurationDto configuration = null;
try {
final GetConfigurationDeviceResponse response = (GetConfigurationDeviceResponse) deviceResponse;
configuration = response.getConfiguration();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Unexpected exception while retrieving response message", e);
}
final MessageMetadata messageMetadata = MessageMetadata.newBuilder().withDeviceIdentification(deviceResponse.getDeviceIdentification()).withOrganisationIdentification(deviceResponse.getOrganisationIdentification()).withCorrelationUid(deviceResponse.getCorrelationUid()).withMessageType(messageType).withDomain(domainInformation.getDomain()).withDomainVersion(domainInformation.getDomainVersion()).withMessagePriority(deviceResponse.getMessagePriority()).withScheduled(isScheduled).withRetryCount(retryCount).build();
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(configuration).build();
responseMessageSender.send(responseMessage);
}
Aggregations