use of org.apache.commons.lang3.StringUtils.isNoneBlank in project cas by apereo.
the class LdapUtils method newLdaptivePooledConnectionFactory.
/**
* New pooled connection factory pooled connection factory.
*
* @param l the ldap properties
* @return the pooled connection factory
*/
public static PooledConnectionFactory newLdaptivePooledConnectionFactory(final AbstractLdapProperties l) {
val cc = newLdaptiveConnectionConfig(l);
LOGGER.debug("Creating LDAP connection pool configuration for [{}]", l.getLdapUrl());
val pooledCf = new PooledConnectionFactory(cc);
pooledCf.setMinPoolSize(l.getMinPoolSize());
pooledCf.setMaxPoolSize(l.getMaxPoolSize());
pooledCf.setValidateOnCheckOut(l.isValidateOnCheckout());
pooledCf.setValidatePeriodically(l.isValidatePeriodically());
pooledCf.setBlockWaitTime(Beans.newDuration(l.getBlockWaitTime()));
val strategy = new IdlePruneStrategy();
strategy.setIdleTime(Beans.newDuration(l.getIdleTime()));
strategy.setPrunePeriod(Beans.newDuration(l.getPrunePeriod()));
pooledCf.setPruneStrategy(strategy);
val validator = l.getValidator();
switch(validator.getType().trim().toLowerCase()) {
case "compare":
val compareRequest = new CompareRequest(validator.getDn(), validator.getAttributeName(), validator.getAttributeValue());
val compareValidator = new CompareConnectionValidator(compareRequest);
compareValidator.setValidatePeriod(Beans.newDuration(l.getValidatePeriod()));
compareValidator.setValidateTimeout(Beans.newDuration(l.getValidateTimeout()));
pooledCf.setValidator(compareValidator);
break;
case "none":
LOGGER.debug("No validator is configured for the LDAP connection pool of [{}]", l.getLdapUrl());
break;
case "search":
default:
val searchRequest = new SearchRequest();
searchRequest.setBaseDn(validator.getBaseDn());
searchRequest.setFilter(validator.getSearchFilter());
searchRequest.setReturnAttributes(ReturnAttributes.NONE.value());
searchRequest.setSearchScope(SearchScope.valueOf(validator.getScope()));
searchRequest.setSizeLimit(1);
val searchValidator = new SearchConnectionValidator(searchRequest);
searchValidator.setValidatePeriod(Beans.newDuration(l.getValidatePeriod()));
searchValidator.setValidateTimeout(Beans.newDuration(l.getValidateTimeout()));
pooledCf.setValidator(searchValidator);
break;
}
pooledCf.setFailFastInitialize(l.isFailFast());
if (StringUtils.isNotBlank(l.getPoolPassivator())) {
val pass = AbstractLdapProperties.LdapConnectionPoolPassivator.valueOf(l.getPoolPassivator().toUpperCase());
switch(pass) {
case BIND:
if (StringUtils.isNotBlank(l.getBindDn()) && StringUtils.isNoneBlank(l.getBindCredential())) {
val bindRequest = new SimpleBindRequest(l.getBindDn(), l.getBindCredential());
pooledCf.setPassivator(new BindConnectionPassivator(bindRequest));
LOGGER.debug("Created [{}] passivator for [{}]", l.getPoolPassivator(), l.getLdapUrl());
} else {
val values = Arrays.stream(AbstractLdapProperties.LdapConnectionPoolPassivator.values()).filter(v -> v != AbstractLdapProperties.LdapConnectionPoolPassivator.BIND).collect(Collectors.toList());
LOGGER.warn("[{}] pool passivator could not be created for [{}] given bind credentials are not specified. " + "If you are dealing with LDAP in such a way that does not require bind credentials, you may need to " + "set the pool passivator setting to one of [{}]", l.getPoolPassivator(), l.getLdapUrl(), values);
}
break;
default:
break;
}
}
LOGGER.debug("Initializing ldap connection pool for [{}] and bindDn [{}]", l.getLdapUrl(), l.getBindDn());
pooledCf.initialize();
return pooledCf;
}
use of org.apache.commons.lang3.StringUtils.isNoneBlank in project cas by apereo.
the class LdapUtils method newLdaptiveBlockingConnectionPool.
/**
* New blocking connection pool connection pool.
*
* @param l the l
* @return the connection pool
*/
public static ConnectionPool newLdaptiveBlockingConnectionPool(final AbstractLdapProperties l) {
final DefaultConnectionFactory bindCf = newLdaptiveConnectionFactory(l);
final PoolConfig pc = newLdaptivePoolConfig(l);
final BlockingConnectionPool cp = new BlockingConnectionPool(pc, bindCf);
cp.setBlockWaitTime(Beans.newDuration(l.getBlockWaitTime()));
cp.setPoolConfig(pc);
final IdlePruneStrategy strategy = new IdlePruneStrategy();
strategy.setIdleTime(Beans.newDuration(l.getIdleTime()));
strategy.setPrunePeriod(Beans.newDuration(l.getPrunePeriod()));
cp.setPruneStrategy(strategy);
switch(l.getValidator().getType().trim().toLowerCase()) {
case "compare":
final CompareRequest compareRequest = new CompareRequest();
compareRequest.setDn(l.getValidator().getDn());
compareRequest.setAttribute(new LdapAttribute(l.getValidator().getAttributeName(), l.getValidator().getAttributeValues().toArray(new String[] {})));
compareRequest.setReferralHandler(new SearchReferralHandler());
cp.setValidator(new CompareValidator(compareRequest));
break;
case "none":
LOGGER.debug("No validator is configured for the LDAP connection pool of [{}]", l.getLdapUrl());
break;
case "search":
default:
final SearchRequest searchRequest = new SearchRequest();
searchRequest.setBaseDn(l.getValidator().getBaseDn());
searchRequest.setSearchFilter(new SearchFilter(l.getValidator().getSearchFilter()));
searchRequest.setReturnAttributes(ReturnAttributes.NONE.value());
searchRequest.setSearchScope(SearchScope.valueOf(l.getValidator().getScope()));
searchRequest.setSizeLimit(1L);
searchRequest.setReferralHandler(new SearchReferralHandler());
cp.setValidator(new SearchValidator(searchRequest));
break;
}
cp.setFailFastInitialize(l.isFailFast());
if (StringUtils.isNotBlank(l.getPoolPassivator())) {
final AbstractLdapProperties.LdapConnectionPoolPassivator pass = AbstractLdapProperties.LdapConnectionPoolPassivator.valueOf(l.getPoolPassivator().toUpperCase());
switch(pass) {
case CLOSE:
cp.setPassivator(new ClosePassivator());
LOGGER.debug("Created [{}] passivator for [{}]", l.getPoolPassivator(), l.getLdapUrl());
break;
case BIND:
if (StringUtils.isNotBlank(l.getBindDn()) && StringUtils.isNoneBlank(l.getBindCredential())) {
final BindRequest bindRequest = new BindRequest();
bindRequest.setDn(l.getBindDn());
bindRequest.setCredential(new Credential(l.getBindCredential()));
cp.setPassivator(new BindPassivator(bindRequest));
LOGGER.debug("Created [{}] passivator for [{}]", l.getPoolPassivator(), l.getLdapUrl());
} else {
final List values = Arrays.stream(AbstractLdapProperties.LdapConnectionPoolPassivator.values()).filter(v -> v != AbstractLdapProperties.LdapConnectionPoolPassivator.BIND).collect(Collectors.toList());
LOGGER.warn("[{}] pool passivator could not be created for [{}] given bind credentials are not specified. " + "If you are dealing with LDAP in such a way that does not require bind credentials, you may need to " + "set the pool passivator setting to one of [{}]", l.getPoolPassivator(), l.getLdapUrl(), values);
}
break;
default:
break;
}
}
LOGGER.debug("Initializing ldap connection pool for [{}] and bindDn [{}]", l.getLdapUrl(), l.getBindDn());
cp.initialize();
return cp;
}
use of org.apache.commons.lang3.StringUtils.isNoneBlank in project eol-globi-data by jhpoelen.
the class DOIResolverCache method init.
void init(final Reader reader) throws PropertyEnricherException, IOException {
DB db = initDb("doiCache");
StopWatch watch = new StopWatch();
watch.start();
final CSVParser parser = CSVTSVUtil.createTSVParser(reader);
LOG.info("doi cache building...");
doiCitationMap = db.createTreeMap("doiCache").pumpPresort(300000).pumpIgnoreDuplicates().pumpSource(new Iterator<Fun.Tuple2<String, String>>() {
private String[] line;
String getCitation(String[] line) {
return line[1];
}
String getDOI(String[] line) {
return line[0];
}
@Override
public boolean hasNext() {
try {
do {
line = parser.getLine();
} while (line != null && line.length > 1 && !StringUtils.isNoneBlank(getCitation(line), getDOI(line)));
boolean hasNext = line != null && line.length > 1 && StringUtils.isNoneBlank(getCitation(line), getDOI(line));
if (!hasNext) {
System.out.println("[no more]");
}
return hasNext;
} catch (IOException e) {
LOG.error("problem reading", e);
return false;
}
}
@Override
public Fun.Tuple2<String, String> next() {
String citationString = StringUtils.defaultString(line[1], "");
String doi = StringUtils.defaultString(line[0], "");
return new Fun.Tuple2<>(citationString, doi);
}
}).make();
watch.stop();
LOG.info("doi cache built in [" + watch.getTime() / 1000 + "] s.");
}
use of org.apache.commons.lang3.StringUtils.isNoneBlank in project azure-tools-for-java by Microsoft.
the class AzureSdkLibraryService method loadAzureSDKEntities.
public static List<AzureJavaSdkEntity> loadAzureSDKEntities(final URL destination) {
try {
final ObjectReader reader = CSV_MAPPER.readerFor(AzureJavaSdkEntity.class).with(CsvSchema.emptySchema().withHeader());
final MappingIterator<AzureJavaSdkEntity> data = reader.readValues(destination);
return data.readAll().stream().filter(e -> StringUtils.isNoneBlank(e.getArtifactId(), e.getGroupId())).collect(Collectors.toList());
} catch (final IOException e) {
log.warn(String.format("failed to load Azure SDK list from \"%s\"", destination.toString()), e);
}
return Collections.emptyList();
}
use of org.apache.commons.lang3.StringUtils.isNoneBlank in project azure-tools-for-java by Microsoft.
the class AzurePlugin method runActivity.
@Override
public void runActivity(@NotNull Project project) {
// read legacy settings from old data.xml
final String installationId = "wangmi-azure-intellij-plugin-base";
final String pluginVersion = "0.0.1-SNAPSHOT";
// check non-empty for valid data.xml
if (StringUtils.isNoneBlank(installationId, pluginVersion)) {
final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
IntellijStore.getInstance().loadState(config);
}
final IntellijStore.AzureConfigurationData config = IntellijStore.getInstance().getState();
String installationID = InstallationIdUtils.getHashMac();
if (StringUtils.isBlank(installationID)) {
installationID = StringUtils.firstNonBlank(InstallationIdUtils.getHashMac(), InstallationIdUtils.hash(PermanentInstallationID.get()));
}
final String userAgent = String.format(USER_AGENT, PLUGIN_VERSION, installationID);
Azure.az().config().setLogLevel("NONE");
Azure.az().config().setUserAgent(userAgent);
final AnAction action = ActionManager.getInstance().getAction(WhatsNewAction.ID);
final DataContext context = dataId -> CommonDataKeys.PROJECT.getName().equals(dataId) ? project : null;
AzureTaskManager.getInstance().runLater(() -> ActionUtil.invokeAction(action, context, "AzurePluginStartupActivity", null, null));
}
Aggregations