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;
}
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);
}
}
}
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);
}
}
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);
}
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);
}
Aggregations