List of usage examples for org.apache.commons.lang3 StringUtils trim
public static String trim(final String str)
Removes control characters (char <= 32) from both ends of this String, handling null by returning null .
The String is trimmed using String#trim() .
From source file:de.micromata.tpsb.project.TpsbProjectCatalog.java
/** * Inits the from local settings.//from w w w. j a v a2 s .c om */ public void initFromLocalSettings() { readGlobalOptions(); LocalSettings ls = LocalSettings.get(); List<String> pns = ls.getKeysPrefixWithInfix("genome.tpsb.project", "name"); for (String k : pns) { String key = k + ".name"; String name = ls.get(key); key = k + ".projectroot"; String projectRoot = ls.get(key); if (StringUtils.isBlank(projectRoot) == true) { log.warn(" No projektroot defined for: " + key); continue; } File projectRootFile = new File(projectRoot); if (projectRootFile.exists() == false) { log.warn(" Projectroot does not exists: " + projectRootFile.getAbsolutePath()); continue; } key = k + ".srcprojectroots"; String sources = ls.get(key); List<String> sourceList = new ArrayList<String>(); if (StringUtils.isBlank(sources) == false) { List<String> tl = Arrays.asList(StringUtils.split(sources, ',')); for (String s : tl) { File srcDir = new File(s); if (srcDir.exists() == false) { log.warn("Source dir defined in localsettings doesn't exist: " + srcDir.getAbsolutePath()); continue; } sourceList.add(s); } } else { sourceList = getDirsIfExists(projectRootFile, "src/test/java", "src/main/java"); } key = k + ".tpsbrepo"; String repos = ls.get(key); if (StringUtils.isBlank(repos) == true) { repos = new File(projectRootFile, "tpsbrepo").getAbsolutePath(); } List<String> repoLista = Arrays.asList(StringUtils.split(repos, ',')); List<String> repoList = new ArrayList<String>(); repoList.addAll(repoLista); for (String repo : repoList) { File repoFile = new File(repo); if (repoFile.exists() == false) { log.warn("Repo defined in localsettings doesn't exist: " + repoFile.getAbsolutePath()); continue; } } if (repoList.isEmpty() == true) { log.warn("No Repositories are defined"); continue; } key = k + ".srcgentarget"; String sourcegen = ls.get(key); if (StringUtils.isBlank(sourcegen) == true) { sourcegen = new File(projectRootFile, "src/test/java").getAbsolutePath(); } key = k + ".imports"; String imports = ls.get(key); List<String> importList = new ArrayList<String>(); if (StringUtils.isNotBlank(imports) == true) { importList = Arrays.asList(StringUtils.split(imports, ',')); } String first = repoList.get(0); repoList.remove(0); TpsbProject project = new TpsbProject(name, projectRoot, first, repoList, sourceList, sourcegen); project.getImportedProjects().addAll(importList); key = k + ".noTestCases"; project.setNoTestCases(ls.getBooleanValue(key, false)); key = k + ".addcp"; String adcp = ls.get(key); if (StringUtils.isNotBlank(adcp) == true) { List<String> addcp = Arrays.asList(StringUtils.split(adcp, ',')); for (String a : addcp) { a = StringUtils.trim(a); File srcDir = new File(a); if (srcDir.exists() == false) { log.warn("Cp dir or jar defined in localsettings doesn't exist: " + srcDir.getAbsolutePath()); continue; } project.getRuntimeCps().add(a); } } projects.put(name, project); } resolveProjectDeps(); }
From source file:com.ottogroup.bi.spqr.pipeline.component.operator.DelayedResponseOperatorRuntimeEnvironment.java
/** * Initializes the runtime environment using the provided input * @param processingNodeId/*from w w w.j a va 2s . c om*/ * @param pipelineId * @param delayedResponseOperator * @param responseWaitStrategy * @param queueConsumer * @param queueProducer * @param executorService * @throws RequiredInputMissingException */ public DelayedResponseOperatorRuntimeEnvironment(final String processingNodeId, final String pipelineId, final DelayedResponseOperator delayedResponseOperator, final DelayedResponseOperatorWaitStrategy responseWaitStrategy, final StreamingMessageQueueConsumer queueConsumer, final StreamingMessageQueueProducer queueProducer, final ExecutorService executorService) throws RequiredInputMissingException { ///////////////////////////////////////////////////////////// // input validation if (StringUtils.isBlank(processingNodeId)) throw new RequiredInputMissingException("Missing required processing node identifier"); if (StringUtils.isBlank(pipelineId)) throw new RequiredInputMissingException("Missing required pipeline identifier"); if (delayedResponseOperator == null) throw new RequiredInputMissingException("Missing required direct delayed operator"); if (responseWaitStrategy == null) throw new RequiredInputMissingException("Missing required response wait strategy"); if (queueConsumer == null) throw new RequiredInputMissingException("Missing required queue consumer"); if (queueProducer == null) throw new RequiredInputMissingException("Missing required queue producer"); // ///////////////////////////////////////////////////////////// this.processingNodeId = StringUtils.lowerCase(StringUtils.trim(processingNodeId)); this.pipelineId = StringUtils.lowerCase(StringUtils.trim(pipelineId)); this.operatorId = StringUtils.lowerCase(StringUtils.trim(delayedResponseOperator.getId())); this.delayedResponseOperator = delayedResponseOperator; this.responseWaitStrategy = responseWaitStrategy; this.responseWaitStrategy.setDelayedResponseCollector(this); this.delayedResponseOperator.setWaitStrategy(this.responseWaitStrategy); this.queueConsumer = queueConsumer; this.queueProducer = queueProducer; this.executorService = executorService; this.executorService.submit(this.responseWaitStrategy); this.running = true; this.consumerQueueWaitStrategy = queueConsumer.getWaitStrategy(); this.destinationQueueWaitStrategy = queueProducer.getWaitStrategy(); if (logger.isDebugEnabled()) logger.debug("delayed response operator init [node=" + this.processingNodeId + ", pipeline=" + this.pipelineId + ", operator=" + this.operatorId + "]"); }
From source file:com.webbfontaine.valuewebb.search.custom.UserCriterion.java
public Criterion getCriterion() throws Exception { if (condition.equals(EQ)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNull(fullKey); } else {/*from w w w . j a v a2 s.c o m*/ return Restrictions.eq(fullKey, value); } } if (condition.equals(NE)) { if (value == null || value.toString().trim().length() == 0) { return Restrictions.isNotNull(fullKey); } else { return Restrictions.ne(fullKey, value); } } if (condition.equals(GT)) { assertNonNullity(value); return Restrictions.gt(fullKey, value); } if (condition.equals(GE)) { assertNonNullity(value); return Restrictions.ge(fullKey, value); } if (condition.equals(LT)) { assertNonNullity(value); return Restrictions.lt(fullKey, value); } if (condition.equals(LE)) { assertNonNullity(value); return Restrictions.le(fullKey, value); } if (condition.equals(IN_A_RANGE)) { assertNonNullity(value); assertNonNullity(diff); return getPercentRange(); } if (condition.equals(ENDS_WITH)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString())); } if (condition.equals(STARTS_WITH)) { return Restrictions.like(fullKey, StringUtils.trim(value.toString()) + "%"); } if (condition.equals(CONTAINS)) { return Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%'); } if (condition.equals(NOT_CONTAIN)) { return Restrictions.not(Restrictions.like(fullKey, "%" + StringUtils.trim(value.toString()) + '%')); } LOGGER.error( "Undefined User Criteria [key:{0}, value:{1}, condition:{3}] couldn't be transformed to search criterion", fullKey, value, condition); throw new RuntimeException("Undefined User Criteria: " + name); }
From source file:com.ottogroup.bi.spqr.node.resource.pipeline.MicroPipelineResource.java
/** * Creates or updates a pipeline for the given identifier and {@link MicroPipelineConfiguration} * @param pipelineId/*from w w w .ja va2s . c o m*/ * @param configuration * @return */ @Produces(value = "application/json") @Timed(name = "pipeline-instantiation") @PUT @Path("{pipelineId}") public MicroPipelineInstantiationResponse updatePipeline(@PathParam("pipelineId") final String pipelineId, final MicroPipelineConfiguration configuration) { if (StringUtils.isBlank(pipelineId)) return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.MISSING_CONFIGURATION, ERROR_MSG_PIPELINE_ID_MISSING); if (configuration == null) return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.MISSING_CONFIGURATION, ERROR_MSG_PIPELINE_CONFIGURATION_MISSING); if (!StringUtils.equalsIgnoreCase(StringUtils.trim(pipelineId), configuration.getId())) return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.PIPELINE_INITIALIZATION_FAILED, ERROR_MSG_PIPELINE_IDS_DIFFER); try { // shutdown running instance of pipeline if (this.microPipelineManager.hasPipeline(pipelineId)) { this.microPipelineManager.shutdownPipeline(pipelineId); } String id = this.microPipelineManager.executePipeline(configuration); return new MicroPipelineInstantiationResponse(id, MicroPipelineValidationResult.OK, ""); } catch (RequiredInputMissingException e) { return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.MISSING_CONFIGURATION, e.getMessage()); } catch (QueueInitializationFailedException e) { return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.QUEUE_INITIALIZATION_FAILED, e.getMessage()); } catch (ComponentInitializationFailedException e) { return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.COMPONENT_INITIALIZATION_FAILED, e.getMessage()); } catch (PipelineInstantiationFailedException e) { return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.PIPELINE_INITIALIZATION_FAILED, e.getMessage()); } catch (NonUniqueIdentifierException e) { return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.NON_UNIQUE_PIPELINE_ID, e.getMessage()); } catch (Exception e) { return new MicroPipelineInstantiationResponse(pipelineId, MicroPipelineValidationResult.TECHNICAL_ERROR, e.getMessage()); } }
From source file:com.ottogroup.bi.spqr.operator.twitter.source.TwitterStreamSource.java
/** * @see com.ottogroup.bi.spqr.pipeline.component.MicroPipelineComponent#initialize(java.util.Properties) *//*from www . ja v a 2s . co m*/ public void initialize(Properties properties) throws RequiredInputMissingException, ComponentInitializationFailedException { if (properties == null || properties.isEmpty()) throw new RequiredInputMissingException("Missing required configuration"); ////////////////////////////////////////////////////////// // extract required configurational data this.consumerKey = properties.getProperty(CFG_TWITTER_CONSUMER_KEY); this.consumerSecret = properties.getProperty(CFG_TWITTER_CONSUMER_SECRET); this.tokenKey = properties.getProperty(CFG_TWITTER_TOKEN_KEY); this.tokenSecret = properties.getProperty(CFG_TWITTER_TOKEN_SECRET); String inSearchTerms = properties.getProperty(CFG_TWITTER_TWEET_SEARCH_TERMS); String[] splittedSearchTerms = (inSearchTerms != null ? inSearchTerms.split(",") : null); if (splittedSearchTerms != null) { for (String sst : splittedSearchTerms) { this.searchTerms.add(StringUtils.trim(sst)); } } String inLanguages = properties.getProperty(CFG_TWITTER_TWEET_LANGUAGES); String[] splittedLanguages = (inLanguages != null ? inLanguages.split(",") : null); if (splittedLanguages != null) { for (String s : splittedLanguages) { this.languages.add(StringUtils.trim(s)); } } String inProfiles = properties.getProperty(CFG_TWITTER_PROFILES); String[] splittedProfiles = (inProfiles != null ? inProfiles.split(",") : null); if (splittedProfiles != null) { for (String sp : splittedProfiles) { if (StringUtils.isNotBlank(sp)) { try { this.profiles.add(Long.parseLong(sp.trim())); } catch (Exception e) { logger.error("Failed to parse profile identifier from input '" + sp + "'"); } } } } // ////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // validate provided input before attempting to establish connection with stream.twitter.com if (StringUtils.isBlank(id)) throw new RequiredInputMissingException("Missing required component identifier"); if (StringUtils.isBlank(this.consumerKey)) throw new RequiredInputMissingException( "Missing required consumer key to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.consumerSecret)) throw new RequiredInputMissingException( "Missing required consumer secrect to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.tokenKey)) throw new RequiredInputMissingException( "Missing required token key to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.tokenSecret)) throw new RequiredInputMissingException( "Missing required token secret to establish connection with stream.twitter.com"); boolean isFilterTermsEmpty = (this.searchTerms == null || this.searchTerms.isEmpty()); boolean isLanguagesEmpty = (this.languages == null || this.languages.isEmpty()); boolean isUserAccountEmpty = (this.profiles == null || this.profiles.isEmpty()); boolean isLocationsEmpty = (this.locations == null || this.locations.isEmpty()); if (isFilterTermsEmpty && isLanguagesEmpty && isUserAccountEmpty && isLocationsEmpty) throw new RequiredInputMissingException( "Mishandle sing information what to filter twitter stream for: terms, languages, user accounts or locations"); // //////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // establish connection with stream.twitter.com Authentication auth = new OAuth1(this.consumerKey, this.consumerSecret, this.tokenKey, this.tokenSecret); StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint(); if (!isFilterTermsEmpty) filterEndpoint.trackTerms(searchTerms); if (!isLanguagesEmpty) filterEndpoint.languages(languages); if (!isUserAccountEmpty) filterEndpoint.followings(profiles); if (!isLocationsEmpty) filterEndpoint.locations(locations); if (this.twitterClient == null) { this.twitterClient = new ClientBuilder().name(id).hosts(Constants.STREAM_HOST).endpoint(filterEndpoint) .authentication(auth).processor(new StringDelimitedProcessor(streamMessageQueue)) .eventMessageQueue(eventMessageQueue).build(); this.twitterClient.connect(); } // ////////////////////////////////////////////////////////// this.running = true; if (logger.isDebugEnabled()) logger.debug("twitter stream consumer initialized [id=" + id + "]"); }
From source file:com.ottogroup.bi.spqr.resman.node.SPQRNodeManager.java
/** * Returns true in case the reference node is registered with this manager instance * @param nodeId/* w w w . ja v a 2s. co m*/ * @return */ public boolean hasNode(final String nodeId) { return this.processingNodes.containsKey(StringUtils.lowerCase(StringUtils.trim(nodeId))); }
From source file:net.lmxm.ute.configuration.ConfigurationReader.java
/** * Parses the file system location.//from w ww. j av a 2s. com * * @param locationType the location type * @return the file system location */ private FileSystemLocation parseFileSystemLocation(final FileSystemLocationType locationType) { final String prefix = "parseFileSystemLocation() :"; LOGGER.debug("{} entered", prefix); final FileSystemLocation location = new FileSystemLocation(); location.setId(StringUtils.trim(locationType.getId())); location.setPath(StringUtils.trim(locationType.getPath())); LOGGER.debug("{} returning {}", prefix, location); return location; }
From source file:com.ottogroup.bi.asap.operator.twitter.consumer.TwitterStreamConsumer.java
/** * @see com.ottogroup.bi.asap.component.Component#init(java.util.Properties) *//*w w w . j a v a 2s. c o m*/ public void init(Properties props) throws RequiredInputMissingException { if (props == null || props.isEmpty()) throw new RequiredInputMissingException("Missing required configuration"); ////////////////////////////////////////////////////////// // extract required configurational data this.consumerKey = props.getProperty(CFG_TWITTER_CONSUMER_KEY); this.consumerSecret = props.getProperty(CFG_TWITTER_CONSUMER_SECRET); this.tokenKey = props.getProperty(CFG_TWITTER_TOKEN_KEY); this.tokenSecret = props.getProperty(CFG_TWITTER_TOKEN_SECRET); this.id = props.getProperty(CFG_COMPONENT_ID); String inSearchTerms = props.getProperty(CFG_TWITTER_TWEET_SEARCH_TERMS); String[] splittedSearchTerms = (inSearchTerms != null ? inSearchTerms.split(",") : null); if (splittedSearchTerms != null) { for (String sst : splittedSearchTerms) { this.searchTerms.add(StringUtils.trim(sst)); } } String inLanguages = props.getProperty(CFG_TWITTER_TWEET_LANGUAGES); String[] splittedLanguages = (inLanguages != null ? inLanguages.split(",") : null); if (splittedLanguages != null) { for (String s : splittedLanguages) { this.languages.add(StringUtils.trim(s)); } } String inProfiles = props.getProperty(CFG_TWITTER_PROFILES); String[] splittedProfiles = (inProfiles != null ? inProfiles.split(",") : null); if (splittedProfiles != null) { for (String sp : splittedProfiles) { if (StringUtils.isNotBlank(sp)) { try { this.profiles.add(Long.parseLong(sp.trim())); } catch (Exception e) { logger.error("Failed to parse profile identifier from input '" + sp + "'"); } } } } // ////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// // validate provided input before attempting to establish connection with stream.twitter.com if (StringUtils.isBlank(id)) throw new RequiredInputMissingException("Missing required component identifier"); if (StringUtils.isBlank(this.consumerKey)) throw new RequiredInputMissingException( "Missing required consumer key to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.consumerSecret)) throw new RequiredInputMissingException( "Missing required consumer secrect to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.tokenKey)) throw new RequiredInputMissingException( "Missing required token key to establish connection with stream.twitter.com"); if (StringUtils.isBlank(this.tokenSecret)) throw new RequiredInputMissingException( "Missing required token secret to establish connection with stream.twitter.com"); boolean isFilterTermsEmpty = (this.searchTerms == null || this.searchTerms.isEmpty()); boolean isLanguagesEmpty = (this.languages == null || this.languages.isEmpty()); boolean isUserAccountEmpty = (this.profiles == null || this.profiles.isEmpty()); boolean isLocationsEmpty = (this.locations == null || this.locations.isEmpty()); if (isFilterTermsEmpty && isLanguagesEmpty && isUserAccountEmpty && isLocationsEmpty) throw new RequiredInputMissingException( "Mishandle sing information what to filter twitter stream for: terms, languages, user accounts or locations"); // //////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // establish connection with stream.twitter.com Authentication auth = new OAuth1(this.consumerKey, this.consumerSecret, this.tokenKey, this.tokenSecret); StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint(); if (!isFilterTermsEmpty) filterEndpoint.trackTerms(searchTerms); if (!isLanguagesEmpty) filterEndpoint.languages(languages); if (!isUserAccountEmpty) filterEndpoint.followings(profiles); if (!isLocationsEmpty) filterEndpoint.locations(locations); if (this.twitterClient == null) { this.twitterClient = new ClientBuilder().name(id).hosts(Constants.STREAM_HOST).endpoint(filterEndpoint) .authentication(auth).processor(new StringDelimitedProcessor(streamMessageQueue)).build(); this.twitterClient.connect(); } // ////////////////////////////////////////////////////////// this.isRunning = true; }
From source file:cop.raml.processor.RestProcessorTest.java
@Test public void shouldWorkCorrectlyForCommentedSources_v08() throws IOException, URISyntaxException { File dir = getResourceAsFile("spring/general"); ThreadLocalContext.setConfig(Config.builder().apiMediaType("application/json").ramlDev(true) .ramlShowExample(false).ramlVersion(RAML_0_8).build()); runAnnotationProcessor(dir);//from ww w . j ava 2 s . c om // System.out.println("----------"); // System.out.println(DevUtils.getRaml()); // System.out.println("----------"); // FileUtils.write(new File("wsdoc.raml"), DevUtils.getRaml(), StandardCharsets.UTF_8); String actual = DevUtils.getRaml(); String expected = StringUtils.trim(TestUtils.getResourceAsString("v0.8/general.raml")); TestUtils.assertThatEquals(actual, expected); }
From source file:com.ottogroup.bi.spqr.operator.json.filter.JsonContentFilter.java
/** * @see com.ottogroup.bi.spqr.pipeline.component.operator.DirectResponseOperator#onMessage(com.ottogroup.bi.spqr.pipeline.message.StreamingDataMessage) *//*from ww w. jav a 2s . c om*/ public StreamingDataMessage[] onMessage(StreamingDataMessage message) { // increment number of messages processed so far this.totalNumOfMessages++; // do nothing if either the event or the body is empty if (message == null || message.getBody() == null || message.getBody().length < 1) return EMPTY_MESSAGES_ARRAY; JsonNode jsonNode = null; try { jsonNode = jsonMapper.readTree(message.getBody()); } catch (IOException e) { logger.error("Failed to read message body to json node. Ignoring message. Error: " + e.getMessage()); } // return null in case the message could not be parsed into // an object representation - the underlying processor does // not forward any NULL messages if (jsonNode == null) return EMPTY_MESSAGES_ARRAY; // step through fields considered to be relevant, extract values and apply filtering function for (final JsonContentFilterFieldSetting fieldSettings : fields) { // read value into string representation for further investigation String value = getTextFieldValue(jsonNode, fieldSettings.getPath()); if (!fieldSettings.getExpression().matcher(StringUtils.trim(value)).matches()) return EMPTY_MESSAGES_ARRAY; } return new StreamingDataMessage[] { message }; }