NIFI-12524 Fixed null handling for auditing Connect Details

Signed-off-by: Matt Burgess <mattyb149@apache.org>

This closes #8198
This commit is contained in:
exceptionfactory 2023-12-30 13:16:31 -06:00 committed by Matt Burgess
parent b8c8eafd03
commit 8ddc0f0741
2 changed files with 82 additions and 3 deletions

View File

@ -443,12 +443,20 @@ public class EntityStoreAuditService implements AuditService, Closeable {
actionEntity.setLink(ActionLink.CONNECT_DETAILS.getProperty(), connectDetailsEntity);
connectDetailsEntity.setProperty(ConnectDetailsEntity.SOURCE_ID.getProperty(), connectDetails.getSourceId());
connectDetailsEntity.setProperty(ConnectDetailsEntity.SOURCE_NAME.getProperty(), connectDetails.getSourceName());
connectDetailsEntity.setProperty(ConnectDetailsEntity.SOURCE_TYPE.getProperty(), connectDetails.getSourceType().name());
if (connectDetails.getSourceName() != null) {
connectDetailsEntity.setProperty(ConnectDetailsEntity.SOURCE_NAME.getProperty(), connectDetails.getSourceName());
}
connectDetailsEntity.setProperty(ConnectDetailsEntity.DESTINATION_ID.getProperty(), connectDetails.getDestinationId());
connectDetailsEntity.setProperty(ConnectDetailsEntity.DESTINATION_NAME.getProperty(), connectDetails.getDestinationName());
connectDetailsEntity.setProperty(ConnectDetailsEntity.DESTINATION_TYPE.getProperty(), connectDetails.getDestinationType().name());
connectDetailsEntity.setProperty(ConnectDetailsEntity.RELATIONSHIP.getProperty(), connectDetails.getRelationship());
if (connectDetails.getDestinationName() != null) {
connectDetailsEntity.setProperty(ConnectDetailsEntity.DESTINATION_NAME.getProperty(), connectDetails.getDestinationName());
}
if (connectDetails.getRelationship() != null) {
connectDetailsEntity.setProperty(ConnectDetailsEntity.RELATIONSHIP.getProperty(), connectDetails.getRelationship());
}
}
private void addMoveDetails(final StoreTransaction storeTransaction, final Entity actionEntity, final MoveDetails moveDetails) {

View File

@ -21,7 +21,9 @@ import org.apache.nifi.action.Component;
import org.apache.nifi.action.FlowChangeAction;
import org.apache.nifi.action.Operation;
import org.apache.nifi.action.details.ActionDetails;
import org.apache.nifi.action.details.ConnectDetails;
import org.apache.nifi.action.details.FlowChangeConfigureDetails;
import org.apache.nifi.action.details.FlowChangeConnectDetails;
import org.apache.nifi.action.details.FlowChangePurgeDetails;
import org.apache.nifi.action.details.PurgeDetails;
import org.apache.nifi.history.History;
@ -73,6 +75,12 @@ class EntityStoreAuditServiceTest {
private static final Component SOURCE_TYPE = Component.Processor;
private static final String DESTINATION_NAME = "UpdateCounter";
private static final Component DESTINATION_TYPE = Component.Funnel;
private static final String RELATIONSHIP = "success";
private static final Operation OPERATION = Operation.Add;
private static final int ACTION_ID = 0;
@ -347,6 +355,55 @@ class EntityStoreAuditServiceTest {
assertEquals(USER_IDENTITY, secondPreviousValue.getUserIdentity());
}
@Test
void testAddActionsConnectDetailsMinimumPropertiesGetAction() {
final FlowChangeAction action = newAction();
final FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
connectDetails.setSourceId(SOURCE_ID);
connectDetails.setSourceType(SOURCE_TYPE);
connectDetails.setDestinationId(SECOND_SOURCE_ID);
connectDetails.setDestinationType(DESTINATION_TYPE);
action.setActionDetails(connectDetails);
final Collection<Action> actions = Collections.singletonList(action);
service.addActions(actions);
final Action actionFound = service.getAction(ACTION_ID);
assertEquals(ACTION_ID, actionFound.getId());
assertActionFound(actionFound);
final ActionDetails actionDetails = actionFound.getActionDetails();
assertConnectDetailsFound(connectDetails, actionDetails);
}
@Test
void testAddActionsConnectDetailsGetAction() {
final FlowChangeAction action = newAction();
final FlowChangeConnectDetails connectDetails = new FlowChangeConnectDetails();
connectDetails.setSourceName(SOURCE_NAME);
connectDetails.setSourceId(SOURCE_ID);
connectDetails.setSourceType(SOURCE_TYPE);
connectDetails.setDestinationName(DESTINATION_NAME);
connectDetails.setDestinationId(SECOND_SOURCE_ID);
connectDetails.setDestinationType(DESTINATION_TYPE);
connectDetails.setRelationship(RELATIONSHIP);
action.setActionDetails(connectDetails);
final Collection<Action> actions = Collections.singletonList(action);
service.addActions(actions);
final Action actionFound = service.getAction(ACTION_ID);
assertEquals(ACTION_ID, actionFound.getId());
assertActionFound(actionFound);
final ActionDetails actionDetails = actionFound.getActionDetails();
assertConnectDetailsFound(connectDetails, actionDetails);
}
private FlowChangeAction newAction() {
final FlowChangeAction action = new FlowChangeAction();
action.setTimestamp(ACTION_TIMESTAMP);
@ -366,4 +423,18 @@ class EntityStoreAuditServiceTest {
assertEquals(USER_IDENTITY, actionFound.getUserIdentity());
assertEquals(OPERATION, actionFound.getOperation());
}
private void assertConnectDetailsFound(final ConnectDetails connectDetails, final ActionDetails actionDetails) {
assertNotNull(actionDetails);
assertInstanceOf(ConnectDetails.class, actionDetails);
final ConnectDetails connectDetailsFound = (ConnectDetails) actionDetails;
assertEquals(connectDetails.getSourceName(), connectDetailsFound.getSourceName());
assertEquals(connectDetails.getSourceId(), connectDetailsFound.getSourceId());
assertEquals(connectDetails.getSourceType(), connectDetailsFound.getSourceType());
assertEquals(connectDetails.getDestinationName(), connectDetailsFound.getDestinationName());
assertEquals(connectDetails.getDestinationId(), connectDetailsFound.getDestinationId());
assertEquals(connectDetails.getDestinationType(), connectDetailsFound.getDestinationType());
assertEquals(connectDetails.getRelationship(), connectDetailsFound.getRelationship());
}
}