List of usage examples for org.apache.commons.lang3 StringUtils startsWith
public static boolean startsWith(final CharSequence str, final CharSequence prefix)
Check if a CharSequence starts with a specified prefix.
null s are handled without exceptions.
From source file:org.apache.atlas.web.rest.DiscoveryREST.java
private String escapeTypeName(String typeName) { String ret;//from www. j av a 2s .co m if (StringUtils.startsWith(typeName, "`") && StringUtils.endsWith(typeName, "`")) { ret = typeName; } else { ret = String.format("`%s`", typeName); } return ret; }
From source file:org.apache.hive.hcatalog.templeton.LauncherDelegator.java
private boolean killTempletonJobWithRetry(String user, String jobId) { /*/*from ww w.ja v a2 s . c o m*/ * Make null safe Check if the job submission has gone through and if job is valid. */ if (StringUtils.startsWith(jobId, "job_")) { LOG.info("Started killing the job " + jobId); boolean success = false; int count = 0; do { try { count++; killJob(user, jobId); success = true; LOG.info("Kill job attempt succeeded."); } catch (Exception e) { LOG.info("Failed to kill the job due to exception: " + e.getMessage()); LOG.info("Waiting for " + jobTimeoutTaskRetryIntervalInSec + "s before retrying " + "the operation. Iteration: " + count); try { Thread.sleep(jobTimeoutTaskRetryIntervalInSec * 1000); } catch (InterruptedException ex) { LOG.info("Got interrupted while waiting for next retry."); } } } while (!success && count < jobTimeoutTaskRetryCount); return success; } else { LOG.info("Couldn't find a valid job id after job request is timed out."); return false; } }
From source file:org.apache.marmotta.platform.core.services.importer.ImportWatchServiceImpl.java
/** * Get the target context. /*w ww .j a va 2s . co m*/ * The algorithm is as follows: * <ol> * <li>check for a file "conf" (configurable, see {@link #CONFIG_KEY_CONF_FILE}) which specifies * the target content using {@link Properties} syntax (key {@code context}), then use is; or * <li>check if the sub-directory is a url-encoded URI, then use it; or * <li>construct the context by using {@link ConfigurationService#getBaseContext()} and the relative sub-dirs and use it; or * <li>use the default context as a general fallback. * </ol> * * @param file the file * @return the context URI * @throws URISyntaxException */ private URI getTargetContext(Path file) throws URISyntaxException { // Check for a configFile final Path config = file.getParent() .resolve(configurationService.getStringConfiguration(CONFIG_KEY_CONF_FILE, "config")); if (Files.isReadable(config)) { Properties prop = loadConfigFile(file); final String _c = prop.getProperty("context"); if (_c != null) { try { URI context = contextService.createContext(_c); log.debug("using context {} from config file {}", context, config); return context; } catch (URISyntaxException e) { log.warn("invalid context {} in config file {}, ignoring", _c, config); } } else { log.trace("no context defined in config file {}", config); } } // Check for url-encoded directory Path subDir = getImportRoot().relativize(file.getParent()); if (StringUtils.isBlank(subDir.toString())) { log.trace("using default context for file {}", file); return contextService.getDefaultContext(); } else if (StringUtils.startsWith(subDir.toString(), "http%3A%2F%2F")) { log.debug("using url-encoded context {} for import of {}", subDir, file); try { return contextService.createContext(URLDecoder.decode(subDir.toString(), "UTF-8")); } catch (UnsupportedEncodingException e) { log.error("Error url-decoding context name '{}', so using the default one: {}", subDir, e.getMessage()); return contextService.getDefaultContext(); } } else { final String _c = String.format("%s/%s", configurationService.getBaseContext().replaceFirst("/$", ""), subDir); final URI context = contextService.createContext(_c); log.debug("using context {} based on relative subdir {} for file {}", context, subDir, file); return context; } }
From source file:org.apache.metron.common.stellar.shell.StellarShell.java
/** * Is a given expression a built-in magic? * @param expression The expression.//from w w w. j ava2s . com */ private boolean isMagic(String expression) { return StringUtils.startsWith(expression, MAGIC_PREFIX); }
From source file:org.apache.metron.common.stellar.shell.StellarShell.java
/** * Is a given expression asking for function documentation? * @param expression The expression.//from w w w . j a v a 2 s .c om */ private boolean isDoc(String expression) { return StringUtils.startsWith(expression, DOC_PREFIX); }
From source file:org.apache.metron.stellar.common.shell.specials.DocCommand.java
@Override public Function<String, Boolean> getMatcher() { return (input) -> StringUtils.startsWith(input, DOC_PREFIX); }
From source file:org.apache.nifi.authorization.util.IdentityMappingUtil.java
/** * Builds the identity mappings from NiFiProperties. * * @param properties the NiFiProperties instance * @return a list of identity mappings/*w w w .java 2 s . com*/ */ public static List<IdentityMapping> getIdentityMappings(final NiFiProperties properties) { final List<IdentityMapping> mappings = new ArrayList<>(); // go through each property for (String propertyName : properties.getPropertyKeys()) { if (StringUtils.startsWith(propertyName, NiFiProperties.SECURITY_IDENTITY_MAPPING_PATTERN_PREFIX)) { final String key = StringUtils.substringAfter(propertyName, NiFiProperties.SECURITY_IDENTITY_MAPPING_PATTERN_PREFIX); final String identityPattern = properties.getProperty(propertyName); if (StringUtils.isBlank(identityPattern)) { LOGGER.warn("Identity Mapping property {} was found, but was empty", new Object[] { propertyName }); continue; } final String identityValueProperty = NiFiProperties.SECURITY_IDENTITY_MAPPING_VALUE_PREFIX + key; final String identityValue = properties.getProperty(identityValueProperty); if (StringUtils.isBlank(identityValue)) { LOGGER.warn("Identity Mapping property {} was found, but corresponding value {} was not found", new Object[] { propertyName, identityValueProperty }); continue; } final IdentityMapping identityMapping = new IdentityMapping(key, Pattern.compile(identityPattern), identityValue); mappings.add(identityMapping); LOGGER.debug("Found Identity Mapping with key = {}, pattern = {}, value = {}", new Object[] { key, identityPattern, identityValue }); } } // sort the list by the key so users can control the ordering in nifi.properties Collections.sort(mappings, new Comparator<IdentityMapping>() { @Override public int compare(IdentityMapping m1, IdentityMapping m2) { return m1.getKey().compareTo(m2.getKey()); } }); return mappings; }
From source file:org.apache.nifi.registry.properties.util.IdentityMappingUtil.java
/** * Builds the identity mappings from NiFiRegistryProperties. * * @param properties the NiFiRegistryProperties instance * @return a list of identity mappings// w ww. ja v a2s. c om */ public static List<IdentityMapping> getIdentityMappings(final NiFiRegistryProperties properties) { final List<IdentityMapping> mappings = new ArrayList<>(); // go through each property for (String propertyName : properties.getPropertyKeys()) { if (StringUtils.startsWith(propertyName, NiFiRegistryProperties.SECURITY_IDENTITY_MAPPING_PATTERN_PREFIX)) { final String key = StringUtils.substringAfter(propertyName, NiFiRegistryProperties.SECURITY_IDENTITY_MAPPING_PATTERN_PREFIX); final String identityPattern = properties.getProperty(propertyName); if (StringUtils.isBlank(identityPattern)) { LOGGER.warn("Identity Mapping property {} was found, but was empty", new Object[] { propertyName }); continue; } final String identityValueProperty = NiFiRegistryProperties.SECURITY_IDENTITY_MAPPING_VALUE_PREFIX + key; final String identityValue = properties.getProperty(identityValueProperty); if (StringUtils.isBlank(identityValue)) { LOGGER.warn("Identity Mapping property {} was found, but corresponding value {} was not found", new Object[] { propertyName, identityValueProperty }); continue; } final IdentityMapping identityMapping = new IdentityMapping(key, Pattern.compile(identityPattern), identityValue); mappings.add(identityMapping); LOGGER.debug("Found Identity Mapping with key = {}, pattern = {}, value = {}", new Object[] { key, identityPattern, identityValue }); } } // sort the list by the key so users can control the ordering in nifi-registry.properties Collections.sort(mappings, new Comparator<IdentityMapping>() { @Override public int compare(IdentityMapping m1, IdentityMapping m2) { return m1.getKey().compareTo(m2.getKey()); } }); return mappings; }
From source file:org.apache.nifi.web.security.jwt.JwtAuthenticationFilter.java
@Override public Authentication attemptAuthentication(final HttpServletRequest request) { // only support jwt login when running securely if (!request.isSecure()) { return null; }// w w w .ja va 2s . co m // TODO: Refactor request header extraction logic to shared utility as it is duplicated in AccessResource // get the principal out of the user token final String authorization = request.getHeader(AUTHORIZATION); // if there is no authorization header, we don't know the user if (authorization == null || !StringUtils.startsWith(authorization, BEARER)) { return null; } else { // Extract the Base64 encoded token from the Authorization header final String token = StringUtils.substringAfterLast(authorization, " "); return new JwtAuthenticationRequestToken(token, request.getRemoteAddr()); } }
From source file:org.apache.phoenix.pherf.RuleGeneratorTest.java
@Test public void testRuleOverrides() throws Exception { XMLConfigParser parser = new XMLConfigParser(matcherScenario); WriteWorkload loader = new WriteWorkload(parser); RulesApplier rulesApplier = loader.getRulesApplier(); Scenario scenario = parser.getScenarios().get(0); // We should be able to find the correct rule based only on Type and Name combination // Test CHAR/* w ww.j a v a 2 s . c o m*/ Column simPhxCol = new Column(); simPhxCol.setName("OTHER_ID"); simPhxCol.setType(DataTypeMapping.CHAR); // Get the rule we expect to match Column rule = rulesApplier.getRule(simPhxCol); assertEquals("Did not find the correct rule.", rule.getName(), simPhxCol.getName()); assertEquals("Did not find the matching rule type.", rule.getType(), simPhxCol.getType()); assertEquals("Rule contains incorrect length.", rule.getLength(), 8); assertEquals("Rule contains incorrect prefix.", rule.getPrefix(), "z0Oxx00"); DataValue value = rulesApplier.getDataForRule(scenario, simPhxCol); assertEquals("Value returned does not match rule.", value.getValue().length(), 8); // Test VARCHAR with RANDOM and prefix simPhxCol.setName("OLDVAL_STRING"); simPhxCol.setType(DataTypeMapping.VARCHAR); // Get the rule we expect to match rule = rulesApplier.getRule(simPhxCol); assertEquals("Did not find the correct rule.", rule.getName(), simPhxCol.getName()); assertEquals("Did not find the matching rule type.", rule.getType(), simPhxCol.getType()); assertEquals("Rule contains incorrect length.", rule.getLength(), 10); assertEquals("Rule contains incorrect prefix.", rule.getPrefix(), "MYPRFX"); value = rulesApplier.getDataForRule(scenario, simPhxCol); assertEquals("Value returned does not match rule.", value.getValue().length(), 10); assertTrue("Value returned start with prefix.", StringUtils.startsWith(value.getValue(), rule.getPrefix())); }