use of io.cdap.cdap.etl.api.connector.PluginSpec in project cdap by caskdata.
the class ConnectionUtils method filterSpecWithPluginNameAndType.
/**
* Returns {@link ConnectorSpec}
*
* @return filtered {@link ConnectorSpec} on the basis of plugin name and type
*/
public static ConnectorSpec filterSpecWithPluginNameAndType(ConnectorSpec spec, @Nullable String pluginName, @Nullable String pluginType) {
if (Strings.isNullOrEmpty(pluginName) && Strings.isNullOrEmpty(pluginType)) {
return spec;
}
ConnectorSpec.Builder specBuilder = ConnectorSpec.builder();
specBuilder.setSchema(spec.getSchema());
for (PluginSpec pluginSpec : spec.getRelatedPlugins()) {
if (Strings.isNullOrEmpty(pluginName)) {
if (pluginType.equalsIgnoreCase(pluginSpec.getType())) {
specBuilder.addRelatedPlugin(pluginSpec);
}
continue;
}
if (Strings.isNullOrEmpty(pluginType)) {
if (pluginName.equalsIgnoreCase(pluginSpec.getName())) {
specBuilder.addRelatedPlugin(pluginSpec);
}
continue;
}
if (pluginType.equalsIgnoreCase(pluginSpec.getType()) && pluginName.equalsIgnoreCase(pluginSpec.getName())) {
specBuilder.addRelatedPlugin(pluginSpec);
}
}
return specBuilder.build();
}
Aggregations