This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new 5f31a0b753 NIFI-14706 NiFi CLI - Flow Version should be optional in PG 
Import command (#10063)
5f31a0b753 is described below

commit 5f31a0b753e227779d6f5db73300bb3caf2eac1b
Author: Pierre Villard <[email protected]>
AuthorDate: Wed Jul 9 05:17:20 2025 +0200

    NIFI-14706 NiFi CLI - Flow Version should be optional in PG Import command 
(#10063)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../toolkit/cli/impl/command/nifi/pg/PGImport.java | 29 +++++++++++++++-------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git 
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java
 
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java
index 928c0c1e16..a09f3878e4 100644
--- 
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java
+++ 
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGImport.java
@@ -35,9 +35,12 @@ import 
org.apache.nifi.web.api.dto.VersionControlInformationDTO;
 import org.apache.nifi.web.api.entity.FlowRegistryClientEntity;
 import org.apache.nifi.web.api.entity.FlowRegistryClientsEntity;
 import org.apache.nifi.web.api.entity.ProcessGroupEntity;
+import org.apache.nifi.web.api.entity.VersionedFlowSnapshotMetadataSetEntity;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Properties;
 import java.util.Set;
 
@@ -54,11 +57,13 @@ public class PGImport extends 
AbstractNiFiCommand<StringResult> {
 
     @Override
     public String getDescription() {
-        return "Creates a new process group by importing a versioned flow from 
a registry. If no process group id is " +
-                "specified, then the created process group will be placed in 
the root group. If only one registry client " +
-                "exists in NiFi, then it does not need to be specified and 
will be automatically selected. The x and y " +
-                "coordinates for the position of the imported process group 
may be optionally specified. If left blank, " +
-                "the position will automatically be selected to avoid 
overlapping with existing process groups.";
+        return "Creates a new process group by importing a versioned flow from 
a registry or using a local file. "
+                + "If no process group ID is specified, then the created 
process group will be placed in the root group. "
+                + "If using import from a registry and no version is 
specified, then the latest will be used. "
+                + "If only one registry client exists in NiFi, then it does 
not need to be specified and will be "
+                + "automatically selected. The x and y coordinates for the 
position of the imported process group may be "
+                + "optionally specified. If left blank, the position will 
automatically be selected to avoid overlapping "
+                + "with existing process groups.";
     }
 
     @Override
@@ -84,7 +89,7 @@ public class PGImport extends 
AbstractNiFiCommand<StringResult> {
 
         final String bucketId = getArg(properties, CommandOption.BUCKET_ID);
         final String flowId = getArg(properties, CommandOption.FLOW_ID);
-        final String flowVersion = getArg(properties, 
CommandOption.FLOW_VERSION);
+        String flowVersion = getArg(properties, CommandOption.FLOW_VERSION);
         final String flowBranch = getArg(properties, 
CommandOption.FLOW_BRANCH);
 
         final String posXStr = getArg(properties, CommandOption.POS_X);
@@ -103,9 +108,6 @@ public class PGImport extends 
AbstractNiFiCommand<StringResult> {
             if (StringUtils.isBlank(flowId)) {
                 throw new IllegalArgumentException("Input path is not 
specified so Flow ID must be specified");
             }
-            if (StringUtils.isBlank(flowVersion)) {
-                throw new IllegalArgumentException("Input path is not 
specified so Flow Version must be specified");
-            }
         } else {
             if (!input.exists() || !input.isFile() || !input.canRead()) {
                 throw new IllegalArgumentException("Specified input is not a 
local readable file: " + inputSource);
@@ -180,6 +182,15 @@ public class PGImport extends 
AbstractNiFiCommand<StringResult> {
                 }
             }
 
+            if (flowVersion == null) {
+                final VersionedFlowSnapshotMetadataSetEntity flowVersions = 
client.getFlowClient().getVersions(registryId, bucketId, flowId, flowBranch);
+                flowVersion = Collections.max(
+                        flowVersions.getVersionedFlowSnapshotMetadataSet(),
+                        Comparator.comparingLong(e -> 
e.getVersionedFlowSnapshotMetadata().getTimestamp()))
+                        .getVersionedFlowSnapshotMetadata()
+                        .getVersion();
+            }
+
             final VersionControlInformationDTO versionControlInfo = new 
VersionControlInformationDTO();
             versionControlInfo.setRegistryId(registryId);
             versionControlInfo.setBucketId(bucketId);

Reply via email to