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