use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method addManufacturer.
/**
* Adds new Manufacturer to the platform. Throws exception if {@link Manufacturer} already exists
*/
@Transactional(value = "writableTransactionManager")
public void addManufacturer(@Identification final String organisationIdentification, @Valid final Manufacturer manufacturer) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.CREATE_MANUFACTURER);
final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer.getCode());
if (databaseManufacturer != null) {
LOGGER.info("Manufacturer already exists.");
throw new FunctionalException(FunctionalExceptionType.EXISTING_MANUFACTURER, ComponentType.WS_CORE, new ExistingEntityException(Manufacturer.class, manufacturer.getCode()));
} else {
this.manufacturerRepository.save(manufacturer);
}
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method changeDeviceModel.
/**
* Updates a DeviceModel to the platform. Throws exception if {@link DeviceModel} doesn't exist.
*/
@Transactional(value = "writableTransactionManager")
public void changeDeviceModel(@Identification final String organisationIdentification, final String manufacturer, final String modelCode, final String description) throws FunctionalException {
final Organisation organisation = this.domainHelperService.findOrganisation(organisationIdentification);
this.domainHelperService.isAllowed(organisation, PlatformFunction.CHANGE_DEVICE_MODEL);
final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer);
final DeviceModel changedDeviceModel = this.deviceModelRepository.findByManufacturerAndModelCode(databaseManufacturer, modelCode);
if (changedDeviceModel == null) {
LOGGER.info("DeviceModel not found.");
throw new FunctionalException(FunctionalExceptionType.UNKNOWN_DEVICEMODEL, ComponentType.WS_CORE, new ExistingEntityException(Manufacturer.class, modelCode));
} else {
changedDeviceModel.setDescription(description);
this.deviceModelRepository.save(changedDeviceModel);
}
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class FirmwareManagementEndpoint method findAllManufacturers.
// === MANUFACTURERS LOGIC ===
@PayloadRoot(localPart = "FindAllManufacturersRequest", namespace = NAMESPACE)
@ResponsePayload
public FindAllManufacturersResponse findAllManufacturers(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindAllManufacturersRequest request) throws OsgpException {
LOGGER.info("Find all Manufacturers for organisation: {}.", organisationIdentification);
final FindAllManufacturersResponse response = new FindAllManufacturersResponse();
try {
final List<Manufacturer> manufacturers = this.firmwareManagementService.findAllManufacturers(organisationIdentification);
response.getManufacturers().addAll(this.firmwareManagementMapper.mapAsList(manufacturers, org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.Manufacturer.class));
} catch (final ConstraintViolationException e) {
LOGGER.error("Exception finding all manufacturers", e);
this.handleException(e);
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method findAllFirmwareFiles.
private List<FirmwareFile> findAllFirmwareFiles(final String manufacturer, final String modelCode) {
List<FirmwareFile> firmwareFiles = new ArrayList<>();
if (manufacturer != null) {
final Manufacturer databaseManufacturer = this.manufacturerRepository.findByCode(manufacturer);
final DeviceModel databaseDeviceModel = this.deviceModelRepository.findByManufacturerAndModelCode(databaseManufacturer, modelCode);
if (databaseDeviceModel != null) {
firmwareFiles = this.firmwareFileRepository.findByDeviceModel(databaseDeviceModel);
}
} else {
final List<DeviceModel> deviceModels = this.deviceModelRepository.findByModelCode(modelCode);
for (final DeviceModel deviceModel : deviceModels) {
firmwareFiles.addAll(this.firmwareFileRepository.findByDeviceModel(deviceModel));
}
}
return firmwareFiles;
}
use of org.opensmartgridplatform.domain.core.entities.Manufacturer in project open-smart-grid-platform by OSGP.
the class ManufacturerSteps method theEntityManufacturerExists.
/**
* Verify whether the entity is created as expected.
*
* @throws Throwable
*/
@Then("^the entity manufacturer exists$")
public void theEntityManufacturerExists(final Map<String, String> settings) throws Throwable {
final Manufacturer manufacturer = this.manufacturerRepository.findByCode(getString(settings, PlatformKeys.MANUFACTURER_CODE, PlatformDefaults.DEFAULT_MANUFACTURER_CODE));
assertThat(manufacturer.getName()).isEqualTo(getString(settings, PlatformKeys.MANUFACTURER_NAME, PlatformDefaults.DEFAULT_MANUFACTURER_NAME));
assertThat(manufacturer.isUsePrefix()).isEqualTo(getBoolean(settings, PlatformKeys.MANUFACTURER_USE_PREFIX, PlatformDefaults.DEFAULT_MANUFACTURER_USE_PREFIX));
}
Aggregations