use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class OslpDeviceSteps method theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform.
@Given("^the device sends a confirm register device request to the platform over \"([^\"]*)\"$")
public void theDeviceSendsAConfirmRegisterDeviceRequestToThePlatform(final String protocol, final Map<String, String> settings) throws DeviceSimulatorException {
try {
final String deviceIdentification = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_IDENTIFICATION, PlatformPubliclightingDefaults.DEFAULT_DEVICE_IDENTIFICATION);
final String deviceUid = getString(settings, PlatformPubliclightingKeys.KEY_DEVICE_UID, PlatformPubliclightingDefaults.DEVICE_UID);
final OslpDevice oslpDevice = this.oslpDeviceRepository.findByDeviceIdentification(deviceIdentification);
final int randomDevice = oslpDevice.getRandomDevice();
final int randomPlatform = oslpDevice.getRandomPlatform();
final Oslp.ConfirmRegisterDeviceRequest confirmRegisterDeviceRequest = Oslp.ConfirmRegisterDeviceRequest.newBuilder().setRandomDevice(randomDevice).setRandomPlatform(randomPlatform).build();
final Message message = Message.newBuilder().setConfirmRegisterDeviceRequest(confirmRegisterDeviceRequest).build();
this.oslpMockServer.incrementSequenceNumber(this.getDeviceUid(settings));
final OslpEnvelope request = this.createEnvelopeBuilder(deviceUid, this.oslpMockServer.getSequenceNumber(this.getDeviceUid(settings))).withPayloadMessage(message).build();
this.send(request, settings);
} catch (final IOException | IllegalArgumentException e) {
ScenarioContext.current().put("Error", e);
}
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class DeviceManagementService method revokeKey.
// === REVOKE KEY ===
public void revokeKey(final MessageMetadata messageMetadata, final DeviceResponseMessageSender responseMessageSender) {
final String deviceIdentification = messageMetadata.getDeviceIdentification();
final String organisationIdentification = messageMetadata.getOrganisationIdentification();
LOGGER.info("revokeKey called for device: {} for organisation: {}", deviceIdentification, organisationIdentification);
try {
final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
if (oslpDevice == null) {
throw new ProtocolAdapterException(String.format("Device not found: %s", deviceIdentification));
}
oslpDevice.revokePublicKey();
this.oslpDeviceSettingsService.updateDevice(oslpDevice);
this.sendResponseMessage(messageMetadata, ResponseMessageResultType.OK, null, responseMessageSender);
} catch (final Exception e) {
LOGGER.error("Unexpected exception during revokeKey", e);
final TechnicalException ex = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while revoking key", e);
this.sendResponseMessage(messageMetadata, ResponseMessageResultType.NOT_OK, ex, responseMessageSender);
}
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class LoggingService method getDeviceIdentification.
private String getDeviceIdentification(final String deviceUid) {
String deviceIdentification = EMPTY;
final OslpDevice oslpDevice = this.oslpDeviceRepository.findByDeviceUid(deviceUid);
if (oslpDevice != null) {
deviceIdentification = oslpDevice.getDeviceIdentification();
}
return deviceIdentification;
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class PublicLightingSetScheduleRequestMessageProcessor method handleSetScheduleSetRebootResponse.
private void handleSetScheduleSetRebootResponse(final SetScheduleDeviceRequest deviceRequest) {
// The device will reboot now.
// At this point we will need to save the current state to the
// pending_set_schedule_request table
LOGGER.info(LOG_MESSAGE_CALL_DEVICE_SERVICE, deviceRequest.getMessageType(), ScheduleMessageTypeDto.SET_SCHEDULE, deviceRequest.getDomain(), deviceRequest.getDomainVersion());
final ScheduleMessageDataContainerDto dataContainer = new ScheduleMessageDataContainerDto.Builder(deviceRequest.getScheduleMessageDataContainer().getSchedule()).withScheduleMessageType(ScheduleMessageTypeDto.SET_SCHEDULE).build();
final String deviceIdentification = deviceRequest.getDeviceIdentification();
final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceIdentification);
final String deviceUid = oslpDevice.getDeviceUid();
final Date expireDateTime = Date.from(ZonedDateTime.now().plusMinutes(this.pendingSetScheduleRequestExpiresInMinutes).toInstant());
final PendingSetScheduleRequest pendingSetScheduleRequest = PendingSetScheduleRequest.builder().deviceIdentification(deviceIdentification).deviceUid(deviceUid).scheduleMessageDataContainerDto(dataContainer).deviceRequest(deviceRequest).expiredAt(expireDateTime).build();
this.pendingSetScheduleRequestService.add(pendingSetScheduleRequest);
}
use of org.opensmartgridplatform.adapter.protocol.oslp.elster.domain.entities.OslpDevice in project open-smart-grid-platform by OSGP.
the class OslpDeviceService method saveOslpResponseLogEntry.
private void saveOslpResponseLogEntry(final DeviceRequest deviceRequest, final OslpEnvelope oslpResponse) {
final OslpDevice oslpDevice = this.oslpDeviceSettingsService.getDeviceByDeviceIdentification(deviceRequest.getDeviceIdentification());
final OslpLogItemRequestMessage oslpLogItemRequestMessage = new OslpLogItemRequestMessage(deviceRequest.getOrganisationIdentification(), oslpDevice.getDeviceUid(), deviceRequest.getDeviceIdentification(), true, oslpResponse.isValid(), oslpResponse.getPayloadMessage(), oslpResponse.getSize());
this.oslpLogItemRequestMessageSender.send(oslpLogItemRequestMessage);
}
Aggregations