Search in sources :

Example 1 with Organisation

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);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) DeviceAuthorization(org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)

Example 2 with Organisation

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);
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) PlatformFunctionGroup(org.opensmartgridplatform.domain.core.valueobjects.PlatformFunctionGroup) ReadSettingsHelper.getString(org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString) PlatformDomain(org.opensmartgridplatform.domain.core.valueobjects.PlatformDomain) Given(io.cucumber.java.en.Given)

Example 3 with Organisation

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

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);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Organisation

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;
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Device(org.opensmartgridplatform.domain.core.entities.Device) Builder(org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder) PublicLightingRequestMessage(org.opensmartgridplatform.adapter.ws.publiclighting.infra.jms.PublicLightingRequestMessage)

Aggregations

Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)97 Device (org.opensmartgridplatform.domain.core.entities.Device)47 Transactional (org.springframework.transaction.annotation.Transactional)28 MessageMetadata (org.opensmartgridplatform.shared.infra.jms.MessageMetadata)23 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)22 CommonRequestMessage (org.opensmartgridplatform.adapter.ws.core.infra.jms.CommonRequestMessage)15 DeviceAuthorization (org.opensmartgridplatform.domain.core.entities.DeviceAuthorization)14 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)10 Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)10 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)10 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)7 PublicLightingRequestMessage (org.opensmartgridplatform.adapter.ws.publiclighting.infra.jms.PublicLightingRequestMessage)6 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)6 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)6 PageRequest (org.springframework.data.domain.PageRequest)6 Test (org.junit.jupiter.api.Test)5 LightMeasurementDevice (org.opensmartgridplatform.domain.core.entities.LightMeasurementDevice)5 Ssld (org.opensmartgridplatform.domain.core.entities.Ssld)5 Builder (org.opensmartgridplatform.shared.infra.jms.MessageMetadata.Builder)5 PersistenceException (javax.persistence.PersistenceException)4