diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java index edbf08fe99..6c49e92ae8 100644 --- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/ProcessGroupClient.java @@ -38,6 +38,9 @@ public interface ProcessGroupClient { ProcessGroupEntity createProcessGroup(String parentGroupdId, ProcessGroupEntity entity) throws NiFiClientException, IOException; + ProcessGroupEntity createProcessGroup(String parentGroupdId, ProcessGroupEntity entity, boolean keepExisting) + throws NiFiClientException, IOException; + ProcessGroupEntity getProcessGroup(String processGroupId) throws NiFiClientException, IOException; ProcessGroupEntity updateProcessGroup(ProcessGroupEntity entity) throws NiFiClientException, IOException; diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java index 4f2ad9e290..2f204e22fa 100644 --- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/client/nifi/impl/JerseyProcessGroupClient.java @@ -58,6 +58,12 @@ public class JerseyProcessGroupClient extends AbstractJerseyClient implements Pr @Override public ProcessGroupEntity createProcessGroup(final String parentGroupdId, final ProcessGroupEntity entity) throws NiFiClientException, IOException { + return createProcessGroup(parentGroupdId, entity, true); + } + + @Override + public ProcessGroupEntity createProcessGroup(final String parentGroupdId, final ProcessGroupEntity entity, boolean keepExisting) + throws NiFiClientException, IOException { if (StringUtils.isBlank(parentGroupdId)) { throw new IllegalArgumentException("Parent process group id cannot be null or blank"); @@ -70,6 +76,7 @@ public class JerseyProcessGroupClient extends AbstractJerseyClient implements Pr return executeAction("Error creating process group", () -> { final WebTarget target = processGroupsTarget .path("{id}/process-groups") + .queryParam("parameterContextHandlingStrategy", keepExisting ? "KEEP_EXISTING" : "REPLACE") .resolveTemplate("id", parentGroupdId); return getRequestBuilder(target).post( diff --git a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java index 5913871031..6c45f9f033 100644 --- a/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java +++ b/nifi-toolkit/nifi-toolkit-cli/src/main/java/org/apache/nifi/toolkit/cli/impl/command/CommandOption.java @@ -83,6 +83,8 @@ public enum CommandOption { PG_NAME("pgn", "processGroupName", "The name of a process group", true), PG_VAR_NAME("var", "varName", "The name of a variable", true), PG_VAR_VALUE("val", "varValue", "The value of a variable", true), + KEEP_EXISTING_PARAMETER_CONTEXT("kepc", "keep-existing-parameter-context", "If false, only directly associated Parameter Contexts will be copied, " + + "inherited Contexts with no direct assignment to a Process Group are ignored", true), POS_X("px", "posX", "The x coordinate of a position", true), POS_Y("py", "posY", "The y coordinate of a position", true), 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 a3a279d107..8afed8b42b 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 @@ -65,6 +65,7 @@ public class PGImport extends AbstractNiFiCommand { addOption(CommandOption.FLOW_VERSION.createOption()); addOption(CommandOption.POS_X.createOption()); addOption(CommandOption.POS_Y.createOption()); + addOption(CommandOption.KEEP_EXISTING_PARAMETER_CONTEXT.createOption()); } @Override @@ -78,6 +79,8 @@ public class PGImport extends AbstractNiFiCommand { final String posXStr = getArg(properties, CommandOption.POS_X); final String posYStr = getArg(properties, CommandOption.POS_Y); + String keepExistingPC = getArg(properties, CommandOption.KEEP_EXISTING_PARAMETER_CONTEXT); + final boolean posXExists = StringUtils.isNotBlank(posXStr); final boolean posYExists = StringUtils.isNotBlank(posYStr); @@ -89,6 +92,12 @@ public class PGImport extends AbstractNiFiCommand { throw new IllegalArgumentException("Missing X position - Please specify both X and Y, or specify neither"); } + if(StringUtils.isNotBlank(keepExistingPC) && !(keepExistingPC.equals("true") || keepExistingPC.equals("false"))) { + throw new IllegalArgumentException("Keep Existing Parameter Context must be either true or false"); + } else if (StringUtils.isBlank(keepExistingPC)) { + keepExistingPC = "true"; + } + // if a registry client is specified use it, otherwise see if there is only one available and use that, // if more than one is available then throw an exception because we don't know which one to use String registryId = getArg(properties, CommandOption.REGISTRY_CLIENT_ID); @@ -140,7 +149,7 @@ public class PGImport extends AbstractNiFiCommand { pgEntity.setRevision(getInitialRevisionDTO()); final ProcessGroupClient pgClient = client.getProcessGroupClient(); - final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(parentPgId, pgEntity); + final ProcessGroupEntity createdEntity = pgClient.createProcessGroup(parentPgId, pgEntity, Boolean.parseBoolean(keepExistingPC)); return new StringResult(createdEntity.getId(), getContext().isInteractive()); }