Search in sources :

Example 6 with Manufacturer

use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.

the class FirmwareManagementServiceTest method setUp.

@BeforeEach
void setUp() {
    // VERSION 1 and VERSION 2 have already been installed previously (in
    // that same order)
    final Manufacturer manufacturer = new Manufacturer("code", "name", false);
    final DeviceModel deviceModel = new DeviceModel(manufacturer, "modelCode", "description", false);
    final Device device = this.createDevice(deviceModel);
    when(this.deviceRepository.findByDeviceIdentification(anyString())).thenReturn(device);
    final DeviceFirmwareFile deviceFirmwareFile1 = new DeviceFirmwareFile(device, this.createFirmwareFile(VERSION_1), DateUtils.addDays(new Date(), -2), "me");
    final DeviceFirmwareFile deviceFirmwareFile2 = new DeviceFirmwareFile(device, this.createFirmwareFile(VERSION_2), DateUtils.addDays(new Date(), -1), "me");
    final List<DeviceFirmwareFile> deviceFirmwareFiles = Arrays.asList(deviceFirmwareFile1, deviceFirmwareFile2);
    when(this.deviceFirmwareFileRepository.findByDeviceOrderByInstallationDateAsc(any(Device.class))).thenReturn(deviceFirmwareFiles);
    when(this.deviceFirmwareFileRepository.save(any(DeviceFirmwareFile.class))).thenReturn(deviceFirmwareFile1);
    when(this.manufacturerRepository.findByCode(anyString())).thenReturn(manufacturer);
    when(this.deviceModelRepository.findByManufacturerAndModelCode(any(Manufacturer.class), anyString())).thenReturn(deviceModel);
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) Device(org.opensmartgridplatform.domain.core.entities.Device) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with Manufacturer

use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.

the class SmartMeterServiceTest method testStoreMeter.

@Test
void testStoreMeter() throws FunctionalException {
    final String organisationIdentification = "org-1";
    final SmartMeteringDevice smartMeteringDevice = new SmartMeteringDevice();
    final DeviceModel deviceModel = new DeviceModel();
    final AddSmartMeterRequest addSmartMeterRequest = new AddSmartMeterRequest(smartMeteringDevice, deviceModel);
    final SmartMeter smartMeter = new SmartMeter();
    final Manufacturer manufacturer = new Manufacturer();
    final ProtocolInfo protocolInfo = mock(ProtocolInfo.class);
    when(this.protocolInfoRepository.findByProtocolAndProtocolVersion(any(), any())).thenReturn(protocolInfo);
    when(this.manufacturerRepository.findByCode(any())).thenReturn(manufacturer);
    when(this.deviceModelRepository.findByManufacturerAndModelCode(any(), any())).thenReturn(new org.opensmartgridplatform.domain.core.entities.DeviceModel());
    when(this.smartMeterRepository.save(any())).thenReturn(smartMeter);
    this.smartMeterService.storeMeter(organisationIdentification, addSmartMeterRequest, smartMeter);
    verify(this.protocolInfoRepository).findByProtocolAndProtocolVersion(any(), any());
    verify(this.manufacturerRepository).findByCode(any());
    verify(this.deviceModelRepository).findByManufacturerAndModelCode(any(), any());
    verify(this.deviceAuthorizationRepository).save(any());
    verify(this.organisationRepository).findByOrganisationIdentification(organisationIdentification);
    verify(this.smartMeterRepository).save(any());
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.valueobjects.DeviceModel) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) ProtocolInfo(org.opensmartgridplatform.domain.core.entities.ProtocolInfo) SmartMeteringDevice(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.SmartMeteringDevice) AddSmartMeterRequest(org.opensmartgridplatform.domain.core.valueobjects.smartmetering.AddSmartMeterRequest) SmartMeter(org.opensmartgridplatform.domain.core.entities.SmartMeter) Test(org.junit.jupiter.api.Test)

Example 8 with Manufacturer

use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.

the class EventRetrievalScheduledTask method run.

@Override
public void run() {
    try {
        final Manufacturer manufacturer = this.findManufacturer(this.eventRetrievalScheduledTaskManufacturerName);
        if (manufacturer == null) {
            return;
        }
        final List<DeviceModel> deviceModels = this.findDeviceModels(manufacturer);
        if (deviceModels == null || deviceModels.isEmpty()) {
            return;
        }
        final List<Device> devices = this.findDevices(deviceModels, Ssld.SSLD_TYPE);
        if (devices.isEmpty()) {
            return;
        }
        List<Device> devicesToContact = this.findDevicesToContact(devices, this.eventRetrievalScheduledTaskMaximumAllowedAge);
        if (devicesToContact == null || devicesToContact.isEmpty()) {
            return;
        }
        devicesToContact = this.filterByExponentialBackOff(devicesToContact);
        this.contactDevices(devicesToContact, DeviceFunction.GET_LIGHT_STATUS);
    } catch (final Exception e) {
        LOGGER.error("Exception caught during EventRetrievalScheduledTask.run()", e);
    }
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) Device(org.opensmartgridplatform.domain.core.entities.Device) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer)

Example 9 with Manufacturer

use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.

the class DeviceManagementService method doFilterOnManufacturer.

private Specification<Device> doFilterOnManufacturer(final DeviceFilter deviceFilter, Specification<Device> specification) throws ArgumentNullOrEmptyException {
    if (!StringUtils.isEmpty(deviceFilter.getManufacturer())) {
        final Manufacturer manufacturer = this.firmwareManagementService.findManufacturer(deviceFilter.getManufacturer());
        specification = specification.and(this.deviceSpecifications.forManufacturer(manufacturer));
    }
    return specification;
}
Also used : Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer)

Example 10 with Manufacturer

use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.

the class FirmwareManagementService method changeManufacturer.

/**
 * Updates a Manufacturer to the platform. Throws exception if {@link Manufacturer} doesn't exist.
 */
@Transactional(value = "writableTransactionManager")
public void changeManufacturer(@Identification final String organisationIdentification, @Valid final Manufacturer manufacturer) throws FunctionalException {
    final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
    this.domainHelperService.isAllowed(organisation, PlatformFunction.CHANGE_MANUFACTURER);
    final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer.getCode());
    if (databaseManufacturer == null) {
        LOGGER.info("Manufacturer not found.");
        throw new FunctionalException(FunctionalExceptionType.UNKNOWN_MANUFACTURER, ComponentType.WS_CORE, new ExistingEntityException(Manufacturer.class, manufacturer.getCode()));
    } else {
        databaseManufacturer.setCode(manufacturer.getCode());
        databaseManufacturer.setName(manufacturer.getName());
        databaseManufacturer.setUsePrefix(manufacturer.isUsePrefix());
        this.manufacturerRepository.save(databaseManufacturer);
    }
}
Also used : Organisation(org.opensmartgridplatform.domain.core.entities.Organisation) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ExistingEntityException(org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Manufacturer (org.opensmartgridplatform.domain.core.entities.Manufacturer)30 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)18 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)13 Organisation (org.opensmartgridplatform.domain.core.entities.Organisation)10 Transactional (org.springframework.transaction.annotation.Transactional)10 DeviceFirmwareFile (org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile)7 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)6 ExistingEntityException (org.opensmartgridplatform.domain.core.exceptions.ExistingEntityException)6 Device (org.opensmartgridplatform.domain.core.entities.Device)5 Then (io.cucumber.java.en.Then)4 ArrayList (java.util.ArrayList)3 ConstraintViolationException (javax.validation.ConstraintViolationException)3 UnknownEntityException (org.opensmartgridplatform.domain.core.exceptions.UnknownEntityException)3 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)3 PayloadRoot (org.springframework.ws.server.endpoint.annotation.PayloadRoot)3 ResponsePayload (org.springframework.ws.server.endpoint.annotation.ResponsePayload)3 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)2 FirmwareModule (org.opensmartgridplatform.domain.core.entities.FirmwareModule)2 Given (io.cucumber.java.en.Given)1 Date (java.util.Date)1