use of org.apache.commons.lang3.StringUtils.removeStart in project knime-core by knime.
the class WorkflowManager method getExternalNodeDataHandles.
/**
* Implementation of {@link #getInputNodes()} and {@link #getExternalOutputs()}.
*
* @param nodeModelClass either {@link InputNode}.class or {@link OutputNode}.class.
* @param retriever resolves the data object from the input or output.
* @return List of nodes with their parameter names unified.
*/
// package scope for tests
<T> List<ExternalNodeDataHandle> getExternalNodeDataHandles(final Class<T> nodeModelClass, final Function<T, ExternalNodeData> retriever) {
List<ExternalNodeDataHandle> result = new ArrayList<>();
try (WorkflowLock lock = lock()) {
Map<NodeID, T> externalNodeDataMap = findNodes(nodeModelClass, NodeModelFilter.all(), true, true);
// get all "parameter names" from all nodes in the workflow in order to see if there are name conflicts;
// occurrence map like {"string-input" -> 1, "foo" -> 1, "bar" -> 3}
Map<String, Long> parameterNamesToCountMap = externalNodeDataMap.values().stream().map(retriever).map(extNodeData -> extNodeData.getID()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
parameterNamesToCountMap.values().removeAll(Collections.singleton(Long.valueOf(1L)));
Set<String> nonUniqueParameterNames = parameterNamesToCountMap.keySet();
if (!nonUniqueParameterNames.isEmpty()) {
LOGGER.warnWithFormat("Workflow contains nodes with duplicate parameter name " + "(will be made unique by appending node IDs): %s", ConvenienceMethods.getShortStringFrom(nonUniqueParameterNames, 5));
}
// create result list, make keys unique where needed but also retain the fully qualified parameter name
for (Map.Entry<NodeID, T> entry : externalNodeDataMap.entrySet()) {
NodeID nodeID = entry.getKey();
ExternalNodeData nodeData = retriever.apply(entry.getValue());
String parameterNameShort = nodeData.getID();
// this ID = 0:3, nodeID = 0:3:5:0:2:2 => nodeIDRelativePath = 5:0:2:2
String nodeIDRelativePath = StringUtils.removeStart(nodeID.toString(), getID().toString() + ":");
// nodeIDRelativePath = 5:0:2:2 --> 5:2:2 (':0' are internals of a subnode)
nodeIDRelativePath = StringUtils.remove(nodeIDRelativePath, ":0");
String parameterNameFullyQualified = (parameterNameShort.isEmpty() ? "" : parameterNameShort + "-") + nodeIDRelativePath;
if (nonUniqueParameterNames.contains(parameterNameShort)) {
parameterNameShort = parameterNameFullyQualified;
}
result.add(new ExternalNodeDataHandle(parameterNameShort, parameterNameFullyQualified, (NativeNodeContainer) findNodeContainer(nodeID), nodeData));
}
return result;
}
}
use of org.apache.commons.lang3.StringUtils.removeStart in project engine by craftercms.
the class S3SiteListResolver method getSiteListFromBucketKeys.
protected Collection<String> getSiteListFromBucketKeys(String bucketName, String rootPrefix) {
List<String> siteNames = new ArrayList<>();
AmazonS3 client = clientBuilder.getClient();
ListObjectsV2Request request = new ListObjectsV2Request().withBucketName(bucketName).withPrefix(rootPrefix).withDelimiter(DELIMITER);
ListObjectsV2Result result = client.listObjectsV2(request);
if (CollectionUtils.isNotEmpty(result.getCommonPrefixes())) {
result.getCommonPrefixes().stream().map(prefix -> StringUtils.stripEnd(StringUtils.removeStart(prefix, rootPrefix), DELIMITER)).forEach(siteNames::add);
}
return siteNames;
}
Aggregations