Example usage for org.apache.commons.lang StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfBlank.

Prototype

public static String defaultIfBlank(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is whitespace, empty ("") or null, the value of defaultStr.

Usage

From source file:org.apache.falcon.regression.ui.search.EntityPage.java

public void checkProcessProperties(ProcessMerlin process) {
    openProperties();//from  ww w .ja v  a  2s .c  om

    final WebElement propertiesBox = propertiesBlock.findElement(By.xpath("//div[@ui-view='processSummary']"));
    UIAssert.assertDisplayed(propertiesBox, "Properties box");
    final List<WebElement> propertiesParts = propertiesBox.findElements(By.xpath("./div"));
    final WebElement generalPropBlock = propertiesParts.get(0);
    final WebElement clusterPropBlock = propertiesParts.get(1);
    final WebElement inputPropBlock = propertiesParts.get(2);
    final WebElement outputPropBlock = propertiesParts.get(3);

    //checking general properties
    final List<WebElement> generalPropParts = generalPropBlock.findElement(By.xpath("./*"))
            .findElements(By.xpath("./*"));
    SoftAssert softAssert = new SoftAssert();
    softAssert.assertEquals(generalPropParts.get(0).getText(), "Process",
            "Unexpected label in general properties.");
    softAssert.assertEquals(generalPropParts.get(1).getText(), "Name",
            "Unexpected label in general properties.");
    softAssert.assertEquals(generalPropParts.get(2).getText(), process.getName(),
            "Unexpected process name in general properties.");
    softAssert.assertEquals(generalPropParts.get(3).getText(), "Tags",
            "Unexpected label in general properties.");
    softAssert.assertEquals(generalPropParts.get(4).getText(),
            StringUtils.defaultIfBlank(process.getTags(), "No tags selected"),
            "Unexpected tags in general properties.");
    softAssert.assertEquals(generalPropParts.get(5).getText(), "Workflow",
            "Unexpected label in general properties.");
    softAssert.assertEquals(generalPropParts.get(6).getText(), "Name\nEngine\nVersion",
            "Unexpected workflow properties in general properties.");
    softAssert.assertEquals(generalPropParts.get(7).getText(),
            String.format("%s%n%s%n%s", StringUtils.defaultIfBlank(process.getWorkflow().getName(), ""),
                    process.getWorkflow().getEngine(), process.getWorkflow().getVersion()),
            "Unexpected workflow properties in general properties.");
    softAssert.assertEquals(generalPropParts.get(7).getText(), "Path",
            "Unexpected label in general properties.");
    softAssert.assertEquals(generalPropParts.get(8).getText(), process.getWorkflow().getPath(),
            "Unexpected workflow path in general properties.");
    softAssert.assertEquals(generalPropParts.get(9).getText(), "Timing",
            "Unexpected label in general properties.");
    softAssert.assertEquals(generalPropParts.get(10).getText(), "Timezone",
            "Unexpected label in general properties.");
    softAssert.assertEquals(generalPropParts.get(12).getText(),
            String.format("Frequency%nEvery %s %s%n", process.getFrequency().getFrequency(),
                    process.getFrequency().getTimeUnit()) + "Max. parallel instances\n" + process.getParallel()
                    + "\nOrder\n" + process.getOrder().toString(),
            "Unexpected frequency/parallel/order info in general properties.");
    softAssert.assertEquals(generalPropParts.get(13).getText(), "Retry",
            "Unexpected label in general properties.");
    final Retry processRetry = process.getRetry();
    softAssert.assertEquals(generalPropParts.get(14).getText(),
            "Policy\n" + processRetry.getPolicy().toString().toLowerCase() + "\nAttempts\n"
                    + processRetry.getAttempts() + "\nDelay\nUp to " + processRetry.getDelay().getFrequency()
                    + " " + processRetry.getDelay().getTimeUnit(),
            "Unexpected policy/attempt/delay in general properties.");

    //checking cluster properties
    final List<WebElement> allClusterProps = clusterPropBlock.findElements(By.xpath("./div/div/div"));
    final WebElement clustersHeading = clusterPropBlock.findElement(By.xpath(".//h5"));
    softAssert.assertEquals(clustersHeading.getText(), "Clusters", "Unexpected label in clusters heading");
    for (WebElement oneClusterProp : allClusterProps) {
        final List<WebElement> clusterPropParts = oneClusterProp.findElements(By.xpath("./*"));
        softAssert.assertEquals(clusterPropParts.get(0).getText(), "Name",
                "Unexpected label in clusters properties");
        final String clusterName = clusterPropParts.get(1).getText();
        final org.apache.falcon.entity.v0.process.Cluster processCluster = process
                .getClusterByName(clusterName);
        softAssert.assertNotNull(processCluster,
                "cluster with name " + clusterName + " was not present in process.");
        softAssert.assertEquals(clusterName, processCluster.getName(),
                "Unexpected cluster name in clusters properties");
        softAssert.assertEquals(clusterPropParts.get(2).getText(), "Validity",
                "Unexpected label in clusters properties");
        softAssert.assertEquals(clusterPropParts.get(3).getText(),
                "Start\n" + processCluster.getValidity().getStart() + "\nEnd\n"
                        + processCluster.getValidity().getEnd(),
                "Unexpected start/end time in clusters properties");
    }
    //checking  inputs properties
    final WebElement inputHeading = inputPropBlock.findElement(By.xpath(".//h5"));
    softAssert.assertEquals(inputHeading.getText(), "Inputs", "Unexpected heading for input properties.");
    final List<WebElement> allInputsProps = inputPropBlock.findElements(By.xpath("./div/div/*"));
    for (WebElement oneInputProps : allInputsProps) {
        final List<WebElement> inputPropParts = oneInputProps.findElements(By.xpath("./*"));
        softAssert.assertEquals(inputPropParts.get(0).getText(), "Name",
                "Unexpected label in input properties");
        final String inputName = inputPropParts.get(1).getText();
        final Input processInput = process.getInputByName(inputName);
        softAssert.assertEquals(inputName, processInput.getName(), "Unexpected input name in input properties");
        softAssert.assertEquals(inputPropParts.get(2).getText(), "Feed",
                "Unexpected label in input properties");
        softAssert.assertEquals(inputPropParts.get(3).getText(), processInput.getFeed(),
                "Unexpected label in input properties");
        softAssert.assertEquals(inputPropParts.get(4).getText(), "Instance",
                "Unexpected label in input properties");
        softAssert.assertEquals(inputPropParts.get(5).getText(),
                "Start\n" + processInput.getStart() + "\nEnd\n" + processInput.getEnd(),
                "Unexpected start/end in input properties");
    }
    final WebElement outputHeading = outputPropBlock.findElement(By.tagName("h5"));
    softAssert.assertEquals(outputHeading.getText(), "Outputs", "Unexpected label for output properties.");
    final List<WebElement> allOutputsProps = outputPropBlock.findElements(By.xpath("./div/div/*"));
    for (WebElement oneOutputProps : allOutputsProps) {
        final List<WebElement> outputPropParts = oneOutputProps.findElements(By.xpath("./*"));
        softAssert.assertEquals(outputPropParts.get(0).getText(), "Name",
                "Unexpected label in output properties");
        final String outputName = outputPropParts.get(1).getText();
        final Output processOutput = process.getOutputByName(outputName);
        softAssert.assertEquals(outputName, processOutput.getName(),
                "Unexpected output name in output properties");
        softAssert.assertEquals(outputPropParts.get(2).getText(), "Feed",
                "Unexpected label in output properties");
        softAssert.assertEquals(outputPropParts.get(3).getText(), processOutput.getFeed(),
                "Unexpected feed name in output properties");
        softAssert.assertEquals(outputPropParts.get(4).getText(), "Instance",
                "Unexpected label in output properties");
        softAssert.assertEquals(outputPropParts.get(5).getText(), processOutput.getInstance(),
                "Unexpected instance in output properties");
        softAssert.assertAll();
    }
}

From source file:org.apache.geode.internal.util.IOUtils.java

/**
 * Gets a fully qualified path with the path elements appended to the specified pathname using the
 * File.separator character. If the pathname is unspecified (null, empty or blank) then path
 * elements are considered relative to file system root, beginning with File.separator. If array
 * of path elements are null, then the pathname is returned as is.
 *
 * @param pathname a String value indicating the base pathname.
 * @param pathElements the path elements to append to pathname.
 * @return the path elements appended to the pathname.
 * @see java.io.File#separator//from w  ww  . j  av a 2  s  .  c  o m
 */
public static String appendToPath(String pathname, final String... pathElements) {
    if (pathElements != null) {
        pathname = StringUtils.defaultIfBlank(pathname, File.separator);

        for (final String pathElement : pathElements) {
            pathname += (pathname.endsWith(File.separator) ? "" : File.separator);
            pathname += pathElement;
        }
    }

    return pathname;
}

From source file:org.apache.geode.management.internal.cli.commands.GfshCommand.java

default String toString(final Boolean condition, final String trueValue, final String falseValue) {
    return Boolean.TRUE.equals(condition) ? StringUtils.defaultIfBlank(trueValue, "true")
            : StringUtils.defaultIfBlank(falseValue, "false");
}

From source file:org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction.java

protected String getDiskStoreName(final Region region) {
    return StringUtils.defaultIfBlank(region.getAttributes().getDiskStoreName(),
            DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
}

From source file:org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction.java

private void setRegionDetails(final Region<?, ?> region, final DiskStore diskStore,
        final DiskStoreDetails diskStoreDetails) {
    if (isUsingDiskStore(region, diskStore)) {
        String regionFullPath = region.getFullPath();
        DiskStoreDetails.RegionDetails regionDetails = new DiskStoreDetails.RegionDetails(regionFullPath,
                StringUtils.defaultIfBlank(region.getName(), regionFullPath));
        regionDetails.setOverflowToDisk(isOverflowToDisk(region));
        regionDetails.setPersistent(isPersistent(region));
        diskStoreDetails.add(regionDetails);
    }/*from  w w  w .j av  a2 s. c om*/

    for (Region<?, ?> subregion : region.subregions(false)) {
        setRegionDetails(subregion, diskStore, diskStoreDetails); // depth-first, recursive strategy
    }
}

From source file:org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction.java

protected String getDiskStoreName(final CacheServer cacheServer) {
    return (cacheServer.getClientSubscriptionConfig() == null ? null
            : StringUtils.defaultIfBlank(cacheServer.getClientSubscriptionConfig().getDiskStoreName(),
                    DiskStoreDetails.DEFAULT_DISK_STORE_NAME));
}

From source file:org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction.java

protected String getDiskStoreName(final GatewaySender gateway) {
    return StringUtils.defaultIfBlank(gateway.getDiskStoreName(), DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
}

From source file:org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction.java

protected void setPdxSerializationDetails(final InternalCache cache, final DiskStore diskStore,
        final DiskStoreDetails diskStoreDetails) {
    if (cache.getPdxPersistent()) {
        String diskStoreName = StringUtils.defaultIfBlank(cache.getPdxDiskStore(),
                DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
        diskStoreDetails// ww  w  . ja  v a2 s.com
                .setPdxSerializationMetaDataStored(ObjectUtils.equals(diskStoreName, diskStore.getName()));
    }
}

From source file:org.apache.geode.management.internal.cli.functions.DescribeDiskStoreFunction.java

protected String getDiskStoreName(final AsyncEventQueue queue) {
    return StringUtils.defaultIfBlank(queue.getDiskStoreName(), DiskStoreDetails.DEFAULT_DISK_STORE_NAME);
}

From source file:org.apache.sentry.api.common.SentryServiceUtil.java

/**
 * Gracefully shut down an Executor service.
 * <p>//w ww  .j a va2s.com
 * This code is based on the Javadoc example for the Executor service.
 * <p>
 * First call shutdown to reject incoming tasks, and then call
 * shutdownNow, if necessary, to cancel any lingering tasks.
 *
 * @param pool the executor service to shut down
 * @param poolName the name of the executor service to shut down to make it easy for debugging
 * @param timeout the timeout interval to wait for its termination
 * @param unit the unit of the timeout
 * @param logger the logger to log the error message if it cannot terminate. It could be null
 */
public static void shutdownAndAwaitTermination(ExecutorService pool, String poolName, long timeout,
        TimeUnit unit, Logger logger) {
    Preconditions.checkNotNull(pool);

    pool.shutdown(); // Disable new tasks from being submitted
    try {
        // Wait a while for existing tasks to terminate
        if (!pool.awaitTermination(timeout, unit)) {
            pool.shutdownNow(); // Cancel currently executing tasks
            // Wait a while for tasks to respond to being cancelled
            if ((!pool.awaitTermination(timeout, unit)) && (logger != null)) {
                logger.error("Executor service {} did not terminate",
                        StringUtils.defaultIfBlank(poolName, "null"));
            }
        }
    } catch (InterruptedException ignored) {
        // (Re-)Cancel if current thread also interrupted
        pool.shutdownNow();
        // Preserve interrupt status
        Thread.currentThread().interrupt();
    }
}