Search in sources :

Example 71 with OsgpException

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);
    }
}
Also used : DlmsDevice(org.opensmartgridplatform.adapter.protocol.dlms.domain.entities.DlmsDevice) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException) SilentException(org.opensmartgridplatform.adapter.protocol.dlms.exceptions.SilentException)

Example 72 with OsgpException

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;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) GetProtocolInfosResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.GetProtocolInfosResponse) ProtocolInfo(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.ProtocolInfo) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 73 with OsgpException

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;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) SetCommunicationNetworkInformationResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.SetCommunicationNetworkInformationResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 74 with OsgpException

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;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) FindDevicesWhichHaveNoOwnerResponse(org.opensmartgridplatform.adapter.ws.schema.admin.devicemanagement.FindDevicesWhichHaveNoOwnerResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) TransactionSystemException(org.springframework.transaction.TransactionSystemException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 75 with OsgpException

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);
    }
}
Also used : UpdateFirmwareRequestDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.UpdateFirmwareRequestDto) FirmwareFileDto(org.opensmartgridplatform.dto.valueobjects.FirmwareFileDto) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) JMSException(javax.jms.JMSException)

Aggregations

OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)235 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)153 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)153 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)128 ConstraintViolationException (javax.validation.ConstraintViolationException)98 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)75 ResponseMessage (org.opensmartgridplatform.shared.infra.jms.ResponseMessage)67 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)64 ResponseMessageResultType (org.opensmartgridplatform.shared.infra.jms.ResponseMessageResultType)54 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)51 JMSException (javax.jms.JMSException)40 IOException (java.io.IOException)30 GetKeysResponseData (org.opensmartgridplatform.adapter.ws.schema.smartmetering.configuration.GetKeysResponseData)23 CorrelationIds (org.opensmartgridplatform.shared.infra.jms.CorrelationIds)18 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)17 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)15 ProtocolResponseMessage (org.opensmartgridplatform.shared.infra.jms.ProtocolResponseMessage)15 ResponseNotFoundException (org.opensmartgridplatform.adapter.ws.da.application.exceptionhandling.ResponseNotFoundException)10 Device (org.opensmartgridplatform.domain.core.entities.Device)10 ArrayList (java.util.ArrayList)9