Search in sources :

Example 1 with PreviousValue

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;
}
Also used : PropertyHistoryDTO(org.apache.nifi.web.api.dto.PropertyHistoryDTO) ArrayList(java.util.ArrayList) PreviousValue(org.apache.nifi.history.PreviousValue) LinkedHashMap(java.util.LinkedHashMap) PreviousValueDTO(org.apache.nifi.web.api.dto.PreviousValueDTO) ComponentHistoryDTO(org.apache.nifi.web.api.dto.ComponentHistoryDTO) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) StateMap(org.apache.nifi.components.state.StateMap) HashMap(java.util.HashMap)

Example 2 with PreviousValue

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;
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PreviousValue(org.apache.nifi.history.PreviousValue) Date(java.util.Date) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Aggregations

ArrayList (java.util.ArrayList)2 PreviousValue (org.apache.nifi.history.PreviousValue)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)1 StateMap (org.apache.nifi.components.state.StateMap)1 ComponentHistoryDTO (org.apache.nifi.web.api.dto.ComponentHistoryDTO)1 PreviousValueDTO (org.apache.nifi.web.api.dto.PreviousValueDTO)1 PropertyHistoryDTO (org.apache.nifi.web.api.dto.PropertyHistoryDTO)1