Search in sources :

Example 1 with DeviceAuthorization

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

the class DlmsDeviceSteps method createDeviceAuthorisationInCoreDatabase.

private void createDeviceAuthorisationInCoreDatabase(final Device device) {
    final Organisation organisation = this.organisationRepo.findByOrganisationIdentification(org.opensmartgridplatform.cucumber.platform.PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
    final DeviceAuthorization deviceAuthorization = device.addAuthorization(organisation, DeviceFunctionGroup.OWNER);
    this.deviceAuthorizationRepository.save(deviceAuthorization);
    this.deviceRepository.save(device);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)

Example 2 with DeviceAuthorization

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

the class DeviceAuthorizationSteps method entityDeviceHasAuthorization.

/**
 * Checks if the expected authorization of a certain organization is in the list of stored
 * authorizations.
 */
private boolean entityDeviceHasAuthorization(final String expectedAuthorization, final String expectedOrganizationIdentification, final List<DeviceAuthorization> storedAuthorizations) {
    boolean hasExpectedAuthorization = false;
    final DeviceFunctionGroup expectedFunctionGroup = org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup.valueOf(expectedAuthorization);
    for (final DeviceAuthorization deviceAuthorization : storedAuthorizations) {
        if (expectedOrganizationIdentification.equals(deviceAuthorization.getOrganisation().getOrganisationIdentification()) && expectedFunctionGroup == deviceAuthorization.getFunctionGroup()) {
            hasExpectedAuthorization = true;
            break;
        }
    }
    return hasExpectedAuthorization;
}
Also used : DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup)

Example 3 with DeviceAuthorization

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

the class DeviceAuthorizationSteps method aDeviceAuthorization.

/**
 * Generic method which adds a device authorization using the settings.
 *
 * @param settings The settings for the device authorization to be used.
 */
@Given("^a device authorization$")
@Transactional("txMgrCore")
public void aDeviceAuthorization(final Map<String, String> settings) {
    final Device device = this.deviceRepository.findByDeviceIdentification(getString(settings, PlatformKeys.KEY_DEVICE_IDENTIFICATION, PlatformDefaults.DEFAULT_DEVICE_IDENTIFICATION));
    final Organisation organization = this.organizationRepository.findByOrganisationIdentification(getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION));
    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);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup) Given(io.cucumber.java.en.Given) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DeviceAuthorization

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

the class DeviceAuthorizationSteps method thenTheEntityDeviceAuthorizationsExist.

/**
 * The test passes if all the device authorizations are created as expected in the database.
 *
 * @param expectedEntity The expected settings.
 */
@Then("^the entity device authorizations exist$")
public void thenTheEntityDeviceAuthorizationsExist(final Map<String, String> expectedEntity) {
    final String authorizationsStringList = expectedEntity.get(PlatformKeys.KEY_DEVICE_FUNCTION_GROUP);
    final String[] authorizations = StringUtils.split(authorizationsStringList, ',');
    final Device device = this.deviceRepository.findByDeviceIdentification(expectedEntity.get(PlatformKeys.KEY_DEVICE_IDENTIFICATION));
    Wait.until(() -> {
        final List<String> storedDeviceAuthorizations = this.deviceAuthorizationRepository.findByDevice(device).stream().map(da -> da.getFunctionGroup().name()).collect(Collectors.toList());
        assertThat(storedDeviceAuthorizations).contains(authorizations);
    });
    final List<DeviceAuthorization> storedDeviceAuthorizations = this.deviceAuthorizationRepository.findByDevice(device);
    final String organizationIdentification = getString(expectedEntity, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
    for (final String authorization : authorizations) {
        assertThat(this.entityDeviceHasAuthorization(authorization, organizationIdentification, storedDeviceAuthorizations)).isTrue();
    }
}
Also used : DeviceAuthorizationRepository(org.opensmartgridplatform.domain.core.repositories.DeviceAuthorizationRepository) Then(io.cucumber.java.en.Then) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceRepository(org.opensmartgridplatform.domain.core.repositories.DeviceRepository) ReadSettingsHelper.getEnum(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getEnum) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) List(java.util.List) Device(org.opensmartgridplatform.domain.core.entities.Device) OrganisationRepository(org.opensmartgridplatform.domain.core.repositories.OrganisationRepository) Given(io.cucumber.java.en.Given) PlatformKeys(org.opensmartgridplatform.cucumber.platform.PlatformKeys) Map(java.util.Map) Wait(org.opensmartgridplatform.cucumber.core.Wait) PlatformDefaults(org.opensmartgridplatform.cucumber.platform.PlatformDefaults) DeviceFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Transactional(org.springframework.transaction.annotation.Transactional) Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Then(io.cucumber.java.en.Then)

Example 5 with DeviceAuthorization

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

the class DeviceAuthorizationSteps method thenTheEntityDeviceAuthorizationDoesNotExist.

/**
 * The test passes if the device authorizations are NOT created as expected in the database.
 *
 * @param expectedEntity The expected settings.
 */
@Then("^the entity device authorization does not exist$")
public void thenTheEntityDeviceAuthorizationDoesNotExist(final Map<String, String> expectedEntity) {
    final String expectedAuthorization = expectedEntity.get(PlatformKeys.KEY_DEVICE_FUNCTION_GROUP);
    final Device device = this.deviceRepository.findByDeviceIdentification(expectedEntity.get(PlatformKeys.KEY_DEVICE_IDENTIFICATION));
    Wait.until(() -> {
        final List<DeviceAuthorization> storedDeviceAuthorizations = this.deviceAuthorizationRepository.findByDevice(device);
        final String organizationIdentification = getString(expectedEntity, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
        assertThat(this.entityDeviceHasAuthorization(expectedAuthorization, organizationIdentification, storedDeviceAuthorizations)).isFalse();
    });
}
Also used : Device(org.opensmartgridplatform.domain.core.entities.Device) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) Then(io.cucumber.java.en.Then)

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