use of org.opensmartgridplatform.domain.core.entities.Organisation 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);
}
use of org.opensmartgridplatform.domain.core.entities.Organisation in project open-smart-grid-platform by OSGP.
the class OrganizationSteps method anOrganization.
/**
* Generic method to create an organization.
*
* @param settings The settings to use to create the organization.
* @throws Throwable
*/
@Given("^an organization$")
public void anOrganization(final Map<String, String> settings) {
final String organizationIdentification = getString(settings, PlatformKeys.KEY_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION);
Organisation entity = this.organisationRepository.findByOrganisationIdentification(organizationIdentification);
if (entity == null) {
entity = new Organisation((organizationIdentification.isEmpty()) ? PlatformDefaults.DEFAULT_NEW_ORGANIZATION_IDENTIFICATION : organizationIdentification, getString(settings, PlatformKeys.KEY_NAME, PlatformDefaults.DEFAULT_ORGANIZATION_NAME), getString(settings, PlatformKeys.KEY_PREFIX, PlatformDefaults.DEFAULT_PREFIX), getEnum(settings, PlatformKeys.KEY_PLATFORM_FUNCTION_GROUP, PlatformFunctionGroup.class, PlatformDefaults.PLATFORM_FUNCTION_GROUP));
} else {
entity.changeOrganisationData(getString(settings, PlatformKeys.KEY_NAME, PlatformDefaults.DEFAULT_ORGANIZATION_NAME), getEnum(settings, PlatformKeys.KEY_PLATFORM_FUNCTION_GROUP, PlatformFunctionGroup.class, PlatformDefaults.PLATFORM_FUNCTION_GROUP));
}
// Add all the mandatory stuff.
entity.setDomains(new ArrayList<>());
String domains = PlatformDefaults.DEFAULT_DOMAINS;
if (settings.containsKey(PlatformKeys.KEY_DOMAINS) && StringUtils.isNotBlank(settings.get(PlatformKeys.KEY_DOMAINS))) {
domains = settings.get(PlatformKeys.KEY_DOMAINS);
}
for (final String domain : domains.split(PlatformKeys.SEPARATOR_SEMICOLON)) {
entity.addDomain(Enum.valueOf(PlatformDomain.class, domain));
}
entity.setIsEnabled(getBoolean(settings, PlatformKeys.KEY_ENABLED, PlatformDefaults.DEFAULT_ORGANIZATION_ENABLED));
this.organisationRepository.save(entity);
}
use of org.opensmartgridplatform.domain.core.entities.Organisation 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.entities.Organisation in project open-smart-grid-platform by OSGP.
the class CoreDatabase method insertDefaultData.
/**
* This method is used to create default data not directly related to the specific tests. For
* example: The test-org organization which is used to send authorized requests to the platform.
*/
@Transactional("txMgrCore")
public void insertDefaultData() {
if (this.organisationRepository.findByOrganisationIdentification(PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION) == null) {
// Create test organization used within the tests.
final Organisation testOrg = new Organisation(PlatformDefaults.DEFAULT_ORGANIZATION_IDENTIFICATION, PlatformDefaults.DEFAULT_ORGANIZATION_DESCRIPTION, PlatformDefaults.DEFAULT_PREFIX, PlatformFunctionGroup.ADMIN);
testOrg.addDomain(PlatformDomain.COMMON);
testOrg.addDomain(PlatformDomain.PUBLIC_LIGHTING);
testOrg.addDomain(PlatformDomain.TARIFF_SWITCHING);
testOrg.setIsEnabled(true);
this.organisationRepository.save(testOrg);
}
// Create default test manufacturer
final Manufacturer manufacturer = new Manufacturer(PlatformDefaults.DEFAULT_MANUFACTURER_CODE, PlatformDefaults.DEFAULT_MANUFACTURER_NAME, false);
this.manufacturerRepository.save(manufacturer);
// Create the default test model
final DeviceModel deviceModel = new DeviceModel(manufacturer, PlatformDefaults.DEFAULT_DEVICE_MODEL_MODEL_CODE, PlatformDefaults.DEFAULT_DEVICE_MODEL_DESCRIPTION, true);
this.deviceModelRepository.save(deviceModel);
}
use of org.opensmartgridplatform.domain.core.entities.Organisation in project open-smart-grid-platform by OSGP.
the class AdHocManagementService method enqueueGetStatusRequest.
public String enqueueGetStatusRequest(@Identification final String organisationIdentification, @Identification final String deviceIdentification, final int messagePriority) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
final Device device = this.domainHelperService.findActiveDevice(deviceIdentification);
this.domainHelperService.isAllowed(organisation, device, DeviceFunction.GET_STATUS);
LOGGER.debug("enqueueGetStatusRequest called with organisation {} and device {}", organisationIdentification, deviceIdentification);
final String correlationUid = this.correlationIdProviderService.getCorrelationId(organisationIdentification, deviceIdentification);
final MessageMetadata deviceMessageMetadata = new MessageMetadata.Builder().withDeviceIdentification(deviceIdentification).withOrganisationIdentification(organisationIdentification).withCorrelationUid(correlationUid).withMessageType(MessageType.GET_LIGHT_STATUS.name()).withMessagePriority(messagePriority).build();
final PublicLightingRequestMessage message = new PublicLightingRequestMessage.Builder().messageMetadata(deviceMessageMetadata).build();
this.messageSender.send(message);
return correlationUid;
}
Aggregations