Search in sources :

Example 6 with BuildInformation

use of org.finra.herd.model.api.xml.BuildInformation in project herd by FINRAOS.

the class HerdControllerTest method testDisplayBuildInfo.

@Test
public void testDisplayBuildInfo() throws Exception {
    // Get a model and view back from the UI controller displayBuildInfo method and ensure it is correct and contains the correct model data.
    ModelAndView modelAndView = herdController.displayBuildInfo();
    assertNotNull(modelAndView);
    assertEquals(UiConstants.DISPLAY_BUILD_INFO_PAGE, modelAndView.getViewName());
    BuildInformation buildInformation = (BuildInformation) modelAndView.getModel().get(UiConstants.MODEL_KEY_BUILD_INFORMATION);
    assertNotNull(buildInformation);
    assertNotNull(buildInformation.getBuildDate());
    logger.info(buildInformation.toString());
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) BuildInformation(org.finra.herd.model.api.xml.BuildInformation) Test(org.junit.Test)

Example 7 with BuildInformation

use of org.finra.herd.model.api.xml.BuildInformation in project herd by FINRAOS.

the class RetentionExpirationDestroyerApp method parseCommandLineArguments.

/**
 * Parses the command line arguments using the argument parser. The command line options will be initialized and added to the argument parser in this
 * method. Ensure the argParser was set in this class prior to calling this method.
 *
 * @param args the command line arguments
 * @param applicationContext the Spring application context
 *
 * @return the return value if the application should exit or null if the application can continue.
 */
// Using System.out to inform user of usage or version information is okay.
@SuppressWarnings("PMD.SystemPrintln")
@SuppressFBWarnings(value = "VA_FORMAT_STRING_USES_NEWLINE", justification = "We will use the standard carriage return character.")
protected ToolsCommonConstants.ReturnValue parseCommandLineArguments(String[] args, ApplicationContext applicationContext) {
    try {
        localInputFileOpt = argParser.addArgument("i", "localInputFile", true, "The path to files on your local file system as input.", true);
        regServerHostOpt = argParser.addArgument("H", "regServerHost", true, "Registration Service hostname.", true);
        Option regServerPortOpt = argParser.addArgument("P", "regServerPort", true, "Registration Service port.", true);
        Option sslOpt = argParser.addArgument("s", "ssl", true, "Enable or disable SSL (HTTPS).", false);
        usernameOpt = argParser.addArgument("u", "username", true, "The username for HTTPS client authentication.", false);
        passwordOpt = argParser.addArgument("w", "password", true, "The password used for HTTPS client authentication.", false);
        Option helpOpt = argParser.addArgument("h", "help", false, "Display usage information and exit.", false);
        Option versionOpt = argParser.addArgument("v", "version", false, "Display version information and exit.", false);
        // Parse command line arguments without failing on any missing required arguments by passing "false" as the second argument.
        argParser.parseArguments(args, false);
        // If help option was specified, then display usage information and return success.
        if (argParser.getBooleanValue(helpOpt)) {
            System.out.println(argParser.getUsageInformation());
            return ToolsCommonConstants.ReturnValue.SUCCESS;
        }
        // If version option was specified, then display version information and return success.
        if (argParser.getBooleanValue(versionOpt)) {
            BuildInformation buildInformation = applicationContext.getBean(BuildInformation.class);
            System.out.println(String.format(ToolsCommonConstants.BUILD_INFO_STRING_FORMAT, buildInformation.getBuildDate(), buildInformation.getBuildNumber(), buildInformation.getBuildOs(), buildInformation.getBuildUser()));
            return ToolsCommonConstants.ReturnValue.SUCCESS;
        }
        // Parse command line arguments for the second time, enforcing the required arguments by passing "true" as the second argument.
        argParser.parseArguments(args, true);
        // Extract a boolean option value passing "false" as a default value.
        useSsl = argParser.getStringValueAsBoolean(sslOpt, false);
        // Username and password are required when useSsl is enabled.
        if (useSsl && (StringUtils.isBlank(argParser.getStringValue(usernameOpt)) || StringUtils.isBlank(argParser.getStringValue(passwordOpt)))) {
            throw new ParseException("Username and password are required when SSL is enabled.");
        }
        // Extract all Integer option values here to catch any NumberFormatException exceptions.
        regServerPort = argParser.getIntegerValue(regServerPortOpt);
    } catch (ParseException ex) {
        // Log a friendly error and return a failure which will cause the application to exit.
        LOGGER.error("Error parsing command line arguments: " + ex.getMessage() + "\n" + argParser.getUsageInformation());
        return ToolsCommonConstants.ReturnValue.FAILURE;
    }
    // The command line arguments were all parsed successfully so return null to continue processing.
    return null;
}
Also used : Option(org.apache.commons.cli.Option) BuildInformation(org.finra.herd.model.api.xml.BuildInformation) ParseException(org.apache.commons.cli.ParseException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 8 with BuildInformation

use of org.finra.herd.model.api.xml.BuildInformation in project herd by FINRAOS.

the class RetentionExpirationDestroyerAppTest method testParseCommandLineArgumentsVersionOpt.

@Test
public void testParseCommandLineArgumentsVersionOpt() {
    String output = runTestGetSystemOut(() -> {
        String[] arguments = { "--version" };
        assertEquals(ToolsCommonConstants.ReturnValue.SUCCESS, exporterApp.parseCommandLineArguments(arguments, applicationContext));
    });
    BuildInformation buildInformation = applicationContext.getBean(BuildInformation.class);
    assertEquals("output", String.format(DataBridgeApp.BUILD_INFO_STRING_FORMAT, buildInformation.getBuildDate(), buildInformation.getBuildNumber(), buildInformation.getBuildOs(), buildInformation.getBuildUser()), output);
}
Also used : BuildInformation(org.finra.herd.model.api.xml.BuildInformation) Test(org.junit.Test)

Example 9 with BuildInformation

use of org.finra.herd.model.api.xml.BuildInformation in project herd by FINRAOS.

the class RetentionExpirationExporterApp method parseCommandLineArguments.

/**
 * Parses the command line arguments using the argument parser. The command line options will be initialized and added to the argument parser in this
 * method. Ensure the argParser was set in this class prior to calling this method.
 *
 * @param args the command line arguments
 * @param applicationContext the Spring application context
 *
 * @return the return value if the application should exit or null if the application can continue.
 */
// Using System.out to inform user of usage or version information is okay.
@SuppressWarnings("PMD.SystemPrintln")
@SuppressFBWarnings(value = "VA_FORMAT_STRING_USES_NEWLINE", justification = "We will use the standard carriage return character.")
ToolsCommonConstants.ReturnValue parseCommandLineArguments(String[] args, ApplicationContext applicationContext) {
    try {
        namespaceOpt = argParser.addArgument("n", "namespace", true, "Namespace.", true);
        businessObjectDefinitionNameOpt = argParser.addArgument("b", "businessObjectDefinitionName", true, "Business object definition.", true);
        localOutputFileOpt = argParser.addArgument("o", "localOutputFile", true, "The path to files on your local file system.", true);
        regServerHostOpt = argParser.addArgument("H", "regServerHost", true, "Registration Service hostname.", true);
        Option regServerPortOpt = argParser.addArgument("P", "regServerPort", true, "Registration Service port.", true);
        udcServerHostOpt = argParser.addArgument("c", "udcServerHost", true, "UDC application server hostname.", true);
        Option sslOpt = argParser.addArgument("s", "ssl", true, "Enable or disable SSL (HTTPS).", false);
        usernameOpt = argParser.addArgument("u", "username", true, "The username for HTTPS client authentication.", false);
        passwordOpt = argParser.addArgument("w", "password", true, "The password used for HTTPS client authentication.", false);
        Option helpOpt = argParser.addArgument("h", "help", false, "Display usage information and exit.", false);
        Option versionOpt = argParser.addArgument("v", "version", false, "Display version information and exit.", false);
        // Parse command line arguments without failing on any missing required arguments by passing "false" as the second argument.
        argParser.parseArguments(args, false);
        // If help option was specified, then display usage information and return success.
        if (argParser.getBooleanValue(helpOpt)) {
            System.out.println(argParser.getUsageInformation());
            return ToolsCommonConstants.ReturnValue.SUCCESS;
        }
        // If version option was specified, then display version information and return success.
        if (argParser.getBooleanValue(versionOpt)) {
            BuildInformation buildInformation = applicationContext.getBean(BuildInformation.class);
            System.out.println(String.format(ToolsCommonConstants.BUILD_INFO_STRING_FORMAT, buildInformation.getBuildDate(), buildInformation.getBuildNumber(), buildInformation.getBuildOs(), buildInformation.getBuildUser()));
            return ToolsCommonConstants.ReturnValue.SUCCESS;
        }
        // Parse command line arguments for the second time, enforcing the required arguments by passing "true" as the second argument.
        argParser.parseArguments(args, true);
        // Extract a boolean option value passing "false" as a default value.
        useSsl = argParser.getStringValueAsBoolean(sslOpt, false);
        // Username and password are required when useSsl is enabled.
        if (useSsl && (StringUtils.isBlank(argParser.getStringValue(usernameOpt)) || StringUtils.isBlank(argParser.getStringValue(passwordOpt)))) {
            throw new ParseException("Username and password are required when SSL is enabled.");
        }
        // Extract all Integer option values here to catch any NumberFormatException exceptions.
        regServerPort = argParser.getIntegerValue(regServerPortOpt);
    } catch (ParseException ex) {
        // Log a friendly error and return a failure which will cause the application to exit.
        LOGGER.error("Error parsing command line arguments: " + ex.getMessage() + "\n" + argParser.getUsageInformation());
        return ToolsCommonConstants.ReturnValue.FAILURE;
    }
    // The command line arguments were all parsed successfully so return null to continue processing.
    return null;
}
Also used : Option(org.apache.commons.cli.Option) BuildInformation(org.finra.herd.model.api.xml.BuildInformation) ParseException(org.apache.commons.cli.ParseException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

BuildInformation (org.finra.herd.model.api.xml.BuildInformation)9 Test (org.junit.Test)5 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 ParseException (org.apache.commons.cli.ParseException)3 Option (org.apache.commons.cli.Option)2 ArgumentParser (org.finra.herd.core.ArgumentParser)1 Bean (org.springframework.context.annotation.Bean)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1