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);
}
}
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);
}
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;
}
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())));
}
}
Aggregations