use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class CommonGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.
private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
DeviceStatusDto status = null;
try {
final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
status = response.getDeviceStatus();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
}
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build()).result(result).osgpException(osgpException).dataObject(status).build();
responseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class PublicLightingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.
private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
DeviceStatusDto status = null;
try {
final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
status = response.getDeviceStatus();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
}
final MessageMetadata messageMetadata = MessageMetadataFactory.from(deviceResponse, messageType).builder().withDomain(domain).withDomainVersion(domainVersion).withRetryCount(retryCount).build();
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().messageMetadata(messageMetadata).result(result).osgpException(osgpException).dataObject(status).build();
responseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class OsgpResponseMessageListener method onMessage.
@Override
public void onMessage(final Message message) {
try {
LOGGER.info("Received message of type: {}", message.getJMSType());
final ObjectMessage objectMessage = (ObjectMessage) message;
final String messageType = objectMessage.getJMSType();
final String deviceIdentification = objectMessage.getStringProperty(Constants.DEVICE_IDENTIFICATION);
final ResponseMessage responseMessage = (ResponseMessage) objectMessage.getObject();
final String result = responseMessage == null ? null : responseMessage.getResult().toString();
final OsgpException osgpException = responseMessage == null ? null : responseMessage.getOsgpException();
if (MessageType.REGISTER_DEVICE.name().equals(messageType)) {
if (ResponseMessageResultType.valueOf(result).equals(ResponseMessageResultType.NOT_OK)) {
throw new ProtocolAdapterException(String.format("Response for device: %s for MessageType: %s is: %s, error: %s", deviceIdentification, messageType, result, osgpException));
} else {
throw new UnknownMessageTypeException("Unknown JMSType: " + messageType);
}
}
} catch (final JMSException ex) {
LOGGER.error("Exception: {} ", ex.getMessage(), ex);
} catch (final ProtocolAdapterException e) {
LOGGER.error("ProtocolAdapterException", e);
} catch (final UnknownMessageTypeException e) {
LOGGER.error("UnknownMessageTypeException", e);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class FirmwareService method checkFirmwareFileSupportsDeviceModel.
public void checkFirmwareFileSupportsDeviceModel(final SmartMeter smartMeter, final FirmwareFile firmware) throws FunctionalException {
final DeviceModel deviceModel = this.determineDeviceModel(smartMeter);
final List<String> deviceModelCodes = firmware.getDeviceModels().stream().map(DeviceModel::getModelCode).collect(Collectors.toList());
if (!deviceModelCodes.contains(deviceModel.getModelCode())) {
throw new FunctionalException(FunctionalExceptionType.FIRMWARE_DOES_NOT_SUPPORT_DEVICE_MODEL, ComponentType.DOMAIN_SMART_METERING, new OsgpException(ComponentType.DOMAIN_SMART_METERING, String.format("DeviceModel %s of smartmeter %s is not in list of devicemodels supported by firmware file %s : %s", smartMeter.getDeviceModel().getModelCode(), smartMeter.getDeviceIdentification(), firmware.getIdentification(), deviceModelCodes)));
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementEndpoint method getGetConfigurationResponse.
@PayloadRoot(localPart = "GetConfigurationAsyncRequest", namespace = NAMESPACE)
@ResponsePayload
public GetConfigurationResponse getGetConfigurationResponse(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetConfigurationAsyncRequest request) throws OsgpException {
LOGGER.info("GetConfigurationRequest received from organisation: {} for device: {}.", organisationIdentification, request.getAsyncRequest().getDeviceId());
final GetConfigurationResponse response = new GetConfigurationResponse();
try {
final ResponseMessage responseMessage = this.getResponseMessage(request.getAsyncRequest());
if (responseMessage != null) {
throwExceptionIfResultNotOk(responseMessage, "getting configuration");
response.setResult(OsgpResultType.fromValue(responseMessage.getResult().getValue()));
if (responseMessage.getDataObject() != null) {
final Configuration configuration = (Configuration) responseMessage.getDataObject();
response.setConfiguration(this.configurationManagementMapper.map(configuration, org.opensmartgridplatform.adapter.ws.schema.core.configurationmanagement.Configuration.class));
}
} else {
LOGGER.debug("Get Configuration data is null");
}
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
Aggregations