use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage 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.infra.jms.ResponseMessage 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.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class WebServiceResponseMessageSender method send.
/**
* Send a response message to the web service adapter using a custom time to live.
*
* @param responseMessage The response message to send.
* @param timeToLive The custom time to live value in milliseconds.
*/
public void send(final ResponseMessage responseMessage, final Long timeToLive, final String messageType) {
// Keep the original time to live from configuration.
final Long originalTimeToLive = this.jmsTemplate.getTimeToLive();
if (timeToLive != null) {
// Set the custom time to live.
this.jmsTemplate.setTimeToLive(timeToLive);
}
this.jmsTemplate.send(new MessageCreator() {
@Override
public Message createMessage(final Session session) throws JMSException {
final ObjectMessage objectMessage = session.createObjectMessage(responseMessage);
objectMessage.setJMSCorrelationID(responseMessage.getCorrelationUid());
objectMessage.setJMSType(messageType);
objectMessage.setStringProperty(Constants.ORGANISATION_IDENTIFICATION, responseMessage.getOrganisationIdentification());
objectMessage.setStringProperty(Constants.DEVICE_IDENTIFICATION, responseMessage.getDeviceIdentification());
objectMessage.setStringProperty(Constants.RESULT, responseMessage.getResult().toString());
if (responseMessage.getOsgpException() != null) {
objectMessage.setStringProperty(Constants.DESCRIPTION, responseMessage.getOsgpException().getMessage());
}
return objectMessage;
}
});
if (timeToLive != null) {
// Restore the time to live from the configuration.
this.jmsTemplate.setTimeToLive(originalTimeToLive);
}
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class ConfigurationService method handleGetConfigurationObjectResponse.
public void handleGetConfigurationObjectResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception, final GetConfigurationObjectResponseDto resultData) {
log.info("handle GetConfigurationObject response for MessageType: {}", messageMetadata.getMessageType());
final GetConfigurationObjectResponse response = this.configurationMapper.map(resultData, GetConfigurationObjectResponse.class);
ResponseMessageResultType result = deviceResult;
if (exception != null) {
log.error(DEVICE_RESPONSE_NOT_OK_LOG_MSG, exception);
result = ResponseMessageResultType.NOT_OK;
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).withDataObject(response).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
use of org.opensmartgridplatform.shared.infra.jms.ResponseMessage in project open-smart-grid-platform by OSGP.
the class ConfigurationService method handleSetPushSetupSmsResponse.
public void handleSetPushSetupSmsResponse(final MessageMetadata messageMetadata, final ResponseMessageResultType deviceResult, final OsgpException exception) {
log.info("handleSetPushSetupSmsResponse for MessageType: {}", messageMetadata.getMessageType());
ResponseMessageResultType result = deviceResult;
if (exception != null) {
log.error("Set Push Setup Sms Response not ok. Unexpected Exception", exception);
result = ResponseMessageResultType.NOT_OK;
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withMessageMetadata(messageMetadata).withResult(result).withOsgpException(exception).build();
this.webServiceResponseMessageSender.send(responseMessage, messageMetadata.getMessageType());
}
Aggregations