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