Search in sources :

Example 1 with DeviceFunctionGroup

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup 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 2 with DeviceFunctionGroup

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup 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 3 with DeviceFunctionGroup

use of org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup 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)

Aggregations

DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)3 DeviceFunctionGroup (org.opensmartgridplatform.domain.core.valueobjects.DeviceFunctionGroup)3 Device (org.opensmartgridplatform.domain.core.entities.Device)2 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)2 Given (io.cucumber.java.en.Given)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 Transactional (org.springframework.transaction.annotation.Transactional)1