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;
}
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);
}
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;
}
Aggregations