Search in sources :

Example 6 with FirmwareModuleData

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

the class FirmwareManagementEndpoint method addOrChangeFirmware.

@PayloadRoot(localPart = "AddOrChangeFirmwareRequest", namespace = NAMESPACE)
@ResponsePayload
public AddOrChangeFirmwareResponse addOrChangeFirmware(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddOrChangeFirmwareRequest request) throws OsgpException {
    LOGGER.info("Adding Or changing firmware:{}.", request.getFirmware().getFilename());
    final AddOrChangeFirmwareResponse addOrChangeFirmwareResponse = new AddOrChangeFirmwareResponse();
    try {
        final FirmwareModuleData firmwareModuleData = this.firmwareManagementMapper.map(request.getFirmware().getFirmwareModuleData(), FirmwareModuleData.class);
        final List<org.opensmartgridplatform.domain.core.valueobjects.DeviceModel> deviceModels = new ArrayList<>();
        for (final org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.DeviceModel wsDeviceModel : request.getFirmware().getDeviceModels()) {
            final org.opensmartgridplatform.domain.core.valueobjects.DeviceModel deviceModel = this.firmwareManagementMapper.map(wsDeviceModel, org.opensmartgridplatform.domain.core.valueobjects.DeviceModel.class);
            deviceModels.add(deviceModel);
        }
        this.firmwareManagementService.addOrChangeFirmware(organisationIdentification, this.firmwareFileRequestFor(request.getFirmware()), request.getFirmware().getFile(), deviceModels, firmwareModuleData);
    } catch (final ConstraintViolationException e) {
        LOGGER.error("Exception adding or changing firmware ", e);
        this.handleException(e);
    } catch (final FunctionalException e) {
        LOGGER.error("Exception adding or changing firmware: {} ", e.getMessage(), e);
        if (FunctionalExceptionType.EXISTING_FIRMWARE == e.getExceptionType()) {
            addOrChangeFirmwareResponse.setResult(OsgpResultType.NOT_OK);
            addOrChangeFirmwareResponse.setDescription(ADD_FIRMWARE_EXISTING_FIRMWARE);
            return addOrChangeFirmwareResponse;
        }
        this.handleException(e);
    } catch (final Exception e) {
        LOGGER.error("Exception: {} while adding or changing firmware: {} for organisation {}", e.getMessage(), request.getFirmware().getFilename(), organisationIdentification, e);
        this.handleException(e);
    }
    addOrChangeFirmwareResponse.setResult(OsgpResultType.OK);
    return addOrChangeFirmwareResponse;
}
Also used : DeviceModel(org.opensmartgridplatform.domain.core.entities.DeviceModel) FirmwareModuleData(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleData) ArrayList(java.util.ArrayList) AddOrChangeFirmwareResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.AddOrChangeFirmwareResponse) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 7 with FirmwareModuleData

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

the class FirmwareManagementEndpoint method changeFirmware.

@PayloadRoot(localPart = "ChangeFirmwareRequest", namespace = NAMESPACE)
@ResponsePayload
public ChangeFirmwareResponse changeFirmware(@OrganisationIdentification final String organisationIdentification, @RequestPayload final ChangeFirmwareRequest request) throws OsgpException {
    LOGGER.info("Changing firmware:{}.", request.getFirmware().getFilename());
    final FirmwareModuleData firmwareModuleData = this.firmwareManagementMapper.map(request.getFirmware().getFirmwareModuleData(), FirmwareModuleData.class);
    // The ChangeFirmwareRequest accepts multiple DeviceModels to be related to a Firmware.
    // This FirmwareManagementService only accepts ONE for now
    final String manufacturer = this.getManufacturerFromFirmware(request.getFirmware());
    final String modelCode = this.getModelCodeFromFirmware(request.getFirmware());
    try {
        this.firmwareManagementService.changeFirmware(organisationIdentification, request.getId(), this.firmwareFileRequestFor(request.getFirmware()), manufacturer, modelCode, firmwareModuleData);
    } catch (final ConstraintViolationException e) {
        LOGGER.error("Exception Changing firmware", e);
        this.handleException(e);
    } catch (final Exception e) {
        LOGGER.error("Exception: {} while Changing firmware: {} for organisation {}", e.getMessage(), request.getFirmware().getFilename(), organisationIdentification, e);
        this.handleException(e);
    }
    final ChangeFirmwareResponse changeFirmwareResponse = new ChangeFirmwareResponse();
    changeFirmwareResponse.setResult(OsgpResultType.OK);
    return changeFirmwareResponse;
}
Also used : FirmwareModuleData(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleData) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) OsgpException(org.opensmartgridplatform.shared.exceptionhandling.OsgpException) ConstraintViolationException(javax.validation.ConstraintViolationException) ChangeFirmwareResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.ChangeFirmwareResponse) AddOrChangeFirmwareResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.AddOrChangeFirmwareResponse) ResponsePayload(org.springframework.ws.server.endpoint.annotation.ResponsePayload) PayloadRoot(org.springframework.ws.server.endpoint.annotation.PayloadRoot)

Example 8 with FirmwareModuleData

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

the class FirmwareManagementEndpoint method addFirmware.

@PayloadRoot(localPart = "AddFirmwareRequest", namespace = NAMESPACE)
@ResponsePayload
public AddFirmwareResponse addFirmware(@OrganisationIdentification final String organisationIdentification, @RequestPayload final AddFirmwareRequest request) throws OsgpException {
    LOGGER.info("Adding firmware:{}.", request.getFirmware().getFilename());
    final AddFirmwareResponse addFirmwareResponse = new AddFirmwareResponse();
    try {
        final FirmwareModuleData firmwareModuleData = this.firmwareManagementMapper.map(request.getFirmware().getFirmwareModuleData(), FirmwareModuleData.class);
        // The AddFirmwareRequest accepts multiple DeviceModels to be related to a Firmware.
        // This FirmwareManagementService only accepts ONE for now
        final String manufacturer = this.getManufacturerFromFirmware(request.getFirmware());
        final String modelCode = this.getModelCodeFromFirmware(request.getFirmware());
        this.firmwareManagementService.addFirmware(organisationIdentification, this.firmwareFileRequestFor(request.getFirmware()), request.getFirmware().getFile(), manufacturer, modelCode, firmwareModuleData);
    } catch (final ConstraintViolationException e) {
        LOGGER.error("Exception adding firmware ", e);
        this.handleException(e);
    } catch (final FunctionalException e) {
        LOGGER.error("Exception adding firmware: {} ", e.getMessage(), e);
        if (FunctionalExceptionType.EXISTING_FIRMWARE == e.getExceptionType()) {
            addFirmwareResponse.setResult(OsgpResultType.NOT_OK);
            addFirmwareResponse.setDescription(ADD_FIRMWARE_EXISTING_FIRMWARE);
            return addFirmwareResponse;
        }
        this.handleException(e);
    } catch (final Exception e) {
        LOGGER.error("Exception: {} while adding firmware: {} for organisation {}", e.getMessage(), request.getFirmware().getFilename(), organisationIdentification, e);
        this.handleException(e);
    }
    addFirmwareResponse.setResult(OsgpResultType.OK);
    return addFirmwareResponse;
}
Also used : FirmwareModuleData(org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleData) AddFirmwareResponse(org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.AddFirmwareResponse) ConstraintViolationException(javax.validation.ConstraintViolationException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) 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)

Aggregations

FirmwareModuleData (org.opensmartgridplatform.domain.core.valueobjects.FirmwareModuleData)8 ConstraintViolationException (javax.validation.ConstraintViolationException)3 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)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 AddOrChangeFirmwareResponse (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.AddOrChangeFirmwareResponse)2 FirmwareUpdateMessageDataContainer (org.opensmartgridplatform.domain.core.valueobjects.FirmwareUpdateMessageDataContainer)2 Serializable (java.io.Serializable)1 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 AddFirmwareResponse (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.AddFirmwareResponse)1 ChangeFirmwareResponse (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.ChangeFirmwareResponse)1 FirmwareModuleDataBuilder (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.FirmwareModuleDataBuilder)1 FirmwareModuleType (org.opensmartgridplatform.adapter.ws.schema.core.firmwaremanagement.FirmwareModuleType)1 ReadSettingsHelper.getNullOrNonEmptyString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getNullOrNonEmptyString)1 ReadSettingsHelper.getString (org.opensmartgridplatform.cucumber.core.ReadSettingsHelper.getString)1 DeviceModel (org.opensmartgridplatform.domain.core.entities.DeviceModel)1 FirmwareFile (org.opensmartgridplatform.domain.core.entities.FirmwareFile)1