forked from apache/nifi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NIFI-11706 Add option to create dedicated Parameter Contexts for Impo…
…rted Flows This closes apache#7401 Signed-off-by: David Handermann <exceptionfactory@apache.org>
- Loading branch information
1 parent
5584a1b
commit cadf2fb
Showing
13 changed files
with
597 additions
and
64 deletions.
There are no files selected for viewing
Binary file modified
BIN
+43.5 KB
(170%)
nifi-docs/src/main/asciidoc/images/import-version-dialog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...lient-dto/src/main/java/org/apache/nifi/web/api/dto/ParameterContextHandlingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.nifi.web.api.dto; | ||
|
||
public enum ParameterContextHandlingStrategy { | ||
KEEP_EXISTING, REPLACE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...web-api/src/main/java/org/apache/nifi/web/util/ParameterContextNameCollisionResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.nifi.web.util; | ||
|
||
import org.apache.nifi.web.api.dto.ParameterContextDTO; | ||
import org.apache.nifi.web.api.entity.ParameterContextEntity; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
class ParameterContextNameCollisionResolver { | ||
private static final String PATTERN_GROUP_NAME = "name"; | ||
private static final String PATTERN_GROUP_INDEX = "index"; | ||
|
||
private static final String LINEAGE_FORMAT = "^(?<" + PATTERN_GROUP_NAME + ">.+?)( \\((?<" + PATTERN_GROUP_INDEX + ">[0-9]+)\\))?$"; | ||
private static final Pattern LINEAGE_PATTERN = Pattern.compile(LINEAGE_FORMAT); | ||
|
||
private static final String NAME_FORMAT = "%s (%d)"; | ||
|
||
public String resolveNameCollision(final String originalParameterContextName, final Collection<ParameterContextEntity> existingContexts) { | ||
final Matcher lineageMatcher = LINEAGE_PATTERN.matcher(originalParameterContextName); | ||
|
||
if (!lineageMatcher.matches()) { | ||
throw new IllegalArgumentException("Existing Parameter Context name \"(" + originalParameterContextName + "\") cannot be processed"); | ||
} | ||
|
||
final String lineName = lineageMatcher.group(PATTERN_GROUP_NAME); | ||
final String originalIndex = lineageMatcher.group(PATTERN_GROUP_INDEX); | ||
|
||
// Candidates cannot be cached because new context might be added between calls | ||
final Set<ParameterContextDTO> candidates = existingContexts | ||
.stream() | ||
.map(pc -> pc.getComponent()) | ||
.filter(dto -> dto.getName().startsWith(lineName)) | ||
.collect(Collectors.toSet()); | ||
|
||
int biggestIndex = (originalIndex == null) ? 0 : Integer.valueOf(originalIndex); | ||
|
||
for (final ParameterContextDTO candidate : candidates) { | ||
final Matcher matcher = LINEAGE_PATTERN.matcher(candidate.getName()); | ||
|
||
if (matcher.matches() && lineName.equals(matcher.group(PATTERN_GROUP_NAME))) { | ||
final String indexGroup = matcher.group(PATTERN_GROUP_INDEX); | ||
|
||
if (indexGroup != null) { | ||
int biggestIndexCandidate = Integer.valueOf(indexGroup); | ||
|
||
if (biggestIndexCandidate > biggestIndex) { | ||
biggestIndex = biggestIndexCandidate; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return String.format(NAME_FORMAT, lineName, biggestIndex + 1); | ||
} | ||
} |
Oops, something went wrong.