use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class OsgpResponseMessageProcessor method processMessageTask.
// SilentException cannot be caught since
@SuppressWarnings("squid:S1193")
private // it does not extend Exception.
void processMessageTask(final Serializable messageObject, final MessageMetadata messageMetadata, final DlmsConnectionManager conn) throws OsgpException {
try {
final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
LOGGER.info("{} called for device: {} for organisation: {}", messageMetadata.getMessageType(), messageMetadata.getDeviceIdentification(), messageMetadata.getOrganisationIdentification());
if (this.usesDeviceConnection()) {
this.handleMessage(conn, this.domainHelperService.findDlmsDevice(messageMetadata), messageObject);
} else {
this.handleMessage(device, messageObject);
}
} catch (final Exception exception) {
// Return original request + exception
if (!(exception instanceof SilentException)) {
LOGGER.error("Unexpected exception during {}", this.messageType.name(), exception);
}
this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, exception, this.responseMessageSender, messageObject);
} finally {
final DlmsDevice device = this.domainHelperService.findDlmsDevice(messageMetadata);
this.doConnectionPostProcessing(device, conn, messageMetadata);
}
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method getProtocolInfos.
@PayloadRoot(localPart = "GetProtocolInfosRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public GetProtocolInfosResponse getProtocolInfos(@OrganisationIdentification final String organisationIdentification, @RequestPayload final GetProtocolInfosRequest request) throws OsgpException {
LOGGER.info("Get protocol infos for organisation: {}.", organisationIdentification);
final GetProtocolInfosResponse getProtocolInfosResponse = new GetProtocolInfosResponse();
try {
final List<org.opensmartgridplatform.domain.core.entities.ProtocolInfo> protocolInfos = this.deviceManagementService.getProtocolInfos(organisationIdentification);
getProtocolInfosResponse.getProtocolInfos().addAll(this.deviceManagementMapper.mapAsList(protocolInfos, org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.ProtocolInfo.class));
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_TYPE_WS_ADMIN, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return getProtocolInfosResponse;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method setCommunicationNetworkInformation.
@PayloadRoot(localPart = "SetCommunicationNetworkInformationRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public SetCommunicationNetworkInformationResponse setCommunicationNetworkInformation(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetCommunicationNetworkInformationRequest request) throws OsgpException {
LOGGER.info("SetCommunicationNetworkInformation for organisation: {} and device: {}.", organisationIdentification, request.getDeviceIdentification());
SetCommunicationNetworkInformationResponse response = null;
try {
response = new SetCommunicationNetworkInformationResponse();
final org.opensmartgridplatform.domain.core.entities.Device updatedDevice = this.deviceManagementService.updateCommunicationNetworkInformation(organisationIdentification, request.getDeviceIdentification(), request.getIpAddress(), request.getBtsId(), request.getCellId());
response.setResult(OsgpResultType.OK);
response.setIpAddress(updatedDevice.getIpAddress());
response.setBtsId(updatedDevice.getBtsId());
response.setCellId(updatedDevice.getCellId());
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_TYPE_WS_ADMIN, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class DeviceManagementEndpoint method findDevicesWhichHaveNoOwner.
@PayloadRoot(localPart = "FindDevicesWhichHaveNoOwnerRequest", namespace = DEVICE_MANAGEMENT_NAMESPACE)
@ResponsePayload
public FindDevicesWhichHaveNoOwnerResponse findDevicesWhichHaveNoOwner(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindDevicesWhichHaveNoOwnerRequest request) throws OsgpException {
LOGGER.info("Finding devices which have no owner for organisation: {}.", organisationIdentification);
final FindDevicesWhichHaveNoOwnerResponse response = new FindDevicesWhichHaveNoOwnerResponse();
try {
final List<org.opensmartgridplatform.domain.core.entities.Device> devicesWithoutOwner = this.deviceManagementService.findDevicesWhichHaveNoOwner(organisationIdentification);
response.getDevices().addAll(this.deviceManagementMapper.mapAsList(devicesWithoutOwner, org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.Device.class));
} catch (final ConstraintViolationException e) {
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_TYPE_WS_ADMIN, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.shared.exceptionhandling.OsgpException in project open-smart-grid-platform by OSGP.
the class GetFirmwareFileMessageProcessor method processMessage.
@Override
public void processMessage(final ObjectMessage message) throws JMSException {
MessageMetadata metadata = null;
Device device = null;
String firmwareFileIdentification = StringUtils.EMPTY;
try {
metadata = MessageMetadata.fromMessage(message);
LOGGER.info("[{}] - Received message of messageType: {}, organisationIdentification: {}, deviceIdentification: {}", metadata.getCorrelationUid(), metadata.getMessageType(), metadata.getOrganisationIdentification(), metadata.getDeviceIdentification());
device = this.deviceRepository.findByDeviceIdentification(metadata.getDeviceIdentification());
final RequestMessage requestMessage = (RequestMessage) message.getObject();
final UpdateFirmwareRequestDto updateFirmwareRequestDto = (UpdateFirmwareRequestDto) requestMessage.getRequest();
firmwareFileIdentification = updateFirmwareRequestDto.getFirmwareIdentification();
final FirmwareFile firmwareFile = this.firmwareFileRepository.findByIdentificationOnly(firmwareFileIdentification);
final FirmwareFileDto firmwareFileDto = new FirmwareFileDto(firmwareFileIdentification, updateFirmwareRequestDto.getDeviceIdentification(), firmwareFile.getFile(), firmwareFile.getImageIdentifier());
this.sendSuccesResponse(metadata, device.getProtocolInfo(), firmwareFileDto);
} catch (final Exception e) {
LOGGER.error("Exception while retrieving firmware file: {}", firmwareFileIdentification);
final OsgpException osgpException = new OsgpException(ComponentType.OSGP_CORE, "Exception while retrieving firmware file.", e);
this.sendFailureResponse(metadata, device.getProtocolInfo(), osgpException);
}
}
Aggregations