/** * Retrieves the argument as a File object, if any, of an option. * * @param option the option that we want argument value to be returned for * @param defaultValue is the default value to be returned if the option is not specified * * @return Value of the argument if option is set, and has an argument, otherwise defaultValue. */ public File getFileValue(Option option, File defaultValue) { File answer = getFileValue(option); return (answer != null) ? answer : defaultValue; } }
/** * Retrieves the argument as a File object, if any, of an option. * * @param option the option that we want argument value to be returned for * @param defaultValue is the default value to be returned if the option is not specified * * @return Value of the argument if option is set, and has an argument, otherwise defaultValue. */ public File getFileValue(Option option, File defaultValue) { File answer = getFileValue(option); return (answer != null) ? answer : defaultValue; } }
@Test public void testGetFileValue() throws ParseException { File testDefaultValue = new File("default_file_name"); ArgumentParser argParser = new ArgumentParser(""); Option fileOpt = argParser.addArgument("f", "file", true, "Source file name", false); File inputValue; File resultValue; final String shortFileOpt = String.format("-%s", fileOpt.getOpt()); final String longFileOpt = String.format("--%s", fileOpt.getLongOpt()); argParser.parseArguments(new String[] {""}); assertNull(argParser.getFileValue(fileOpt)); assertEquals(testDefaultValue, argParser.getFileValue(fileOpt, testDefaultValue)); inputValue = new File("folder/file_name_1"); argParser.parseArguments(new String[] {shortFileOpt, inputValue.toString()}); resultValue = argParser.getFileValue(fileOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); inputValue = new File("folder/file_name_2"); argParser.parseArguments(new String[] {shortFileOpt, inputValue.toString()}); resultValue = argParser.getFileValue(fileOpt, testDefaultValue); assertNotNull(resultValue); assertEquals(inputValue, resultValue); inputValue = new File("file_name_3"); argParser.parseArguments(new String[] {longFileOpt, inputValue.toString()}); resultValue = argParser.getFileValue(fileOpt); assertNotNull(resultValue); assertEquals(inputValue, resultValue); }
/** * Runs the application by parsing the command line arguments and calling the controller to export business object data that passed its relative retention * expiration. This is the main entry into the application class itself and is typically called from a main method. * * @param args the command line arguments passed to the program * * @return the return value of the application * @throws Exception if any problems were encountered */ protected ToolsCommonConstants.ReturnValue go(String[] args) throws Exception { // Create the Spring application context. ApplicationContext applicationContext = createApplicationContext(); // Parse the command line arguments and return a return value if we shouldn't continue processing (e.g. we displayed usage information, etc.). ToolsCommonConstants.ReturnValue returnValue = parseCommandLineArguments(args, applicationContext); if (returnValue != null) { return returnValue; } // Create a DTO to communicate with herd registration server. RegServerAccessParamsDto regServerAccessParamsDto = RegServerAccessParamsDto.builder().withRegServerHost(argParser.getStringValue(regServerHostOpt)).withRegServerPort(regServerPort).withUseSsl(useSsl) .withUsername(argParser.getStringValue(usernameOpt)).withPassword(argParser.getStringValue(passwordOpt)) .withTrustSelfSignedCertificate(trustSelfSignedCertificate).withDisableHostnameVerification(disableHostnameVerification).build(); // Call the controller with the user specified parameters to perform the upload. RetentionExpirationDestroyerController controller = applicationContext.getBean(RetentionExpirationDestroyerController.class); controller.performRetentionExpirationDestruction(argParser.getFileValue(localInputFileOpt), regServerAccessParamsDto); // No exceptions were returned so return success. return ToolsCommonConstants.ReturnValue.SUCCESS; }
argParser.getFileValue(localOutputFileOpt), regServerAccessParamsDto, argParser.getStringValue(udcServerHostOpt));
.withUsername(argParser.getStringValue(usernameOpt)).withPassword(argParser.getStringValue(passwordOpt)) .withTrustSelfSignedCertificate(trustSelfSignedCertificate).withDisableHostnameVerification(disableHostnameVerification).build(); controller.performDownload(regServerAccessParamsDto, argParser.getFileValue(manifestPathOpt), params);
.withUsername(argParser.getStringValue(usernameOpt)).withPassword(argParser.getStringValue(passwordOpt)) .withTrustSelfSignedCertificate(trustSelfSignedCertificate).withDisableHostnameVerification(disableHostnameVerification).build(); controller.performUpload(regServerAccessParamsDto, argParser.getFileValue(manifestPathOpt), params, argParser.getBooleanValue(createNewVersionOpt), argParser.getBooleanValue(forceOpt), maxRetryAttempts, retryDelaySecs);