Search in sources :

Example 1 with UnknownEntityException

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);
}
Also used : UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 2 with UnknownEntityException

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);
    }
}
Also used : RtuDevice(org.opensmartgridplatform.domain.core.entities.RtuDevice) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) OptimisticLockException(javax.persistence.OptimisticLockException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 3 with UnknownEntityException

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));
        }
    }
}
Also used : JpaSystemException(org.springframework.orm.jpa.JpaSystemException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PersistenceException(javax.persistence.PersistenceException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 4 with UnknownEntityException

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));
        }
    }
}
Also used : JpaSystemException(org.springframework.orm.jpa.JpaSystemException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PersistenceException(javax.persistence.PersistenceException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Example 5 with UnknownEntityException

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));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) DeviceAuthorizationRepository(org.opensmartgridplatform.domain.core.repositories.DeviceAuthorizationRepository) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Date(java.util.Date) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) ObjectMessage(javax.jms.ObjectMessage) MessageType(org.opensmartgridplatform.shared.infra.jms.MessageType) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Answer(org.mockito.stubbing.Answer) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) DomainRequestService(org.opensmartgridplatform.core.domain.model.domain.DomainRequestService) DomainInfo(org.opensmartgridplatform.domain.core.entities.DomainInfo) DeviceRepository(org.opensmartgridplatform.domain.core.repositories.DeviceRepository) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) JMSException(javax.jms.JMSException) EventNotificationMessageService(org.opensmartgridplatform.core.application.services.EventNotificationMessageService) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PushNotificationAlarmDto(org.opensmartgridplatform.dto.valueobjects.smartmetering.PushNotificationAlarmDto) Device(org.opensmartgridplatform.domain.core.entities.Device) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) DomainInfoRepository(org.opensmartgridplatform.domain.core.repositories.DomainInfoRepository) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup) Collections(java.util.Collections) EventType(org.opensmartgridplatform.domain.core.valueobjects.EventType) Device(org.opensmartgridplatform.domain.core.entities.Device) RequestMessage(org.opensmartgridplatform.shared.infra.jms.RequestMessage) DomainInfo(org.opensmartgridplatform.domain.core.entities.DomainInfo) Date(java.util.Date) ObjectMessageBuilder(org.opensmartgridplatform.shared.infra.jms.ObjectMessageBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)17 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)15 Transactional (org.springframework.transaction.annotation.Transactional)9 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)8 Device (org.opensmartgridplatform.domain.core.entities.Device)6 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)6 NotAuthorizedException (org.opensmartgridplatform.domain.core.exceptions.NotAuthorizedException)4 RequestMessage (org.opensmartgridplatform.shared.infra.jms.RequestMessage)4 PersistenceException (javax.persistence.PersistenceException)3 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)3 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)3 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)3 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)3 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)3 JpaSystemException (org.springframework.orm.jpa.JpaSystemException)3 JMSException (javax.jms.JMSException)2 OptimisticLockException (javax.persistence.OptimisticLockException)2 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)2 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)2 RtuDevice (org.opensmartgridplatform.domain.core.entities.RtuDevice)2