use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class FirmwareManagementService method updateFirmware.
// === UPDATE FIRMWARE ===
public void updateFirmware(final CorrelationIds ids, final FirmwareUpdateMessageDataContainer firmwareUpdateMessageDataContainer, final Long scheduleTime, final String messageType, final int messagePriority) throws FunctionalException {
LOGGER.debug("Update firmware called with organisation [{}], device [{}], firmwareIdentification [{}].", ids.getOrganisationIdentification(), ids.getDeviceIdentification(), firmwareUpdateMessageDataContainer.getFirmwareUrl());
this.findOrganisation(ids.getOrganisationIdentification());
final Device device = this.findActiveDevice(ids.getDeviceIdentification());
if (device instanceof Ssld) {
this.createSsldPendingFirmwareUpdateRecord(ids, firmwareUpdateMessageDataContainer.getFirmwareUrl());
}
this.osgpCoreRequestMessageSender.sendWithScheduledTime(new RequestMessage(ids, this.domainCoreMapper.map(firmwareUpdateMessageDataContainer, org.opensmartgridplatform.dto.valueobjects.FirmwareUpdateMessageDataContainer.class)), messageType, messagePriority, device.getIpAddress(), scheduleTime);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method handleUpdateKeyResponse.
public void handleUpdateKeyResponse(final String deviceIdentification, final String organisationIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType deviceResult, final OsgpException exception) {
LOGGER.info("MessageType: {}. Handle update key response for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = exception;
try {
if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
Ssld device = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
if (device == null) {
// Device not found, create new device
LOGGER.debug("Device [{}] does not exist, creating new device", deviceIdentification);
device = new Ssld(deviceIdentification);
}
device.setPublicKeyPresent(true);
this.ssldRepository.save(device);
LOGGER.info("publicKey has been set for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
} catch (final Exception e) {
LOGGER.error("Unexpected Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while updating key", e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(osgpException).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method handleRevokeKeyResponse.
public void handleRevokeKeyResponse(final String organisationIdentification, final String deviceIdentification, final String correlationUid, final String messageType, final ResponseMessageResultType deviceResult, final OsgpException exception) {
LOGGER.info("MessageType: {}. Handle revoke key for device: {} for organisation: {}", messageType, deviceIdentification, organisationIdentification);
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = exception;
try {
if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
final Device device = this.deviceRepository.findByDeviceIdentification(deviceIdentification);
if (device == null) {
throw new PlatformException(String.format("Device not found: %s", deviceIdentification));
}
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(deviceIdentification);
ssld.setPublicKeyPresent(false);
this.ssldRepository.save(ssld);
LOGGER.info("publicKey has been revoked for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
} catch (final Exception e) {
LOGGER.error("Unexpected Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while revoking key", e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withCorrelationUid(correlationUid).withOrganisationIdentification(organisationIdentification).withDeviceIdentification(deviceIdentification).withResult(result).withOsgpException(osgpException).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class PublicLightingAdHocManagementEndpoint method findAllDevices.
@PayloadRoot(localPart = "FindAllDevicesRequest", namespace = NAMESPACE)
@ResponsePayload
public FindAllDevicesResponse findAllDevices(@OrganisationIdentification final String organisationIdentification, @RequestPayload final FindAllDevicesRequest request) throws OsgpException {
LOGGER.info("Finding All Devices Request received from organisation: {}.", organisationIdentification);
final FindAllDevicesResponse response = new FindAllDevicesResponse();
try {
final PageSpecifier pageSpecifier = new PageSpecifier(request.getPageSize(), request.getPage());
final Page<Device> page = this.adHocManagementService.findAllDevices(organisationIdentification, pageSpecifier);
if (page != null && !page.isEmpty()) {
final List<Ssld> sslds = listOfType(page, Ssld.class);
final List<LightMeasurementDevice> lmds = listOfType(page, LightMeasurementDevice.class);
final DevicePage devicePage = new DevicePage();
devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
devicePage.getPage().setPageSize(page.getSize());
devicePage.getPage().setTotalPages(page.getTotalPages());
devicePage.getPage().setCurrentPage(page.getNumber());
devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(sslds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.Ssld.class));
devicePage.getDevices().addAll(this.adHocManagementMapper.mapAsList(lmds, org.opensmartgridplatform.adapter.ws.schema.publiclighting.adhocmanagement.LightMeasurementDevice.class));
response.setDevicePage(devicePage);
} else {
final DevicePage devicePage = new DevicePage();
devicePage.setPage(new org.opensmartgridplatform.adapter.ws.schema.publiclighting.common.Page());
devicePage.getPage().setCurrentPage(0);
devicePage.getPage().setPageSize(request.getPageSize() == null ? 0 : request.getPageSize());
devicePage.getPage().setTotalPages(0);
response.setDevicePage(devicePage);
}
} catch (final ConstraintViolationException e) {
LOGGER.error(EXCEPTION_OCCURRED, e);
throw new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR, COMPONENT_WS_PUBLIC_LIGHTING, new ValidationException(e.getConstraintViolations()));
} catch (final Exception e) {
this.handleException(e);
}
return response;
}
use of org.opensmartgridplatform.domain.core.entities.Ssld in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementService method handleGetConfigurationResponse.
public void handleGetConfigurationResponse(final ConfigurationDto configurationDto, final CorrelationIds ids, final String messageType, final int messagePriority, final ResponseMessageResultType deviceResult, final OsgpException exception) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = exception;
Configuration configuration = null;
try {
if (deviceResult == ResponseMessageResultType.NOT_OK || osgpException != null) {
LOGGER.error("Device Response not ok.", osgpException);
throw osgpException;
}
final Ssld ssld = this.ssldRepository.findByDeviceIdentification(ids.getDeviceIdentification());
final List<DeviceOutputSetting> outputSettings = ssld.getOutputSettings();
this.replaceEmptyOutputSettings(configurationDto, outputSettings);
configuration = this.domainCoreMapper.map(configurationDto, Configuration.class);
// TARIFF_REVERSED will be changed to the correct RelayType.
for (final DeviceOutputSetting dos : outputSettings) {
if (dos.getOutputType().equals(RelayType.TARIFF_REVERSED)) {
for (final RelayMap rm : configuration.getRelayConfiguration().getRelayMap()) {
if (rm.getIndex() == dos.getExternalId() && rm.getRelayType().equals(RelayType.TARIFF)) {
rm.changeRelayType(RelayType.TARIFF_REVERSED);
}
}
}
}
} catch (final Exception e) {
LOGGER.error("Unexpected Exception for messageType: {}", messageType, e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, e.getMessage(), e);
}
final ResponseMessage responseMessage = ResponseMessage.newResponseMessageBuilder().withIds(ids).withResult(result).withOsgpException(osgpException).withDataObject(configuration).withMessagePriority(messagePriority).withMessageType(MessageType.GET_CONFIGURATION.name()).build();
this.webServiceResponseMessageSender.send(responseMessage);
}
Aggregations