Search in sources :

Example 11 with Manufacturer

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

Example 12 with 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);
    }
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) 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)

Example 13 with Manufacturer

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;
}
Also used : FindAllManufacturersResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.FindAllManufacturersResponse) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 14 with Manufacturer

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;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) ArrayList(java.util.ArrayList) Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) DeviceFirmwareFile(org.opensmartgridplatform.domain.core.entities.DeviceFirmwareFile) FirmwareFile(org.opensmartgridplatform.domain.core.entities.FirmwareFile)

Example 15 with Manufacturer

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));
}
Also used : Manufacturer(org.opensmartgridplatform.domain.core.entities.Manufacturer) Then(io.cucumber.java.en.Then)

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