use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class FirmwareManagementEndpoint method addManufacturer.
@PayloadRoot(localPart = "AddManufacturerRequest", namespace = NAMESPACE)
@ResponsePayload
public AddManufacturerResponse addManufacturer(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddManufacturerRequest request) throws OsgpException {
LOGGER.info("Adding manufacturer:{}.", request.getManufacturer().getName());
final AddManufacturerResponse addManufacturerResponse = new AddManufacturerResponse();
try {
this.firmwareManagementService.addManufacturer(organisationIdentification, new Manufacturer(request.getManufacturer().getCode(), request.getManufacturer().getName(), request.getManufacturer().isUsePrefix()));
} catch (final ConstraintViolationException e) {
LOGGER.error("Exception adding manufacturer", e);
this.handleException(e);
} catch (final FunctionalException e) {
LOGGER.error("Exception adding manufacturer: {} ", e.getMessage(), e);
if (FunctionalExceptionType.EXISTING_MANUFACTURER == e.getExceptionType()) {
addManufacturerResponse.setResult(OsgpResultType.NOT_OK);
addManufacturerResponse.setDescription(ADD_MANUFACTURER_EXISTING_MANUFACTURER);
return addManufacturerResponse;
}
this.handleException(e);
} catch (final Exception e) {
LOGGER.error("Exception: {} while adding manufacturer: {} for organisation {}", e.getMessage(), request.getManufacturer().getCode(), organisationIdentification, e);
this.handleException(e);
}
addManufacturerResponse.setResult(OsgpResultType.OK);
return addManufacturerResponse;
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class DlmsDeviceSteps method getDeviceModel.
private DeviceModel getDeviceModel(final Map<String, String> inputSettings) {
final String manufacturerCode = inputSettings.get(PlatformSmartmeteringKeys.MANUFACTURER_CODE);
final String modelCode = inputSettings.get(PlatformSmartmeteringKeys.DEVICE_MODEL_CODE);
if (manufacturerCode != null && modelCode != null) {
final Manufacturer manufacturer = this.manufacturerRepository.findByCode(manufacturerCode);
return this.deviceModelRepository.findByManufacturerAndModelCode(manufacturer, modelCode);
}
return null;
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class RtuDeviceService method addDeviceModel.
private void addDeviceModel(final org.opensmartgridplatform.domain.core.valueobjects.DeviceModel deviceModel, final org.opensmartgridplatform.domain.core.entities.RtuDevice rtuDeviceEntity) throws FunctionalException {
final Manufacturer manufacturer = this.manufacturerRepository.findByCode(deviceModel.getManufacturer());
final DeviceModel deviceModelEntity = this.deviceModelRepository.findByManufacturerAndModelCode(manufacturer, deviceModel.getModelCode());
if (deviceModelEntity == null) {
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.DOMAIN_DISTRIBUTION_AUTOMATION);
}
rtuDeviceEntity.setDeviceModel(deviceModelEntity);
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method changeFirmware.
/**
* Updates a FirmwareFile to the platform. Throws exception if {@link FirmwareFile} doesn't exist.
*/
@Transactional(value = "writableTransactionManager")
public void changeFirmware(@Identification final String organisationIdentification, final int id, final FirmwareFileRequest firmwareFileRequest, final String manufacturer, final String modelCode, final FirmwareModuleData firmwareModuleData) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.CHANGE_FIRMWARE);
FirmwareFile changedFirmwareFile = this.firmwareFileRepository.findById((long) id).orElseThrow(supplyFirmwareFileNotFoundException(id, firmwareFileRequest.getFileName()));
final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer);
if (databaseManufacturer == null) {
LOGGER.info("Manufacturer {} doesn't exist.", manufacturer);
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_MANUFACTURER, ComponentType.WS_CORE, new UnknownEntityException(Manufacturer.class, manufacturer));
}
final DeviceModel databaseDeviceModel = this.deviceModelRepository.findByManufacturerAndModelCode(databaseManufacturer, modelCode);
if (databaseDeviceModel == null) {
LOGGER.info("DeviceModel unknown for manufacturer {} and model code {}.", manufacturer, modelCode);
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE, new UnknownEntityException(DeviceModel.class, modelCode));
}
changedFirmwareFile.setDescription(firmwareFileRequest.getDescription());
/*
* A firmware file has been changed to be related to (possibly) multiple
* device models to be usable across different value streams for all
* kinds of devices.
*
* This code mimics the earlier behavior with a single device model
* linked to the firmware file, where the device model is changed.
*
* If multiple device models are related, it is not clear what to do,
* and which if the device models (if any) should be removed. In such
* case the device model will be added for now.
*
* 2021-06-02: In case of multiple DeviceModels all existing must be deleted
* and all new DeviceModels in the request must be added
*/
final Set<DeviceModel> existingDeviceModels = changedFirmwareFile.getDeviceModels();
if (existingDeviceModels.size() > 1) {
LOGGER.warn("Change Firmware (FirmwareFile id={}) with {} existing DeviceModels, adding {}", changedFirmwareFile.getId(), existingDeviceModels.size(), databaseDeviceModel);
} else {
LOGGER.warn("Change Firmware (FirmwareFile id={}) with {} existing DeviceModel(s), replacing by {}", changedFirmwareFile.getId(), existingDeviceModels.size(), databaseDeviceModel);
}
existingDeviceModels.clear();
changedFirmwareFile.addDeviceModel(databaseDeviceModel);
changedFirmwareFile.setFilename(firmwareFileRequest.getFileName());
changedFirmwareFile.updateFirmwareModuleData(firmwareModuleData.getVersionsByModule(this.firmwareModuleRepository, false));
changedFirmwareFile.setPushToNewDevices(firmwareFileRequest.isPushToNewDevices());
changedFirmwareFile.setActive(firmwareFileRequest.isActive());
// Save the changed firmware entity
changedFirmwareFile = this.firmwareFileRepository.save(changedFirmwareFile);
// Set all devicefirmwares.pushToNewDevices on false
if (firmwareFileRequest.isPushToNewDevices()) {
final List<FirmwareFile> firmwareFiles = this.firmwareFileRepository.findByDeviceModel(databaseDeviceModel);
firmwareFiles.remove(changedFirmwareFile);
this.setPushToNewDevicesToFalse(firmwareFiles);
}
this.firmwareFileRepository.save(changedFirmwareFile);
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method addOrChangeFirmware.
@Transactional(value = "writableTransactionManager")
public void addOrChangeFirmware(@Identification final String organisationIdentification, final FirmwareFileRequest firmwareFileRequest, final byte[] file, final List<org.opensmartgridplatform.domain.core.valueobjects.DeviceModel> deviceModels, final FirmwareModuleData firmwareModuleData) throws OsgpException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.CREATE_FIRMWARE);
// find for each DeviceModel from the WebServcies the corresponding entities
// There should be at least one DeviceModel. If none found a FunctionalException should be
// raised
// Each DeviceModel can have it's own Manufacturer (at least a theory)
// if a Manufacturer entity related to the DeviceModel can not be found a FunctionalException
// should be raised
// if one of the DeviceModel entities can not be found a FunctionalException should be raised
final List<DeviceModel> databaseDeviceModels = new ArrayList<>();
for (final org.opensmartgridplatform.domain.core.valueobjects.DeviceModel deviceModel : deviceModels) {
final Manufacturer databaseManufacturer = this.findManufacturerByCode(deviceModel.getManufacturer());
final DeviceModel databaseDeviceModel = this.deviceModelRepository.findByManufacturerAndModelCode(databaseManufacturer, deviceModel.getModelCode());
if (databaseDeviceModel == null) {
LOGGER.info("DeviceModel doesn't exist.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE, new UnknownEntityException(DeviceModel.class, deviceModel.getModelCode()));
}
databaseDeviceModels.add(databaseDeviceModel);
}
if (!deviceModels.isEmpty() && databaseDeviceModels.isEmpty()) {
LOGGER.info("No DeviceModels found.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE);
}
final Map<FirmwareModule, String> firmwareVersionsByModule = firmwareModuleData.getVersionsByModule(this.firmwareModuleRepository, true);
final FirmwareFile firmwareFile = this.insertOrUdateDatabase(firmwareFileRequest, file);
firmwareFile.updateFirmwareDeviceModels(databaseDeviceModels);
firmwareFile.updateFirmwareModuleData(firmwareVersionsByModule);
this.firmwareFileRepository.save(firmwareFile);
}
Aggregations