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.sentry.service.thrift.NotificationProcessor.java

/**
 * Processes "alter table" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *//*from  w  w w.  j  a  v  a2 s  . c  o m*/
private boolean processAlterTable(NotificationEvent event) throws Exception {

    if (!hdfsSyncEnabled) {
        return false;
    }

    SentryJSONAlterTableMessage alterTableMessage = deserializer.getAlterTableMessage(event.getMessage());
    String oldDbName = alterTableMessage.getDB();
    String oldTableName = alterTableMessage.getTable();
    String newDbName = event.getDbName();
    String newTableName = event.getTableName();
    String oldLocation = alterTableMessage.getOldLocation();
    String newLocation = alterTableMessage.getNewLocation();

    if ((oldDbName == null) || (oldTableName == null) || (newDbName == null) || (newTableName == null)
            || (oldLocation == null) || (newLocation == null)) {
        LOGGER.error(String.format(
                "Alter table event "
                        + "has incomplete information. oldDbName = %s, oldTableName = %s, oldLocation = %s, "
                        + "newDbName = %s, newTableName = %s, newLocation = %s",
                StringUtils.defaultIfBlank(oldDbName, "null"), StringUtils.defaultIfBlank(oldTableName, "null"),
                StringUtils.defaultIfBlank(oldLocation, "null"), StringUtils.defaultIfBlank(newDbName, "null"),
                StringUtils.defaultIfBlank(newTableName, "null"),
                StringUtils.defaultIfBlank(newLocation, "null")));
        return false;
    }

    if ((oldDbName.equals(newDbName)) && (oldTableName.equals(newTableName))
            && (oldLocation.equals(newLocation))) {
        LOGGER.error(String.format(
                "Alter table notification ignored as neither name nor "
                        + "location has changed: oldAuthzObj = %s, oldLocation = %s, newAuthzObj = %s, "
                        + "newLocation = %s",
                oldDbName + "." + oldTableName, oldLocation, newDbName + "." + newTableName, newLocation));
        return false;
    }

    if (!newDbName.equalsIgnoreCase(oldDbName) || !oldTableName.equalsIgnoreCase(newTableName)) {
        // Name has changed
        try {
            renamePrivileges(oldDbName, oldTableName, newDbName, newTableName);
        } catch (SentryNoSuchObjectException e) {
            LOGGER.info("Rename Sentry privilege ignored as there are no privileges on the table:" + " {}.{}",
                    oldDbName, oldTableName);
        } catch (Exception e) {
            LOGGER.info("Could not process Alter table event. Event: {}", event.toString(), e);
            return false;
        }
    }
    String oldAuthzObj = oldDbName + "." + oldTableName;
    String newAuthzObj = newDbName + "." + newTableName;
    renameAuthzPath(oldAuthzObj, newAuthzObj, oldLocation, newLocation, event);
    return true;
}

From source file:org.apache.sentry.service.thrift.NotificationProcessor.java

/**
 * Processes "add partition" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *///from w ww.j av a  2s. c om
private boolean processAddPartition(NotificationEvent event) throws Exception {
    if (!hdfsSyncEnabled) {
        return false;
    }

    SentryJSONAddPartitionMessage addPartitionMessage = deserializer.getAddPartitionMessage(event.getMessage());
    String dbName = addPartitionMessage.getDB();
    String tableName = addPartitionMessage.getTable();
    List<String> locations = addPartitionMessage.getLocations();
    if ((dbName == null) || (tableName == null) || (locations == null)) {
        LOGGER.error(String.format(
                "Create table event has incomplete information. "
                        + "dbName = %s, tableName = %s, locations = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                locations != null ? locations.toString() : "null"));
        return false;
    }
    String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
    addPaths(authzObj, locations, event);
    return true;
}

From source file:org.apache.sentry.service.thrift.NotificationProcessor.java

/**
 * Processes "drop partition" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *//*from  ww w  .  j ava 2  s  .com*/
private boolean processDropPartition(NotificationEvent event) throws Exception {
    if (!hdfsSyncEnabled) {
        return false;
    }

    SentryJSONDropPartitionMessage dropPartitionMessage = deserializer
            .getDropPartitionMessage(event.getMessage());
    String dbName = dropPartitionMessage.getDB();
    String tableName = dropPartitionMessage.getTable();
    List<String> locations = dropPartitionMessage.getLocations();
    if ((dbName == null) || (tableName == null) || (locations == null)) {
        LOGGER.error(String.format(
                "Drop partition event "
                        + "has incomplete information. dbName = %s, tableName = %s, location = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                locations != null ? locations.toString() : "null"));
        return false;
    }
    String authzObj = SentryServiceUtil.getAuthzObj(dbName, tableName);
    removePaths(authzObj, locations, event);
    return true;
}

From source file:org.apache.sentry.service.thrift.NotificationProcessor.java

/**
 * Processes "alter partition" notification event, and applies its corresponding
 * snapshot change as well as delta path update into Sentry DB.
 *
 * @param event notification event to be processed.
 * @throws Exception if encounters errors while persisting the path change
 *///from   ww w  .ja  v  a2 s.  co m
private boolean processAlterPartition(NotificationEvent event) throws Exception {
    if (!hdfsSyncEnabled) {
        return false;
    }

    SentryJSONAlterPartitionMessage alterPartitionMessage = deserializer
            .getAlterPartitionMessage(event.getMessage());
    String dbName = alterPartitionMessage.getDB();
    String tableName = alterPartitionMessage.getTable();
    String oldLocation = alterPartitionMessage.getOldLocation();
    String newLocation = alterPartitionMessage.getNewLocation();

    if ((dbName == null) || (tableName == null) || (oldLocation == null) || (newLocation == null)) {
        LOGGER.error(String.format(
                "Alter partition event " + "has incomplete information. dbName = %s, tableName = %s, "
                        + "oldLocation = %s, newLocation = %s",
                StringUtils.defaultIfBlank(dbName, "null"), StringUtils.defaultIfBlank(tableName, "null"),
                StringUtils.defaultIfBlank(oldLocation, "null"),
                StringUtils.defaultIfBlank(newLocation, "null")));
        return false;
    }

    if (oldLocation.equals(newLocation)) {
        LOGGER.info(String.format(
                "Alter partition notification ignored as"
                        + "location has not changed: AuthzObj = %s, Location = %s",
                dbName + "." + "." + tableName, oldLocation));
        return false;
    }

    String oldAuthzObj = dbName + "." + tableName;
    renameAuthzPath(oldAuthzObj, oldAuthzObj, oldLocation, newLocation, event);
    return true;
}

From source file:org.apache.solr.handler.clustering.ClusteringComponent.java

@SuppressWarnings("unchecked")
@Override/*w w w.  j  a  va 2 s . c om*/
public void inform(SolrCore core) {
    if (initParams != null) {
        log.info("Initializing Clustering Engines");

        // Our target list of engines, split into search-results and document clustering.
        SolrResourceLoader loader = core.getResourceLoader();

        for (Map.Entry<String, Object> entry : initParams) {
            if ("engine".equals(entry.getKey())) {
                NamedList<Object> engineInitParams = (NamedList<Object>) entry.getValue();
                Boolean optional = engineInitParams.getBooleanArg("optional");
                optional = (optional == null ? Boolean.FALSE : optional);

                String engineClassName = StringUtils.defaultIfBlank((String) engineInitParams.get("classname"),
                        CarrotClusteringEngine.class.getName());

                // Instantiate the clustering engine and split to appropriate map. 
                final ClusteringEngine engine = loader.newInstance(engineClassName, ClusteringEngine.class);
                final String name = StringUtils.defaultIfBlank(engine.init(engineInitParams, core), "");

                if (!engine.isAvailable()) {
                    if (optional) {
                        log.info("Optional clustering engine not available: " + name);
                    } else {
                        throw new SolrException(ErrorCode.SERVER_ERROR,
                                "A required clustering engine failed to initialize, check the logs: " + name);
                    }
                }

                final ClusteringEngine previousEntry;
                if (engine instanceof SearchClusteringEngine) {
                    previousEntry = searchClusteringEngines.put(name, (SearchClusteringEngine) engine);
                } else if (engine instanceof DocumentClusteringEngine) {
                    previousEntry = documentClusteringEngines.put(name, (DocumentClusteringEngine) engine);
                } else {
                    log.warn("Unknown type of a clustering engine for class: " + engineClassName);
                    continue;
                }
                if (previousEntry != null) {
                    log.warn("Duplicate clustering engine component named '" + name + "'.");
                }
            }
        }

        // Set up the default engine key for both types of engines.
        setupDefaultEngine("search results clustering", searchClusteringEngines);
        setupDefaultEngine("document clustering", documentClusteringEngines);

        log.info("Finished Initializing Clustering Engines");
    }
}

From source file:org.apache.solr.handler.component.AlfrescoSolrClusteringComponent.java

@SuppressWarnings("unchecked")
@Override/*from   w ww  . ja v  a  2s  . c  o m*/
public void inform(SolrCore core) {
    if (initParams != null) {
        log.info("Initializing Clustering Engines");

        // Our target list of engines, split into search-results and document clustering.
        SolrResourceLoader loader = core.getResourceLoader();

        for (Map.Entry<String, Object> entry : initParams) {
            if ("engine".equals(entry.getKey())) {
                NamedList<Object> engineInitParams = (NamedList<Object>) entry.getValue();

                String engineClassName = StringUtils.defaultIfBlank((String) engineInitParams.get("classname"),
                        CarrotClusteringEngine.class.getName());

                // Instantiate the clustering engine and split to appropriate map. 
                final ClusteringEngine engine = loader.newInstance(engineClassName, ClusteringEngine.class);
                final String name = StringUtils.defaultIfBlank(engine.init(engineInitParams, core), "");
                final ClusteringEngine previousEntry;
                if (engine instanceof SearchClusteringEngine) {
                    previousEntry = searchClusteringEngines.put(name, (SearchClusteringEngine) engine);
                } else if (engine instanceof DocumentClusteringEngine) {
                    previousEntry = documentClusteringEngines.put(name, (DocumentClusteringEngine) engine);
                } else {
                    log.warn("Unknown type of a clustering engine for class: " + engineClassName);
                    continue;
                }
                if (previousEntry != null) {
                    log.warn("Duplicate clustering engine component named '" + name + "'.");
                }
            }
        }

        // Set up the default engine key for both types of engines.
        setupDefaultEngine("search results clustering", searchClusteringEngines);
        setupDefaultEngine("document clustering", documentClusteringEngines);

        log.info("Finished Initializing Clustering Engines");
    }
}

From source file:org.beangle.ems.log.service.BusinessEventLogger.java

public void onApplicationEvent(BusinessEvent event) {
    BusinessLogBean log = new BusinessLogBean();
    log.setOperateAt(event.getIssueAt());
    log.setOperation(StringUtils.defaultIfBlank(event.getDescription(), "  "));
    log.setResource(StringUtils.defaultIfBlank(event.getResource(), "  "));
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    if (null == auth)
        return;//  w ww . j a  v a2  s  . c  om
    log.setOperator(auth.getName());
    Object details = auth.getDetails();
    if ((details instanceof WebAuthenticationDetails)) {
        WebAuthenticationDetails webDetails = (WebAuthenticationDetails) details;
        log.setIp(webDetails.getAgent().getIp());
        log.setAgent(webDetails.getAgent().getOs() + " " + webDetails.getAgent().getBrowser());
        log.setEntry(sessionRegistry.getResource(webDetails.getSessionId()));
    }
    if (null != event.getDetail()) {
        log.setDetail(new BusinessLogDetailBean(log, event.getDetail()));
    }
    if (StringUtils.isEmpty(log.getEntry())) {
        log.setEntry("empty");
    }
    entityDao.saveOrUpdate(log);
}

From source file:org.biouno.unochoice.CascadeChoiceParameter.java

/**
 * Constructor called from Jelly with parameters.
 *
 * @param name name/*from   w  w  w.  ja  v  a2 s  .  com*/
 * @param description description
 * @param script script
 * @param choiceType choice type
 * @param referencedParameters referenced parameters
 * @param filterable filter flag
 * @deprecated see JENKINS-32149
 */
public CascadeChoiceParameter(String name, String description, Script script, String choiceType,
        String referencedParameters, Boolean filterable) {
    super(name, description, script, referencedParameters);
    this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
    this.filterable = filterable;
}

From source file:org.biouno.unochoice.CascadeChoiceParameter.java

/**
 * Constructor called from Jelly with parameters.
 *
 * @param name name/*from www  .  ja va2s  . c  o m*/
 * @param description description
 * @param randomName parameter random generated name (uuid)
 * @param script script
 * @param choiceType choice type
 * @param referencedParameters referenced parameters
 * @param filterable filter flag
 */
@DataBoundConstructor
public CascadeChoiceParameter(String name, String description, String randomName, Script script,
        String choiceType, String referencedParameters, Boolean filterable) {
    super(name, description, randomName, script, referencedParameters);
    this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
    this.filterable = filterable;
}

From source file:org.biouno.unochoice.ChoiceParameter.java

/**
 * Constructor called from Jelly with parameters.
 *
 * @param name name/*from w w w  .j a va 2  s  .  c  om*/
 * @param description description
 * @param script script
 * @param choiceType choice type
 * @param filterable filter flag
 * @deprecated see JENKINS-32149
 */
public ChoiceParameter(String name, String description, Script script, String choiceType, Boolean filterable) {
    super(name, description, script);
    this.choiceType = StringUtils.defaultIfBlank(choiceType, PARAMETER_TYPE_SINGLE_SELECT);
    this.filterable = filterable;
}