InstallIntoDhsCommand extends AbstractInstallerCommand { protected List<Command> buildCommandsForDhs(Options options) { DeployOtherDatabasesCommand dbCommand = new DeployOtherDatabasesCommand(); dbCommand.setDeployDatabaseCommandFactory(new HubDeployDatabaseCommandFactory(hubConfig)); List<String> groupNames = Arrays.asList(options.getGroupNames().split(",")); List<Command> commands = new ArrayList<>(); commands.add(new DeployPrivilegesCommand()); DeployRolesCommand deployRolesCommand = new DeployRolesCommand(); deployRolesCommand.setResourceFilenamesExcludePattern( Pattern.compile("(flow-developer-role|flow-operator-role|data-hub-admin-role).*") ); commands.add(deployRolesCommand); commands.add(new DeployAmpsCommand()); commands.add(dbCommand); DhsDeployServersCommand ddsc = new DhsDeployServersCommand(); ddsc.setServerVersion(serverVersion); commands.add(ddsc); commands.add(new DeployDatabaseFieldCommand()); commands.add(new DeployTriggersCommand()); commands.add(new DeployHubTriggersCommand(hubConfig.getStagingTriggersDbName())); commands.add(new LoadHubModulesCommand(hubConfig)); commands.add(new LoadHubArtifactsCommand(hubConfig, true)); commands.add(new GenerateFunctionMetadataCommand(hubConfig, true)); commands.add(new CopyQueryOptionsCommand(hubConfig, groupNames, Arrays.asList(options.getServerNames().split(",")), hubConfig.getDbName(DatabaseKind.JOB) )); commands.add(new UpdateDhsModulesPermissionsCommand(hubConfig)); commands.add(new CreateGranularPrivilegesCommand(hubConfig, groupNames)); return commands; }  @Override void run(ApplicationContext context, Options options);  }
@Test public void buildCommandList() { InstallIntoDhsCommand command = new InstallIntoDhsCommand(); command.hubConfig = super.adminHubConfig; Options options = new Options(); options.setGroupNames("Evaluator,Curator"); List<Command> commands = command.buildCommandsForDhs(options); Collections.sort(commands, Comparator.comparing(Command::getExecuteSortOrder)); int index = 0; System.out.println(commands); assertTrue(commands.get(index++) instanceof DeployPrivilegesCommand); assertTrue(commands.get(index++) instanceof DeployRolesCommand); assertTrue(commands.get(index++) instanceof DeployOtherDatabasesCommand); assertTrue(commands.get(index++) instanceof DeployDatabaseFieldCommand); assertTrue(commands.get(index++) instanceof DhsDeployServersCommand); assertTrue(commands.get(index++) instanceof LoadHubModulesCommand); assertTrue(commands.get(index++) instanceof UpdateDhsModulesPermissionsCommand); assertTrue(commands.get(index++) instanceof DeployAmpsCommand); assertTrue(commands.get(index++) instanceof CopyQueryOptionsCommand); assertTrue(commands.get(index++) instanceof DeployTriggersCommand); assertTrue(commands.get(index++) instanceof DeployHubTriggersCommand); assertTrue(commands.get(index++) instanceof LoadHubArtifactsCommand); assertTrue(commands.get(index++) instanceof GenerateFunctionMetadataCommand); assertTrue(commands.get(index++) instanceof CreateGranularPrivilegesCommand); assertEquals(14, commands.size()); DeployRolesCommand deployRolesCommand = (DeployRolesCommand) commands.get(1); ResourceFilenameFilter filter = (ResourceFilenameFilter) deployRolesCommand.getResourceFilenameFilter(); File dir = new File(PROJECT_PATH); assertTrue(filter.accept(dir, "data-hub-entity-model-reader.json")); assertTrue(filter.accept(dir, "data-hub-explorer-architect.json")); assertFalse(filter.accept(dir, "flow-developer-role.json"), "The DHF 'legacy' roles should not be deployed as they grant too many privileges for a DHS user"); assertFalse(filter.accept(dir, "flow-operator-role.json"), "The DHF 'legacy' roles should not be deployed as they grant too many privileges for a DHS user"); assertFalse(filter.accept(dir, "data-hub-admin-role.json"), "The DHF 'legacy' roles should not be deployed as they grant too many privileges for a DHS user"); CreateGranularPrivilegesCommand createGranularPrivilegesCommand = (CreateGranularPrivilegesCommand) commands.get(13); List<String> names = createGranularPrivilegesCommand.getGroupNames(); assertEquals("Evaluator", names.get(0)); assertEquals("Curator", names.get(1)); assertEquals(2, names.size()); }