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 08d061786b NIFI-14086 NiFi CLI - Add PGRename and possibility to 
rename in PGImport (#10152)
08d061786b is described below

commit 08d061786beca973006dd9e57d5ec14cf6a80b41
Author: Pierre Villard <[email protected]>
AuthorDate: Thu Jul 31 23:12:51 2025 +0200

    NIFI-14086 NiFi CLI - Add PGRename and possibility to rename in PGImport 
(#10152)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../cli/impl/command/nifi/NiFiCommandGroup.java    |  2 +
 .../toolkit/cli/impl/command/nifi/pg/PGImport.java | 10 ++-
 .../toolkit/cli/impl/command/nifi/pg/PGRename.java | 79 ++++++++++++++++++++++
 3 files changed, 90 insertions(+), 1 deletion(-)

diff --git 
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
 
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
index ef5ebdb1d6..e0ffd66e5a 100644
--- 
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
+++ 
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/NiFiCommandGroup.java
@@ -96,6 +96,7 @@ import 
org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGGetVersion;
 import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGImport;
 import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGList;
 import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGListProcessors;
+import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGRename;
 import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGReplace;
 import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGSetParamContext;
 import org.apache.nifi.toolkit.cli.impl.command.nifi.pg.PGStart;
@@ -178,6 +179,7 @@ public class NiFiCommandGroup extends AbstractCommandGroup {
         commands.add(new PGGetParamContext());
         commands.add(new PGSetParamContext());
         commands.add(new PGReplace());
+        commands.add(new PGRename());
         commands.add(new PGExport());
         commands.add(new PGEmptyQueues());
         commands.add(new PGDelete());
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 a09f3878e4..785ebb95b9 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
@@ -63,12 +63,14 @@ public class PGImport extends 
AbstractNiFiCommand<StringResult> {
                 + "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.";
+                + "with existing process groups. If a process group name is 
specified, the imported process group will be "
+                + "renamed with the specified name.";
     }
 
     @Override
     protected void doInitialize(Context context) {
         addOption(CommandOption.PG_ID.createOption());
+        addOption(CommandOption.PG_NAME.createOption());
         addOption(CommandOption.INPUT_SOURCE.createOption());
         addOption(CommandOption.REGISTRY_CLIENT_ID.createOption());
         addOption(CommandOption.BUCKET_ID.createOption());
@@ -218,6 +220,12 @@ public class PGImport extends 
AbstractNiFiCommand<StringResult> {
             createdEntity = pgClient.upload(parentPgId, input, pgName, 
posDto.getX(), posDto.getY());
         }
 
+        final String pgName = getArg(properties, CommandOption.PG_NAME);
+        if (StringUtils.isNotBlank(pgName)) {
+            final PGRename pgRename = new PGRename();
+            pgRename.rename(pgName, pgClient, createdEntity);
+        }
+
         return new StringResult(createdEntity.getId(), 
getContext().isInteractive());
     }
 
diff --git 
a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGRename.java
 
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGRename.java
new file mode 100644
index 0000000000..99f866a408
--- /dev/null
+++ 
b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/nifi/pg/PGRename.java
@@ -0,0 +1,79 @@
+/*
+ * 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.toolkit.cli.impl.command.nifi.pg;
+
+import org.apache.commons.cli.MissingOptionException;
+import org.apache.nifi.toolkit.cli.api.Context;
+import org.apache.nifi.toolkit.cli.impl.command.CommandOption;
+import org.apache.nifi.toolkit.cli.impl.command.nifi.AbstractNiFiCommand;
+import org.apache.nifi.toolkit.cli.impl.result.StringResult;
+import org.apache.nifi.toolkit.client.NiFiClient;
+import org.apache.nifi.toolkit.client.NiFiClientException;
+import org.apache.nifi.toolkit.client.ProcessGroupClient;
+import org.apache.nifi.web.api.entity.ProcessGroupEntity;
+import org.apache.nifi.web.api.entity.ProcessGroupRecursivity;
+
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * Command to rename a process group.
+ */
+public class PGRename extends AbstractNiFiCommand<StringResult> {
+
+    public PGRename() {
+        super("pg-rename", StringResult.class);
+    }
+
+    @Override
+    public String getDescription() {
+        return "Renames the given process group.";
+    }
+
+    @Override
+    protected void doInitialize(final Context context) {
+        addOption(CommandOption.PG_ID.createOption());
+        addOption(CommandOption.PG_NAME.createOption());
+    }
+
+    @Override
+    public StringResult doExecute(final NiFiClient client, final Properties 
properties)
+            throws NiFiClientException, IOException, MissingOptionException {
+
+        final String pgId = getRequiredArg(properties, CommandOption.PG_ID);
+        final String pgName = getRequiredArg(properties, 
CommandOption.PG_NAME);
+
+        final ProcessGroupClient pgClient = client.getProcessGroupClient();
+        final ProcessGroupEntity pgEntity = pgClient.getProcessGroup(pgId);
+        if (pgEntity == null) {
+            throw new NiFiClientException("Process group with id " + pgId + " 
not found.");
+        }
+
+        rename(pgName, pgClient, pgEntity);
+
+        return new StringResult(pgId, isInteractive());
+    }
+
+    protected void rename(final String pgName, final ProcessGroupClient 
pgClient, final ProcessGroupEntity pgEntity) throws NiFiClientException, 
IOException {
+        
pgEntity.setProcessGroupUpdateStrategy(ProcessGroupRecursivity.DIRECT_CHILDREN.name());
+        pgEntity.getComponent().setContents(null);
+        pgEntity.getComponent().setVersionControlInformation(null);
+        pgEntity.getComponent().setName(pgName);
+
+        pgClient.updateProcessGroup(pgEntity);
+    }
+}
\ No newline at end of file

Reply via email to