use of com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850ClientRTUEventListener method processReport.
private void processReport(final Report report, final String reportDescription, final Iec61850ReportHandler reportHandler) throws ProtocolAdapterException {
if (report.getDataSet() == null) {
this.logger.warn("No DataSet available for {}", reportDescription);
return;
}
final List<FcModelNode> members = report.getDataSet().getMembers();
if ((members == null) || members.isEmpty()) {
this.logger.warn("No members in DataSet available for {}", reportDescription);
return;
}
final List<MeasurementDto> measurements = new ArrayList<>();
for (final FcModelNode member : members) {
if (member == null) {
this.logger.warn("Member == null in DataSet for {}", reportDescription);
continue;
}
this.logger.info("Handle member {} for {}", member.getReference(), reportDescription);
try {
final MeasurementDto dto = reportHandler.handleMember(new ReadOnlyNodeContainer(this.deviceIdentification, member));
if (dto != null) {
measurements.add(dto);
} else {
this.logger.warn("Unsupprted member {}, skipping", member.getName());
}
} catch (final Exception e) {
this.logger.error("Error adding event notification for member {} from {}", member.getReference(), reportDescription, e);
}
}
final GetDataSystemIdentifierDto systemResult = reportHandler.createResult(measurements);
final List<GetDataSystemIdentifierDto> systems = new ArrayList<>();
systems.add(systemResult);
final ReportDto reportDto = new ReportDto(report.getSqNum(), new DateTime(report.getTimeOfEntry().getTimestampValue() + IEC61850_ENTRY_TIME_OFFSET), report.getRptId());
this.deviceManagementService.sendMeasurements(this.deviceIdentification, new GetDataResponseDto(systems, reportDto));
}
use of com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850RtuDeviceService method handleGetData.
// ========================
// PRIVATE HELPER METHODS =
// ========================
private GetDataResponseDto handleGetData(final DeviceConnection connection, final GetDataDeviceRequest deviceRequest) throws ProtocolAdapterException {
final GetDataRequestDto requestedData = deviceRequest.getDataRequest();
final String serverName = this.getServerName(deviceRequest);
final Function<GetDataResponseDto> function = new Function<GetDataResponseDto>() {
@Override
public GetDataResponseDto apply(final DeviceMessageLog deviceMessageLog) throws Exception {
final Iec61850RtuDeviceReportingService reportingService = new Iec61850RtuDeviceReportingService(serverName);
reportingService.enableReportingOnDevice(connection, deviceRequest.getDeviceIdentification());
final List<GetDataSystemIdentifierDto> identifiers = new ArrayList<>();
for (final SystemFilterDto systemFilter : requestedData.getSystemFilters()) {
final SystemService systemService = Iec61850RtuDeviceService.this.systemServiceFactory.getSystemService(systemFilter);
final GetDataSystemIdentifierDto getDataSystemIdentifier = systemService.getData(systemFilter, Iec61850RtuDeviceService.this.iec61850Client, connection);
identifiers.add(getDataSystemIdentifier);
}
return new GetDataResponseDto(identifiers, null);
}
};
return this.iec61850Client.sendCommandWithRetry(function, deviceRequest.getDeviceIdentification());
}
use of com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850RtuDeviceService method getData.
@Override
public void getData(final GetDataDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
try {
final String serverName = this.getServerName(deviceRequest);
final ServerModel serverModel = this.connectAndRetrieveServerModel(deviceRequest, serverName);
final ClientAssociation clientAssociation = this.iec61850DeviceConnectionService.getClientAssociation(deviceRequest.getDeviceIdentification());
final GetDataResponseDto getDataResponse = this.handleGetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest);
final GetDataDeviceResponse deviceResponse = new GetDataDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.OK, getDataResponse);
deviceResponseHandler.handleResponse(deviceResponse);
} catch (final ConnectionFailureException se) {
LOGGER.error("Could not connect to device after all retries", se);
final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
} catch (final Exception e) {
LOGGER.error("Unexpected exception during Get Data", e);
final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
deviceResponseHandler.handleException(e, deviceResponse);
}
}
use of com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto in project Protocol-Adapter-IEC61850 by OSGP.
the class MicrogridsGetDataRequestMessageProcessor method handleGetDataDeviceResponse.
private void handleGetDataDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
GetDataResponseDto dataResponse = null;
try {
final GetDataDeviceResponse response = (GetDataDeviceResponse) deviceResponse;
dataResponse = response.getDataResponse();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Unexpected exception while retrieving response message", e);
}
final DeviceMessageMetadata deviceMessageMetaData = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, 0);
final ProtocolResponseMessage responseMessage = new ProtocolResponseMessage.Builder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetaData).result(result).osgpException(osgpException).dataObject(dataResponse).retryCount(retryCount).build();
responseMessageSender.send(responseMessage);
}
Aggregations