use of org.apache.nifi.history.PreviousValue in project nifi by apache.
the class StandardNiFiServiceFacade method getComponentHistory.
@Override
public ComponentHistoryDTO getComponentHistory(final String componentId) {
final Map<String, PropertyHistoryDTO> propertyHistoryDtos = new LinkedHashMap<>();
final Map<String, List<PreviousValue>> propertyHistory = auditService.getPreviousValues(componentId);
for (final Map.Entry<String, List<PreviousValue>> entry : propertyHistory.entrySet()) {
final List<PreviousValueDTO> previousValueDtos = new ArrayList<>();
for (final PreviousValue previousValue : entry.getValue()) {
final PreviousValueDTO dto = new PreviousValueDTO();
dto.setPreviousValue(previousValue.getPreviousValue());
dto.setTimestamp(previousValue.getTimestamp());
dto.setUserIdentity(previousValue.getUserIdentity());
previousValueDtos.add(dto);
}
if (!previousValueDtos.isEmpty()) {
final PropertyHistoryDTO propertyHistoryDto = new PropertyHistoryDTO();
propertyHistoryDto.setPreviousValues(previousValueDtos);
propertyHistoryDtos.put(entry.getKey(), propertyHistoryDto);
}
}
final ComponentHistoryDTO history = new ComponentHistoryDTO();
history.setComponentId(componentId);
history.setPropertyHistory(propertyHistoryDtos);
return history;
}
use of org.apache.nifi.history.PreviousValue in project nifi by apache.
the class StandardActionDAO method getPreviousValuesForProperty.
private List<PreviousValue> getPreviousValuesForProperty(final String componentId, final String property) {
List<PreviousValue> previousValues = new ArrayList<>();
PreparedStatement statement = null;
ResultSet rs = null;
try {
// create the statement
statement = connection.prepareStatement(SELECT_PREVIOUS_VALUES);
statement.setString(1, componentId);
statement.setString(2, property);
// execute the query
rs = statement.executeQuery();
// ensure results
while (rs.next()) {
// get the previous value
final PreviousValue previousValue = new PreviousValue();
previousValue.setPreviousValue(rs.getString("VALUE"));
previousValue.setTimestamp(new Date(rs.getTimestamp("ACTION_TIMESTAMP").getTime()));
previousValue.setUserIdentity(rs.getString("IDENTITY"));
previousValues.add(previousValue);
}
} catch (SQLException sqle) {
throw new DataAccessException(sqle);
} finally {
RepositoryUtils.closeQuietly(rs);
RepositoryUtils.closeQuietly(statement);
}
return previousValues;
}
Aggregations