Search in sources :

Example 1 with FlowChangePurgeDetails

use of org.apache.nifi.action.details.FlowChangePurgeDetails in project nifi by apache.

the class StandardActionDAO method createAction.

@Override
public Action createAction(Action action) throws DataAccessException {
    if (action.getUserIdentity() == null) {
        throw new IllegalArgumentException("User cannot be null.");
    }
    if (action.getTimestamp() == null) {
        throw new IllegalArgumentException("Action timestamp cannot be null.");
    }
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // obtain a statement to insert to the action table
        statement = connection.prepareStatement(INSERT_ACTION, Statement.RETURN_GENERATED_KEYS);
        statement.setString(1, StringUtils.left(action.getUserIdentity(), 4096));
        statement.setString(2, action.getSourceId());
        statement.setString(3, StringUtils.left(action.getSourceName(), 1000));
        statement.setString(4, action.getSourceType().name());
        statement.setString(5, action.getOperation().name());
        statement.setTimestamp(6, new java.sql.Timestamp(action.getTimestamp().getTime()));
        // insert the action
        int updateCount = statement.executeUpdate();
        final FlowChangeAction createdAction = new FlowChangeAction();
        createdAction.setUserIdentity(action.getUserIdentity());
        createdAction.setSourceId(action.getSourceId());
        createdAction.setSourceName(action.getSourceName());
        createdAction.setSourceType(action.getSourceType());
        createdAction.setOperation(action.getOperation());
        createdAction.setTimestamp(action.getTimestamp());
        createdAction.setActionDetails(action.getActionDetails());
        createdAction.setComponentDetails(action.getComponentDetails());
        // get the action id
        rs = statement.getGeneratedKeys();
        if (updateCount == 1 && rs.next()) {
            createdAction.setId(rs.getInt(1));
        } else {
            throw new DataAccessException("Unable to insert action.");
        }
        // close the previous statement
        statement.close();
        // determine the type of component
        ComponentDetails componentDetails = createdAction.getComponentDetails();
        if (componentDetails instanceof FlowChangeExtensionDetails) {
            createExtensionDetails(createdAction.getId(), (ExtensionDetails) componentDetails);
        } else if (componentDetails instanceof FlowChangeRemoteProcessGroupDetails) {
            createRemoteProcessGroupDetails(createdAction.getId(), (RemoteProcessGroupDetails) componentDetails);
        }
        // determine the type of action
        ActionDetails details = createdAction.getActionDetails();
        if (details instanceof FlowChangeConnectDetails) {
            createConnectDetails(createdAction.getId(), (ConnectDetails) details);
        } else if (details instanceof FlowChangeMoveDetails) {
            createMoveDetails(createdAction.getId(), (MoveDetails) details);
        } else if (details instanceof FlowChangeConfigureDetails) {
            createConfigureDetails(createdAction.getId(), (ConfigureDetails) details);
        } else if (details instanceof FlowChangePurgeDetails) {
            createPurgeDetails(createdAction.getId(), (PurgeDetails) details);
        }
        return createdAction;
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
}
Also used : FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) MoveDetails(org.apache.nifi.action.details.MoveDetails) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) SQLException(java.sql.SQLException) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) PreparedStatement(java.sql.PreparedStatement) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) FlowChangeRemoteProcessGroupDetails(org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails) RemoteProcessGroupDetails(org.apache.nifi.action.component.details.RemoteProcessGroupDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) FlowChangeExtensionDetails(org.apache.nifi.action.component.details.FlowChangeExtensionDetails) ResultSet(java.sql.ResultSet) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) ActionDetails(org.apache.nifi.action.details.ActionDetails) ComponentDetails(org.apache.nifi.action.component.details.ComponentDetails) DataAccessException(org.apache.nifi.admin.dao.DataAccessException) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 2 with FlowChangePurgeDetails

use of org.apache.nifi.action.details.FlowChangePurgeDetails in project nifi by apache.

the class StandardNiFiServiceFacade method deleteActions.

@Override
public void deleteActions(final Date endDate) {
    // get the user from the request
    final NiFiUser user = NiFiUserUtils.getNiFiUser();
    if (user == null) {
        throw new WebApplicationException(new Throwable("Unable to access details for current user."));
    }
    // create the purge details
    final FlowChangePurgeDetails details = new FlowChangePurgeDetails();
    details.setEndDate(endDate);
    // create a purge action to record that records are being removed
    final FlowChangeAction purgeAction = new FlowChangeAction();
    purgeAction.setUserIdentity(user.getIdentity());
    purgeAction.setOperation(Operation.Purge);
    purgeAction.setTimestamp(new Date());
    purgeAction.setSourceId("Flow Controller");
    purgeAction.setSourceName("History");
    purgeAction.setSourceType(Component.Controller);
    purgeAction.setActionDetails(details);
    // purge corresponding actions
    auditService.purgeActions(endDate, purgeAction);
}
Also used : NiFiUser(org.apache.nifi.authorization.user.NiFiUser) WebApplicationException(javax.ws.rs.WebApplicationException) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) Date(java.util.Date) FlowChangeAction(org.apache.nifi.action.FlowChangeAction)

Example 3 with FlowChangePurgeDetails

use of org.apache.nifi.action.details.FlowChangePurgeDetails in project nifi by apache.

the class StandardActionDAO method getPurgeDetails.

private PurgeDetails getPurgeDetails(Integer actionId) throws DataAccessException {
    FlowChangePurgeDetails purgeDetails = null;
    PreparedStatement statement = null;
    ResultSet rs = null;
    try {
        // create the statement
        statement = connection.prepareStatement(SELECT_PURGE_DETAILS_FOR_ACTION);
        statement.setInt(1, actionId);
        // execute the query
        rs = statement.executeQuery();
        // ensure results
        if (rs.next()) {
            purgeDetails = new FlowChangePurgeDetails();
            purgeDetails.setEndDate(new Date(rs.getTimestamp("END_DATE").getTime()));
        }
    } catch (SQLException sqle) {
        throw new DataAccessException(sqle);
    } finally {
        RepositoryUtils.closeQuietly(rs);
        RepositoryUtils.closeQuietly(statement);
    }
    return purgeDetails;
}
Also used : FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Date(java.util.Date) DataAccessException(org.apache.nifi.admin.dao.DataAccessException)

Example 4 with FlowChangePurgeDetails

use of org.apache.nifi.action.details.FlowChangePurgeDetails in project nifi by apache.

the class DtoFactory method createActionDetailsDto.

/**
 * Creates an ActionDetailsDTO for the specified ActionDetails.
 *
 * @param actionDetails details
 * @return dto
 */
private ActionDetailsDTO createActionDetailsDto(final ActionDetails actionDetails) {
    if (actionDetails == null) {
        return null;
    }
    if (actionDetails instanceof FlowChangeConfigureDetails) {
        final ConfigureDetailsDTO configureDetails = new ConfigureDetailsDTO();
        configureDetails.setName(((ConfigureDetails) actionDetails).getName());
        configureDetails.setPreviousValue(((ConfigureDetails) actionDetails).getPreviousValue());
        configureDetails.setValue(((ConfigureDetails) actionDetails).getValue());
        return configureDetails;
    } else if (actionDetails instanceof FlowChangeConnectDetails) {
        final ConnectDetailsDTO connectDetails = new ConnectDetailsDTO();
        connectDetails.setSourceId(((ConnectDetails) actionDetails).getSourceId());
        connectDetails.setSourceName(((ConnectDetails) actionDetails).getSourceName());
        connectDetails.setSourceType(((ConnectDetails) actionDetails).getSourceType().toString());
        connectDetails.setRelationship(((ConnectDetails) actionDetails).getRelationship());
        connectDetails.setDestinationId(((ConnectDetails) actionDetails).getDestinationId());
        connectDetails.setDestinationName(((ConnectDetails) actionDetails).getDestinationName());
        connectDetails.setDestinationType(((ConnectDetails) actionDetails).getDestinationType().toString());
        return connectDetails;
    } else if (actionDetails instanceof FlowChangeMoveDetails) {
        final MoveDetailsDTO moveDetails = new MoveDetailsDTO();
        moveDetails.setPreviousGroup(((MoveDetails) actionDetails).getPreviousGroup());
        moveDetails.setPreviousGroupId(((MoveDetails) actionDetails).getPreviousGroupId());
        moveDetails.setGroup(((MoveDetails) actionDetails).getGroup());
        moveDetails.setGroupId(((MoveDetails) actionDetails).getGroupId());
        return moveDetails;
    } else if (actionDetails instanceof FlowChangePurgeDetails) {
        final PurgeDetailsDTO purgeDetails = new PurgeDetailsDTO();
        purgeDetails.setEndDate(((PurgeDetails) actionDetails).getEndDate());
        return purgeDetails;
    } else {
        throw new WebApplicationException(new IllegalArgumentException(String.format("Unrecognized type of action details encountered %s during serialization.", actionDetails.toString())));
    }
}
Also used : FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) ConfigureDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConfigureDetailsDTO) MoveDetailsDTO(org.apache.nifi.web.api.dto.action.details.MoveDetailsDTO) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) WebApplicationException(javax.ws.rs.WebApplicationException) FlowChangeConfigureDetails(org.apache.nifi.action.details.FlowChangeConfigureDetails) ConnectDetails(org.apache.nifi.action.details.ConnectDetails) FlowChangeConnectDetails(org.apache.nifi.action.details.FlowChangeConnectDetails) FlowChangeMoveDetails(org.apache.nifi.action.details.FlowChangeMoveDetails) FlowChangePurgeDetails(org.apache.nifi.action.details.FlowChangePurgeDetails) PurgeDetails(org.apache.nifi.action.details.PurgeDetails) PurgeDetailsDTO(org.apache.nifi.web.api.dto.action.details.PurgeDetailsDTO) ConnectDetailsDTO(org.apache.nifi.web.api.dto.action.details.ConnectDetailsDTO)

Aggregations

FlowChangePurgeDetails (org.apache.nifi.action.details.FlowChangePurgeDetails)4 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 FlowChangeAction (org.apache.nifi.action.FlowChangeAction)2 FlowChangeConfigureDetails (org.apache.nifi.action.details.FlowChangeConfigureDetails)2 FlowChangeConnectDetails (org.apache.nifi.action.details.FlowChangeConnectDetails)2 FlowChangeMoveDetails (org.apache.nifi.action.details.FlowChangeMoveDetails)2 PurgeDetails (org.apache.nifi.action.details.PurgeDetails)2 DataAccessException (org.apache.nifi.admin.dao.DataAccessException)2 ComponentDetails (org.apache.nifi.action.component.details.ComponentDetails)1 FlowChangeExtensionDetails (org.apache.nifi.action.component.details.FlowChangeExtensionDetails)1 FlowChangeRemoteProcessGroupDetails (org.apache.nifi.action.component.details.FlowChangeRemoteProcessGroupDetails)1 RemoteProcessGroupDetails (org.apache.nifi.action.component.details.RemoteProcessGroupDetails)1 ActionDetails (org.apache.nifi.action.details.ActionDetails)1 ConnectDetails (org.apache.nifi.action.details.ConnectDetails)1 MoveDetails (org.apache.nifi.action.details.MoveDetails)1 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)1