Search in sources :

Example 91 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class PublicLightingAdHocManagementEndpoint method setLight.

// === SET LIGHT ===
@PayloadRoot(localPart = "SetLightRequest", namespace = NAMESPACE)
@ResponsePayload
public SetLightAsyncResponse setLight(@OrganisationIdentification final String organisationIdentification, @RequestPayload final SetLightRequest request, @MessagePriority final String messagePriority) throws OsgpException {
    LOGGER.info("Set Light Request received from organisation: {} for device: {} with message priority: {}.", organisationIdentification, request.getDeviceIdentification(), messagePriority);
    final SetLightAsyncResponse response = new SetLightAsyncResponse();
    try {
        final List<LightValue> lightValues = new ArrayList<>(this.adHocManagementMapper.mapAsList(request.getLightValue(), LightValue.class));
        final String correlationUid = this.adHocManagementService.enqueueSetLightRequest(organisationIdentification, request.getDeviceIdentification(), lightValues, MessagePriorityEnum.getMessagePriority(messagePriority));
        final AsyncResponse asyncResponse = new AsyncResponse();
        asyncResponse.setCorrelationUid(correlationUid);
        asyncResponse.setDeviceId(request.getDeviceIdentification());
        response.setAsyncResponse(asyncResponse);
    } catch (final ConstraintViolationException e) {
        LOGGER.error(EXCEPTION_OCCURRED, e);
        throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
    } catch (final Exception e) {
        this.handleException(e);
    }
    return response;
}
Also used : ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) LightValue(org.opensmartgridplatform.domain.core.valueobjects.LightValue) ArrayList(java.util.ArrayList) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) AsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.AsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) ResumeScheduleAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.ResumeScheduleAsyncResponse) GetStatusAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.GetStatusAsyncResponse) SetTransitionAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetTransitionAsyncResponse) SetLightAsyncResponse(org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.SetLightAsyncResponse) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) 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 92 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DetailSoapFaultMappingExceptionResolver method customizeFault.

@Override
protected void customizeFault(final Object endpoint, final Exception ex, final SoapFault fault) {
    final SoapFaultDetail detail = fault.addFaultDetail();
    final Result result = detail.getResult();
    FunctionalException fex = null;
    TechnicalException tex = null;
    ConnectionFailureException cex = null;
    if (ex instanceof FunctionalException) {
        fex = (FunctionalException) ex;
    } else if (ex instanceof TechnicalException) {
        tex = (TechnicalException) ex;
    } else if (ex instanceof ConnectionFailureException) {
        cex = (ConnectionFailureException) ex;
    }
    if (fex != null) {
        try {
            this.marshalFunctionalException(fex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Functional Exception", e);
        }
    }
    if (tex != null) {
        try {
            this.marshalTechnicalException(tex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Technical Exception", e);
        }
    }
    if (cex != null) {
        try {
            this.marshalConnectionFailureException(cex, result);
        } catch (final JAXBException e) {
            LOGGER.error("Unable to marshal the Connection Failure Exception", e);
        }
    }
}
Also used : TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) SoapFaultDetail(org.springframework.ws.soap.SoapFaultDetail) ConnectionFailureException(org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException) JAXBException(javax.xml.bind.JAXBException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) Result(javax.xml.transform.Result)

Example 93 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class FirmwareManagementService method handleSsldPendingFirmwareUpdate.

public void handleSsldPendingFirmwareUpdate(final String deviceIdentification) {
    final List<SsldPendingFirmwareUpdate> ssldPendingFirmwareUpdates = this.ssldPendingFirmwareUpdateRepository.findByDeviceIdentification(deviceIdentification);
    if (CollectionUtils.isEmpty(ssldPendingFirmwareUpdates)) {
        return;
    }
    /*
     * A pending firmware update record was stored for this device earlier.
     * This means this method is probably called following a firmware
     * update. Retrieve the firmware version from the device to have the
     * current version that is installed available.
     *
     * If multiple pending update records exist, it is not really clear what
     * to do. The following approach assumes the most recently created one
     * is relevant, and other pending records are out-dated.
     */
    final SsldPendingFirmwareUpdate ssldPendingFirmwareUpdate;
    if (ssldPendingFirmwareUpdates.size() == 1) {
        ssldPendingFirmwareUpdate = ssldPendingFirmwareUpdates.get(0);
    } else {
        LOGGER.warn("Found multiple pending firmware update records for SSLD: {}", ssldPendingFirmwareUpdates);
        ssldPendingFirmwareUpdate = this.getMostRecentSsldPendingFirmwareUpdate(ssldPendingFirmwareUpdates).orElseThrow(() -> new AssertionError("No most recent pending firmware update from a non-empty list"));
        this.deleteOutdatedSsldPendingFirmwareUpdates(ssldPendingFirmwareUpdates, ssldPendingFirmwareUpdate);
    }
    final String organisationIdentification = ssldPendingFirmwareUpdate.getOrganisationIdentification();
    final String correlationUid = ssldPendingFirmwareUpdate.getCorrelationUid();
    LOGGER.info("Handling SSLD pending firmware update for device identification: {}, organisation identification: {} and correlation UID: {}.", deviceIdentification, organisationIdentification, correlationUid);
    try {
        final int messagePriority = MessagePriorityEnum.DEFAULT.getPriority();
        this.getFirmwareVersion(organisationIdentification, deviceIdentification, correlationUid, DeviceFunction.GET_FIRMWARE_VERSION.name(), messagePriority, this.getFirmwareVersionDelay);
    } catch (final FunctionalException e) {
        LOGGER.error("Caught exception when calling get firmware version", e);
    }
}
Also used : SsldPendingFirmwareUpdate(org.opensmartgridplatform.domain.core.entities.SsldPendingFirmwareUpdate) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 94 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DeviceInstallationService method handleGetStatusResponse.

public void handleGetStatusResponse(final DeviceStatusDto deviceStatusDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
    LOGGER.info("handleResponse for MessageType: {}", messageType);
    final GetStatusResponse response = new GetStatusResponse();
    response.setOsgpException(exception);
    response.setResult(deviceResult);
    if (deviceResult == ResponseMessageResultType.NOT_OK || exception != null) {
        LOGGER.error("Device Response not ok.", exception);
    } else {
        final DeviceStatus status = this.domainCoreMapper.map(deviceStatusDto, DeviceStatus.class);
        try {
            final Device dev = this.deviceDomainService.searchDevice(ids.getDeviceIdentification());
            if (LightMeasurementDevice.LMD_TYPE.equals(dev.getDeviceType())) {
                this.handleLmd(status, response);
            } else {
                this.handleSsld(ids.getDeviceIdentification(), status, response);
            }
        } catch (final FunctionalException e) {
            LOGGER.error("Caught FunctionalException", e);
        }
    }
    final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(response.getResult()).withOsgpException(response.getOsgpException()).withDataObject(response.getDeviceStatusMapped()).withMessagePriority(messagePriority).withMessageType(MessageType.GET_STATUS.name()).build();
    this.webServiceResponseMessageSender.send(responseMessage);
}
Also used : GetStatusResponse(org.opensmartgridplatform.adapter.domain.shared.GetStatusResponse) LightMeasurementDevice(org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceStatus(org.opensmartgridplatform.domain.core.valueobjects.DeviceStatus) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponseMessage(org.opensmartgridplatform.shared.infra.jms.ResponseMessage)

Example 95 with FunctionalException

use of org.opensmartgridplatform.shared.exceptionhandling.FunctionalException in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method updateKey.

// === UPDATE KEY ===
public void updateKey(final String organisationIdentification, @Identification final String deviceIdentification, final String correlationUid, final String messageType, @PublicKey final String publicKey) throws FunctionalException {
    LOGGER.info("MessageType: {}. Updating key for device [{}] on behalf of organisation [{}]", messageType, deviceIdentification, organisationIdentification);
    try {
        this.organisationDomainService.searchOrganisation(organisationIdentification);
    } catch (final UnknownEntityException e) {
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_ORGANISATION, ComponentType.DOMAIN_ADMIN, e);
    }
    this.osgpCoreRequestMessageSender.send(new RequestMessage(correlationUid, organisationIdentification, deviceIdentification, publicKey), messageType, null);
}
Also used : UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Aggregations

FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)155 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)63 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)54 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)54 ConstraintViolationException (javax.validation.ConstraintViolationException)51 ValidationException (org.opensmartgridplatform.domain.core.exceptions.ValidationException)47 Device (org.opensmartgridplatform.domain.core.entities.Device)32 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)31 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)22 Transactional (org.springframework.transaction.annotation.Transactional)19 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)15 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)12 SmartMeter (org.opensmartgridplatform.domain.core.entities.SmartMeter)12 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)11 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)11 ArrayList (java.util.ArrayList)10 Test (org.junit.jupiter.api.Test)10 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)10 ResponseData (org.opensmartgridplatform.adapter.ws.domain.entities.ResponseData)9 AsyncResponse (org.opensmartgridplatform.adapter.ws.schema.core.common.AsyncResponse)9