use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method revokeKey.
// === REVOKE KEY ===
public void revokeKey(final String organisationIdentification, @Identification final String deviceIdentification, final String correlationUid, final String messageType) throws FunctionalException {
LOGGER.info("MessageType: {}. Revoking 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, null), messageType, null);
}
use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method handleResponseMessageReceived.
private void handleResponseMessageReceived(final String deviceIdentification) throws FunctionalException {
try {
final RtuDevice device = this.rtuDeviceRepository.findByDeviceIdentification(deviceIdentification).orElseThrow(() -> new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICE, COMPONENT_TYPE, new UnknownEntityException(RtuDevice.class, deviceIdentification)));
if (this.shouldUpdateCommunicationTime(device)) {
device.messageReceived();
this.rtuDeviceRepository.save(device);
} else {
LOGGER.info("Last communication time within duration: {}. Skipping last communication date update.", this.minimumDurationBetweenCommunicationTimeUpdates);
}
} catch (final OptimisticLockException ex) {
LOGGER.warn("Last communication time not updated due to optimistic lock exception", ex);
}
}
use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method changeOrganisation.
public void changeOrganisation(@Identification final String organisationIdentification, @Identification final String organisationToBeChangedIdentification, final String newOrganisationName, @NotNull final PlatformFunctionGroup newOrganisationPlatformFunctionGroup, @NotNull final List<PlatformDomain> newDomains) throws FunctionalException {
LOGGER.info("changeOrganisation called with organisation {} and organisation to change {}. new values for organisationName {}, organisationPlatformFunctionGroup {}", organisationIdentification, organisationToBeChangedIdentification, newOrganisationName, newOrganisationPlatformFunctionGroup);
final Organisation organisation = this.findOrganisation(organisationIdentification);
this.isAllowed(organisation, PlatformFunction.CHANGE_ORGANISATION);
try {
final Organisation organisationToChange = this.findOrganisation(organisationToBeChangedIdentification);
organisationToChange.changeOrganisationData(newOrganisationName, newOrganisationPlatformFunctionGroup);
organisationToChange.setDomains(newDomains);
this.organisationRepository.save(organisationToChange);
} catch (final JpaSystemException ex) {
if (ex.getCause() instanceof PersistenceException) {
LOGGER.error("change organisation failure JpaSystemException", ex);
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_ORGANISATION, ComponentType.WS_ADMIN, new UnknownEntityException(Organisation.class, organisationToBeChangedIdentification, ex));
}
}
}
use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method activateOrganisation.
public void activateOrganisation(@Identification final String organisationIdentification, @Identification final String organisationIdentificationToActivate) throws FunctionalException {
LOGGER.debug("activateOrganisation called with organisation {} and organisation to activate {}", organisationIdentification, organisationIdentificationToActivate);
final Organisation organisation = this.findOrganisation(organisationIdentification);
final Organisation organisationToActivate = this.findOrganisation(organisationIdentificationToActivate);
this.isAllowed(organisation, PlatformFunction.CHANGE_ORGANISATION);
try {
organisationToActivate.setIsEnabled(true);
this.organisationRepository.save(organisationToActivate);
} catch (final JpaSystemException ex) {
if (ex.getCause() instanceof PersistenceException) {
LOGGER.error("activate organisation failure JpaSystemException", ex);
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_ORGANISATION, ComponentType.WS_ADMIN, new UnknownEntityException(Organisation.class, organisationIdentificationToActivate, ex));
}
}
}
use of org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException in project open-smart-grid-platform by OSGP.
the class PushNotificationAlarmMessageProcessorTest method init.
@BeforeEach
public void init() throws JMSException, UnknownEntityException {
final String correlationUid = "corr-uid-1";
final String organisationIdentification = "test-org";
final String ipAddress = "127.0.0.1";
final RequestMessage requestMessage = new RequestMessage(correlationUid, organisationIdentification, DEVICE_IDENTIFICATION, ipAddress, null, null, this.pushNotificationAlarm);
this.message = new ObjectMessageBuilder().withCorrelationUid(correlationUid).withMessageType(MessageType.PUSH_NOTIFICATION_ALARM.name()).withDeviceIdentification(DEVICE_IDENTIFICATION).withObject(requestMessage).build();
this.device = new Device(DEVICE_IDENTIFICATION);
when(this.deviceRepository.findByDeviceIdentification(DEVICE_IDENTIFICATION)).thenReturn(this.device);
when(this.deviceRepository.save(this.device)).thenAnswer((Answer<Void>) invocationOnMock -> null);
doNothing().when(this.eventNotificationMessageService).handleEvent(any(String.class), any(Date.class), any(EventType.class), any(String.class), any(Integer.class));
when(this.deviceAuthorizationRepository.findByDeviceAndFunctionGroup(this.device, DeviceFunctionGroup.OWNER)).thenReturn(Collections.singletonList(this.deviceAuthorization));
when(this.deviceAuthorization.getOrganisation()).thenReturn(this.organisation);
when(this.organisation.getOrganisationIdentification()).thenReturn(requestMessage.getOrganisationIdentification());
when(this.domainInfoRepository.findAll()).thenReturn(Collections.singletonList(this.domainInfo));
when(this.domainInfo.getDomain()).thenReturn("SMART_METERING");
when(this.domainInfo.getDomainVersion()).thenReturn("1.0");
doNothing().when(this.domainRequestService).send(any(RequestMessage.class), any(String.class), any(DomainInfo.class));
}
Aggregations