use of com.thinkbiganalytics.nifi.rest.model.visitor.NifiVisitableConnection in project kylo by Teradata.
the class NifiConnectionOrderVisitor method getSourceProcessors.
public List<NifiVisitableProcessor> getSourceProcessors(ConnectionDTO connection) {
ConnectableDTO source = connection.getSource();
List<NifiVisitableProcessor> sourceProcessors = new ArrayList<>();
if (source != null) {
if ("INPUT_PORT".equalsIgnoreCase(source.getType())) {
NifiVisitableProcessGroup group = visitedProcessGroups.get(source.getGroupId());
if (group == null) {
group = processGroup;
}
NifiVisitableProcessGroup parent = visitedProcessGroups.get(group.getDto().getParentGroupId());
// if the parent is null the parent is the starting process group
if (parent == null) {
parent = processGroup;
}
ConnectionDTO conn = parent.getConnectionMatchingDestinationId(source.getId());
if (conn == null) {
// if its null get it from the cache and process with that.
conn = cache.getProcessGroupCache().values().stream().flatMap(g -> g.getContents().getConnections().stream()).filter(connectionDTO -> connectionDTO.getDestination().getId().equalsIgnoreCase(source.getId())).findFirst().orElse(null);
}
if (conn != null && conn != connection) {
// get the processor whos source matches this connection Id
sourceProcessors = getSourceProcessors(conn);
// assign the inputPortProcessor == the the destination of this connection
}
List<NifiVisitableProcessor> inputProcessors = getDestinationProcessors(connection, false);
if (inputProcessors != null) {
for (NifiVisitableProcessor inputProcessor : inputProcessors) {
currentProcessGroup.addInputPortProcessor(source.getId(), inputProcessor);
}
}
} else if ("OUTPUT_PORT".equals(source.getType())) {
// get the sources group id then get the ending processor for that group
NifiVisitableProcessGroup group = visitedProcessGroups.get(source.getGroupId());
if (group != null) {
Set<NifiVisitableProcessor> sources = group.getOutputPortProcessors(source.getId());
if (sourceProcessors != null && sources != null) {
sourceProcessors.addAll(sources);
}
/*
If a process group is connected to another process group without any processors there will be no source processors
having sourceProcessors as null here is ok.
*/
}
} else if ("FUNNEL".equalsIgnoreCase(source.getType())) {
List<ConnectionDTO> passThroughConnections = NifiConnectionUtil.findConnectionsMatchingDestinationId(currentProcessGroup.getDto().getContents().getConnections(), connection.getSource().getId());
if (passThroughConnections != null) {
for (ConnectionDTO dto : passThroughConnections) {
ConnectionDTO newConnection = new ConnectionDTO();
newConnection.setSource(dto.getSource());
newConnection.setId(connection.getSource().getId());
newConnection.setDestination(connection.getDestination());
visitConnection(new NifiVisitableConnection(currentProcessGroup, newConnection));
}
}
} else if ("PROCESSOR".equals(source.getType())) {
NifiVisitableProcessor sourceProcessor = getConnectionProcessor(source.getGroupId(), source.getId());
sourceProcessors.add(sourceProcessor);
}
for (NifiVisitableProcessor sourceProcessor : sourceProcessors) {
sourceProcessor.addDestinationConnectionIdentifier(connection);
}
}
return sourceProcessors;
}
Aggregations