Example usage for org.springframework.util StringUtils isEmpty

List of usage examples for org.springframework.util StringUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util StringUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Object str) 

Source Link

Document

Check whether the given object (possibly a String ) is empty.

Usage

From source file:com.consol.citrus.selenium.action.ExtractAction.java

@Override
public void doExecute(TestContext context) {
    super.doExecute(context);

    if (elements != null) {
        for (By by : elements.keySet()) {
            String variable = elements.get(by).getVariable();
            String attribute = elements.get(by).getAttribute();
            String value = null;//  w w  w . ja va  2 s.c  om
            logger.info("extracting the element by <{}>", by);

            WebElement element = webClient.findElement(by);

            // check if the by has attribute selection
            if (by instanceof By.ByXPath) {
                // TODO: refactor the following
                String xpathExpression = by.toString().replaceAll("By.xpath:\\s*", "");
                if (xpathExpression.contains("/@")) {
                    // we found attribute selection.
                    String[] parts = xpathExpression.split("/@");
                    attribute = parts[1];
                    String newXpathExpresseion = parts[0];
                    element = webClient.findElement(By.xpath(newXpathExpresseion));
                }
            }

            if (element != null) {
                if (StringUtils.hasText(attribute)) {
                    value = element.getAttribute(attribute);
                } else {
                    value = element.getAttribute("value");
                    if (StringUtils.isEmpty(value)) {
                        value = element.getText();
                    }
                }
            }
            context.setVariable(variable, value);
        }
    }

    if (StringUtils.hasText(pageName)) {
        WebPage pageObj;
        try {
            logger.debug("Initializing the page object {}", pageName);
            Class pageClass = Class.forName(pageName);
            pageObj = webClient.createPage(pageClass);
            logger.debug("page object {} is succesfully created.", pageName);
            webClient.verifyPage(pageObj);
            for (String pageAction : pageActions.keySet()) {
                String variable = pageActions.get(pageAction);
                logger.debug("running the action {} on the page object {}", pageAction, pageName);
                logger.info("Invoking method '" + pageAction + "' on instance '" + pageClass + "'");
                Method actionMethod = pageObj.getClass().getMethod("get" + pageAction);
                String value = (String) actionMethod.invoke(pageObj);
                context.setVariable(variable, value);
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
            throw new CitrusRuntimeException(ex);
        }
    }
}

From source file:com.dickthedeployer.dick.web.service.BuildService.java

@Transactional
public void onTrigger(TriggerModel model) throws BuildAlreadyQueuedException, RepositoryParsingException {
    Optional<Project> projectOptional = projectDao.findByNamespaceNameAndName(model.getNamespace(),
            model.getName());/*from   www  . j  a v a 2s .  co m*/
    Project project = projectOptional.get();
    log.info("Found project {} for name {}", project.getId(), model.getName());
    String sha = model.getSha();
    if (StringUtils.isEmpty(sha)) {
        sha = repositoryService.getLastSha(project);
    }
    List<EnvironmentVariable> environment = getEnvironment(model);
    try {
        String lastMessage = repositoryService.getLastMessage(project, sha);
        buildProject(project, sha, Optional.ofNullable(lastMessage), environment);
    } catch (CommandExecutionException ex) {
        throw new RepositoryParsingException(ex);
    }
}

From source file:com.duck8823.matcher.IDataSetMatcher.java

@Override
public void describeTo(Description description) {
    description.appendValue(expected);/*from   ww  w .  j av a2s .  c  o m*/
    if (!StringUtils.isEmpty(message)) {
        description.appendText(message);
    }
}

From source file:de.dlopes.stocks.facilitator.services.impl.StockInfoServiceImpl.java

@Override
public void addStocks(AddStocksForm addStocksForm) {

    List<String> yahooSymbols = null;
    String url = addStocksForm.getUrl();
    if (StringUtils.isEmpty(url)) {

        String yhooSymString = addStocksForm.getListOfYahooSymbols();
        yhooSymString = yhooSymString.replace("\n", ",");
        yhooSymString = yhooSymString.replace("\r", ",");
        yhooSymString = yhooSymString.replace(",,", ",");
        yhooSymString = StringUtils.trimAllWhitespace(yhooSymString);
        yahooSymbols = Arrays.asList(StringUtils.delimitedListToStringArray(yhooSymString, ","));

    } else {/*from  ww  w . j av a 2s .c om*/
        /*              
                   // get the ISINs 
                   FinanzenNetIndexHTMLExtractorImpl fn_isin_extr = new FinanzenNetIndexHTMLExtractorImpl();
                   List<String> isins = fn_isin_extr.getFinanceData(url);
                  // TODO: remove ISINs which already exist in the DB from list
                    
                   log.info("ISINs extracted!");
                           
                    // guard: abort when there is nothing to add
                    if (isins.size() < 1) {
                      throw new RuntimeException("no ISINs found!.");   
                      // TODO: propagate error message to UI
                   }
                           
                   log.info("ISINs found!");      
                           
                  // receive the mapping 
                  Map<String,String> symbols2isins = null;
                  try {
                      symbols2isins = YahooFinanceDataCollectorImpl.getSymbols4ISINs(isins);
                   } catch (SFApplicationException sfae) {
                       throw new RuntimeException("Yahoo Symbols could not be loaded", sfae);    
                   }
                    
                   log.info("Yahoo symbols loaded!");
                           
                    // when there was no mapping was found for one or more ISIN, the we 
                    // have to propagate this as a warning message
                    if (symbols2isins.size() < isins.size()) {
        // remove all ISINs that returned a valid mapping and see what stays in the list
        for (String s : symbols2isins.keySet()) {
            String isin = symbols2isins.get(s);
            isins.remove(isin);
        }
                
        // TODO: propagate a message to the UI
                    }
                    
                   log.info("Yahoo symbols cleaned up!");
                            
                    // guard: do not proceed when we don't have new symbols to add 
                    if (symbols2isins.size() < 1) {
                      throw new RuntimeException("no YAHOO symbols found!.");   
                      // TODO: propagate error message to UI
                   }
                           
                   log.info("still have Yahoo symbols to load!");        
            */

        FinanceDataExtractor finDataExtr = cs.getFinanceDataExtractor();
        yahooSymbols = finDataExtr.getFinanceData(url);

    }

    // guard: abort when there is nothing to add
    if (yahooSymbols == null || yahooSymbols.isEmpty()) {
        throw new RuntimeException("no Yahoo Symbols found!.");
        // TODO: propagate error message to UI
    }

    // load stock details from yahoo finance api
    Map<String, Stock> stocks = null;
    try {
        stocks = YahooFinanceDataCollectorImpl.requestStocks(yahooSymbols);
    } catch (SFApplicationException sfae) {
        throw new RuntimeException("Stock details could not be loaded", sfae);
    }

    log.info("Stock info requested from Yahoo!");

    for (String symbol : stocks.keySet()) {

        Stock stock = stocks.get(symbol);
        // TODO: refactor 
        FinanznachrichtenOrderbuchExtractorImpl foei = new FinanznachrichtenOrderbuchExtractorImpl();
        List<String> isins = foei.getFinanceData(
                FinanznachrichtenOrderbuchExtractorImpl.PREFIX + symbol.split("\\.")[0] + ".htm");
        String isin = null;
        if (isins != null && isins.size() > 0) {
            isin = isins.get(0);
        }

        log.debug("creating StockInfo record for ISIN '" + isin + "'");

        StockInfo si = new StockInfo(isin);
        Stock2StockInfoConverter.applyUpdates(stock, si);

        log.debug("yahoo data applied to StockInfo record for ISIN '" + isin + "'");

        siRepo.save(si);

        log.debug("StockInfo record for ISIN '" + isin + "' saved");
    }
    siRepo.flush();

    log.info("Stock info committed to database!");

}

From source file:com.stehno.sjdbcx.reflection.extractor.AnnotatedCollaborationExtractor.java

@Override
@SuppressWarnings("unchecked")
public C extract(final Method method) {
    final Annotation annotation = AnnotationUtils.getAnnotation(method, annoType);
    if (annotation != null) {
        final String extractionKey = (String) AnnotationUtils.getValue(annotation);
        if (!StringUtils.isEmpty(extractionKey)) {
            return resolve(extractionKey);
        } else {//  w  w  w . jav  a  2  s .c  o  m
            return resolve((Class<C>) AnnotationUtils.getValue(annotation, TYPE_ATTRIBUTE));
        }

    } else {
        return defaultExtractor;
    }
}

From source file:com.stehno.sjdbcx.support.SqlResolver.java

private Resource determineResolverResource(final Class clazz, final JdbcRepository jdbcAnno) {
    final String resourceStr = jdbcAnno != null ? jdbcAnno.value() : null;
    final String fileName = clazz.getSimpleName().toLowerCase();
    final String resourcePath = StringUtils.isEmpty(resourceStr) ? String.format(PROP_FILE, fileName)
            : resourceStr;// www  .  j av a2s  .  co  m
    final ClassPathResource resource = new ClassPathResource("/" + resourcePath);

    log.debug("Resolving SQL for ({}) from resource ({})", clazz, resource);

    return resource;
}

From source file:org.psikeds.resolutionengine.rules.RelationStack.java

public boolean containsRelation(final String rid) {
    return (StringUtils.isEmpty(rid) ? false : this.containsKey(rid));
}

From source file:cn.guoyukun.spring.web.controller.BaseController.java

/**
 * @param backURL null ??getViewPrefix()
 * @return//  w w w.jav  a2 s  .  c o m
 */
protected String redirectToUrl(String backURL) {
    if (StringUtils.isEmpty(backURL)) {
        backURL = getViewPrefix();
    }
    if (!backURL.startsWith("/") && !backURL.startsWith("http")) {
        backURL = "/" + backURL;
    }
    return "redirect:" + backURL;
}

From source file:org.jasig.ssp.util.importer.job.report.ReportGenerator.java

private void sendEmail(JobExecution jobExecution, String report) {

    final MimeMessage mimeMessage = javaMailSender.createMimeMessage();
    final MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage);
    String[] recipients = emailRecipients.split(",");
    String EOL = System.getProperty("line.separator");

    try {//  www .ja  v  a  2 s .com
        for (String recipient : recipients) {
            mimeMessageHelper.addTo(recipient);

            if (!StringUtils.isEmpty(replyTo)) {
                mimeMessageHelper.setReplyTo(replyTo);
            }
            mimeMessageHelper.setSubject("Data Import Report for SSP Instance: " + batchTitle + " JobId: "
                    + jobExecution.getJobId());
            mimeMessageHelper.setText(report);
            javaMailSender.send(mimeMessage);

        }
        logger.info("Report emailed" + EOL);
    } catch (MessagingException e) {
        logger.error(e.toString());
    }
    ;
}

From source file:net.phoenix.thrift.xml.ArgsBeanDefinitionParser.java

@Override
protected void preParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    Element parent = (Element) element.getParentNode();
    String name = parent.getAttribute("name") + BEAN_NAME_SUFFIX;
    if (StringUtils.isEmpty(element.getAttribute("id"))) {
        element.setAttribute("id", name);
    }/*  www  . j ava  2s  .c  om*/
    if (StringUtils.isEmpty(element.getAttribute("name"))) {
        element.setAttribute("name", name);
    }
    builder.addConstructorArgValue(this.buildSocket(element));
}