Search in sources :

Example 16 with DeviceAuthorization

use of org.opensmartgridplatform.domain.core.entities.DeviceAuthorization in project open-smart-grid-platform by OSGP.

the class DeviceSteps method theDeviceWithIdExists.

/**
 * Checks whether the device exists in the database..
 */
@Then("^the device with id \"([^\"]*)\" exists$")
public void theDeviceWithIdExists(final String deviceIdentification) throws Throwable {
    Wait.until(() -> {
        final Device entity = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
        assertThat(entity).as("Device with identification [" + deviceIdentification + "]").isNotNull();
        final List<DeviceAuthorization> devAuths = this.deviceAuthorizationRepository.findByDevice(entity);
        assertThat(entity).as("No entity found").isNotNull();
        assertThat(devAuths.size() > 0).as("DeviceAuthorizations amount is not > 0").isTrue();
    });
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Then(io.cucumber.java.en.Then)

Example 17 with DeviceAuthorization

use of org.opensmartgridplatform.domain.core.entities.DeviceAuthorization in project open-smart-grid-platform by OSGP.

the class DeviceSteps method theDeviceShouldBeRemoved.

/**
 * Checks whether the device does not exist in the database.
 */
@Then("^the device with id \"([^\"]*)\" should be removed$")
public void theDeviceShouldBeRemoved(final String deviceIdentification) throws Throwable {
    Wait.until(() -> {
        final Device entity = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
        assertThat(entity).as("Device with identification [" + deviceIdentification + "] should be removed").isNull();
        final List<DeviceAuthorization> devAuths = this.deviceAuthorizationRepository.findByDevice(entity);
        assertThat(devAuths.isEmpty()).as("DeviceAuthorizations for device with identification [" + deviceIdentification + "] should be removed").isTrue();
    });
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Then(io.cucumber.java.en.Then)

Example 18 with DeviceAuthorization

use of org.opensmartgridplatform.domain.core.entities.DeviceAuthorization in project open-smart-grid-platform by OSGP.

the class BaseDeviceSteps method updateWithAuthorization.

private Device updateWithAuthorization(final Device device, final Map<String, String> settings) {
    final String organizationIdentification = getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
    final Organisation organization = this.findOrganization(organizationIdentification);
    if (organization == null) {
        return device;
    }
    final DeviceFunctionGroup functionGroup = getEnum(settings, PlatformKeys.KEY_DEVICE_FUNCTION_GROUP, DeviceFunctionGroup.class, DeviceFunctionGroup.OWNER);
    final DeviceAuthorization authorization = device.addAuthorization(organization, functionGroup);
    this.deviceAuthorizationRepository.save(authorization);
    final Device savedDevice = this.deviceRepository.save(device);
    ScenarioContext.current().put(PlatformKeys.KEY_DEVICE_IDENTIFICATION, savedDevice.getDeviceIdentification());
    return savedDevice;
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup)

Example 19 with DeviceAuthorization

use of org.opensmartgridplatform.domain.core.entities.DeviceAuthorization in project open-smart-grid-platform by OSGP.

the class BaseDeviceSteps method setDefaultDeviceAuthorizationForDevice.

public DeviceAuthorization setDefaultDeviceAuthorizationForDevice(Device device) {
    device.addOrganisation(PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
    final Organisation organization = this.organizationRepository.findByOrganisationIdentification(PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
    device = this.deviceRepository.save(device);
    final DeviceAuthorization deviceAuthorization = device.addAuthorization(organization, DeviceFunctionGroup.OWNER);
    return this.deviceAuthorizationRepository.save(deviceAuthorization);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)

Example 20 with DeviceAuthorization

use of org.opensmartgridplatform.domain.core.entities.DeviceAuthorization in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method removeOrganisation.

public void removeOrganisation(@Identification final String organisationIdentification, @Identification final String organisationToRemoveIdentification) throws FunctionalException {
    LOGGER.debug("removeOrganisation called with organisation {} and organisation to remove {}", organisationIdentification, organisationToRemoveIdentification);
    final Organisation organisation = this.findOrganisation(organisationIdentification);
    final Organisation organisationToRemove = this.findOrganisation(organisationToRemoveIdentification);
    this.isAllowed(organisation, PlatformFunction.REMOVE_ORGANISATION);
    try {
        final List<DeviceAuthorization> deviceAuthorizations = this.authorizationRepository.findByOrganisation(organisationToRemove);
        if (!deviceAuthorizations.isEmpty()) {
            throw new FunctionalException(FunctionalExceptionType.EXISTING_DEVICE_AUTHORIZATIONS, ComponentType.WS_ADMIN, new ValidationException(String.format("Device Authorizations are still present for the current organisation %s", organisationToRemove.getOrganisationIdentification())));
        }
        organisationToRemove.setIsEnabled(false);
        this.organisationRepository.save(organisationToRemove);
    } catch (final JpaSystemException ex) {
        if (ex.getCause() instanceof PersistenceException) {
            LOGGER.error("Remove organisation failure JpaSystemException", ex);
            throw new FunctionalException(FunctionalExceptionType.UNKNOWN_ORGANISATION, ComponentType.WS_ADMIN, new UnknownEntityException(Organisation.class, organisationToRemoveIdentification, ex));
        }
    }
}
Also used : JpaSystemException(org.springframework.orm.jpa.JpaSystemException) ValidationException(org.opensmartgridplatform.domain.core.exceptions.ValidationException) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) UnknownEntityException(org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException) PersistenceException(javax.persistence.PersistenceException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)

Aggregations

DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)25 Device (org.opensmartgridplatform.domain.core.entities.Device)17 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)15 Transactional (org.springframework.transaction.annotation.Transactional)9 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)7 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)5 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)5 Then (io.cucumber.java.en.Then)4 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)4 NotAuthorizedException (org.opensmartgridplatform.domain.core.exceptions.NotAuthorizedException)4 DeviceFunctionGroup (org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup)4 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)3 Given (io.cucumber.java.en.Given)2 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 PersistenceException (javax.persistence.PersistenceException)1