use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class DefaultDeviceResponseServiceTest method testDefaultDeviceResponseWithNotOkTypeAndException.
@Test
public void testDefaultDeviceResponseWithNotOkTypeAndException() {
// Arrange
final ResponseMessageResultType deviceResult = ResponseMessageResultType.NOT_OK;
final OsgpException exception = new OsgpException(ComponentType.DOMAIN_CORE, "There was an exception");
final ResponseMessage expectedResponseMessage = ResponseMessage.newResponseMessageBuilder().withIds(IDS).withResult(ResponseMessageResultType.NOT_OK).withOsgpException(exception).withMessagePriority(MESSAGE_PRIORITY).withMessageType(MESSAGE_TYPE).build();
// Act
this.defaultDeviceResponseService.handleDefaultDeviceResponse(IDS, MESSAGE_TYPE, MESSAGE_PRIORITY, deviceResult, exception);
final ArgumentCaptor<ResponseMessage> argument = ArgumentCaptor.forClass(ResponseMessage.class);
verify(this.webServiceResponseMessageSender).send(argument.capture());
// Assert
assertThat(argument.getValue()).usingRecursiveComparison().isEqualTo(expectedResponseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementService method handleGetConfigurationResponse.
public void handleGetConfigurationResponse(final ConfigurationDto configurationDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = exception;
Configuration configuration = null;
try {
if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
final List<DeviceOutputSetting> outputSettings = ssld.getOutputSettings();
this.replaceEmptyOutputSettings(configurationDto, outputSettings);
configuration = this.domainCoreMapper.map(configurationDto, Configuration.class);
// TARIFF_REVERSED will be changed to the correct RelayType.
for (final DeviceOutputSetting dos : outputSettings) {
if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
if (rm.getIndex() == dos.getExternalId() && rm.getRelayType().equals(RelayType.TARIFF)) {
rm.changeRelayType(RelayType.TARIFF_REVERSED);
}
}
}
}
} catch (final Exception e) {
LOGGER.error("Unexpected Exception for messageType: {}", messageType, e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, e.getMessage(), e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(configuration).withMessagePriority(messagePriority).withMessageType(MessageType.GET_CONFIGURATION.name()).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class CommonGetConfigurationResponseMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
LOGGER.debug("Processing common get configuration response message");
String correlationUid = null;
String messageType = null;
int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
String organisationIdentification = null;
String deviceIdentification = null;
ResponseMessage responseMessage;
ResponseMessageResultType responseMessageResultType = null;
OsgpException osgpException = null;
Object dataObject;
try {
correlationUid = message.getJMSCorrelationID();
messageType = message.getJMSType();
messagePriority = message.getJMSPriority();
organisationIdentification = message.getStringProperty(Constants.ORGANISATION_IDENTIFICATION);
deviceIdentification = message.getStringProperty(Constants.DEVICE_IDENTIFICATION);
responseMessage = (ResponseMessage) message.getObject();
responseMessageResultType = responseMessage.getResult();
osgpException = responseMessage.getOsgpException();
dataObject = responseMessage.getDataObject();
} catch (final JMSException e) {
LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
LOGGER.debug("correlationUid: {}", correlationUid);
LOGGER.debug("messageType: {}", messageType);
LOGGER.debug("messagePriority: {}", messagePriority);
LOGGER.debug("organisationIdentification: {}", organisationIdentification);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
LOGGER.debug("responseMessageResultType: {}", responseMessageResultType);
LOGGER.debug("deviceIdentification: {}", deviceIdentification);
LOGGER.debug("osgpException", osgpException);
return;
}
try {
LOGGER.info("Calling application service function to handle response: {}", messageType);
final ConfigurationDto configurationDto = (ConfigurationDto) dataObject;
final CorrelationIds ids = new CorrelationIds(organisationIdentification, deviceIdentification, correlationUid);
this.configurationManagementService.handleGetConfigurationResponse(configurationDto, ids, messageType, messagePriority, responseMessageResultType, osgpException);
} catch (final Exception e) {
this.handleError(e, correlationUid, organisationIdentification, deviceIdentification, messageType, messagePriority);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class MonitoringEndpoint method getPQValuesPeriodic.
@PayloadRoot(localPart = "GetPQValuesPeriodicRequest", namespace = NAMESPACE)
@ResponsePayload
public GetPQValuesPeriodicAsyncResponse getPQValuesPeriodic(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetPQValuesPeriodicRequest request) throws OsgpException {
LOGGER.info("Get PQ Values Periodic Request received from organisation: {} for device: {}.", organisationIdentification, request.getDeviceIdentification());
final GetPQValuesPeriodicAsyncResponse response = new GetPQValuesPeriodicAsyncResponse();
try {
final org.opensmartgridplatform.domain.da.valueobjects.GetPQValuesPeriodicRequest getPQValuesPeriodicRequest = this.mapper.map(request, org.opensmartgridplatform.domain.da.valueobjects.GetPQValuesPeriodicRequest.class);
final String correlationUid = this.service.enqueueGetPQValuesPeriodicRequest(organisationIdentification, request.getDeviceIdentification(), getPQValuesPeriodicRequest);
final AsyncResponse asyncResponse = new AsyncResponse();
asyncResponse.setCorrelationUid(correlationUid);
asyncResponse.setDeviceId(request.getDeviceIdentification());
response.setAsyncResponse(asyncResponse);
} catch (final Exception e) {
this.handleException(LOGGER, e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class MonitoringEndpoint method getMeasurementReport.
@PayloadRoot(localPart = "GetMeasurementReportRequest", namespace = NAMESPACE)
@ResponsePayload
public GetMeasurementReportResponse getMeasurementReport(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetMeasurementReportRequest request) throws OsgpException {
LOGGER.info("Get Measurement Report Request received from organisation: {} for correlationUid: {}.", organisationIdentification, request.getCorrelationUid());
final GetMeasurementReportResponse response = new GetMeasurementReportResponse();
try {
final org.opensmartgridplatform.domain.da.measurements.MeasurementReport dataResponse = this.service.dequeueMeasurementReport(request.getCorrelationUid());
if (dataResponse != null) {
final MeasurementReport report = this.mapper.map(dataResponse, MeasurementReport.class);
response.setMeasurementReport(report);
response.setResult(OsgpResultType.OK);
} else {
response.setResult(OsgpResultType.NOT_FOUND);
}
} catch (final ResponseNotFoundException e) {
LOGGER.warn("ResponseNotFoundException for getMeasurementReport", e);
response.setResult(OsgpResultType.NOT_FOUND);
} catch (final Exception e) {
this.handleException(LOGGER, e);
}
return response;
}
Aggregations