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