Example usage for org.apache.commons.lang3 StringUtils defaultIfBlank

List of usage examples for org.apache.commons.lang3 StringUtils defaultIfBlank

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils defaultIfBlank.

Prototype

public static <T extends CharSequence> T defaultIfBlank(final T str, final T defaultStr) 

Source Link

Document

Returns either the passed in CharSequence, or if the CharSequence is whitespace, empty ("") or null , the value of defaultStr .

 StringUtils.defaultIfBlank(null, "NULL")  = "NULL" StringUtils.defaultIfBlank("", "NULL")    = "NULL" StringUtils.defaultIfBlank(" ", "NULL")   = "NULL" StringUtils.defaultIfBlank("bat", "NULL") = "bat" StringUtils.defaultIfBlank("", null)      = null 

Usage

From source file:org.kuali.coeus.propdev.impl.core.ProposalDocumentView.java

@Override
protected void generatePessimisticLockMessages(TransactionalDocumentFormBase form) {
    ProposalDevelopmentDocumentForm proposalDevelopmentDocumentForm = (ProposalDevelopmentDocumentForm) form;
    if (!proposalDevelopmentDocumentForm.isViewOnly()) {
        Document document = form.getDocument();
        String pageId = proposalDevelopmentDocumentForm.getPageId();
        Person user = GlobalVariables.getUserSession().getPerson();

        for (PessimisticLock lock : document.getPessimisticLocks()) {
            String lockRegion = lock.getLockDescriptor() != null
                    ? StringUtils.split(lock.getLockDescriptor(), "-")[1]
                    : null;/*from  www . j a v a  2 s  .  c o  m*/
            if (!lock.isOwnedByUser(user)
                    && !StringUtils.equals(pageId, ProposalDevelopmentConstants.KradConstants.BUDGET_PAGE)
                    && !StringUtils.equals(lockRegion, KraAuthorizationConstants.LOCK_DESCRIPTOR_BUDGET)) {
                String lockDescriptor = StringUtils.defaultIfBlank(lock.getLockDescriptor(), FULL);
                String lockOwner = lock.getOwnedByUser().getName();
                String lockTime = RiceConstants.getDefaultTimeFormat().format(lock.getGeneratedTimestamp());
                String lockDate = RiceConstants.getDefaultDateFormat().format(lock.getGeneratedTimestamp());

                if (!getParameterService().getParameterValueAsBoolean(Constants.KC_GENERIC_PARAMETER_NAMESPACE,
                        Constants.KC_ALL_PARAMETER_DETAIL_TYPE_CODE,
                        PessimisticLockConstants.ALLOW_CLEAR_PESSIMISTIC_LOCK_PARM)) {
                    GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                            RiceKeyConstants.ERROR_TRANSACTIONAL_LOCKED, lockDescriptor, lockOwner, lockTime,
                            lockDate);
                } else {
                    GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                            KC_ERROR_TRANSACTIONAL_LOCKED, lockDescriptor, lockOwner, lockTime, lockDate,
                            lock.getId().toString());
                }
            }
        }
    }
}

From source file:org.kuali.coeus.sys.framework.view.KcTransactionalDocumentView.java

@Override
protected void generatePessimisticLockMessages(TransactionalDocumentFormBase form) {
    if (!getParameterService().getParameterValueAsBoolean("KC-GEN", "All",
            PessimisticLockConstants.ALLOW_CLEAR_PESSIMISTIC_LOCK_PARM)) {
        super.generatePessimisticLockMessages(form);
    } else {//from   w  ww .j  a  v a2s . c o  m
        Document document = form.getDocument();
        Person user = GlobalVariables.getUserSession().getPerson();

        for (PessimisticLock lock : document.getPessimisticLocks()) {
            if (!lock.isOwnedByUser(user)) {
                String lockDescriptor = StringUtils.defaultIfBlank(lock.getLockDescriptor(), "full");
                String lockOwner = lock.getOwnedByUser().getName();
                String lockTime = RiceConstants.getDefaultTimeFormat().format(lock.getGeneratedTimestamp());
                String lockDate = RiceConstants.getDefaultDateFormat().format(lock.getGeneratedTimestamp());

                GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS,
                        KC_ERROR_TRANSACTIONAL_LOCKED, lockDescriptor, lockOwner, lockTime, lockDate,
                        lock.getId().toString());
            }
        }
    }
}

From source file:org.ligoj.app.plugin.prov.aws.in.ProvAwsPriceImportResource.java

/**
 * Build a new instance price type from the CSV line.
 *//*w  ww.j  ava  2s  .  c o m*/
private ProvInstancePriceTerm newInstancePriceTerm(final UpdateContext context, final AwsEc2Price csvPrice) {
    final ProvInstancePriceTerm term = new ProvInstancePriceTerm();
    term.setNode(context.getNode());
    term.setCode(csvPrice.getOfferTermCode());

    // Build the name from the leasing, purchase option and offering class
    final String name = StringUtils.trimToNull(StringUtils.removeAll(
            StringUtils.replaceAll(csvPrice.getPurchaseOption(), "([a-z])Upfront", "$1 Upfront"),
            "No\\s*Upfront"));
    term.setName(Arrays
            .stream(new String[] { csvPrice.getTermType(),
                    StringUtils.replace(csvPrice.getLeaseContractLength(), " ", ""), name,
                    StringUtils.trimToNull(StringUtils.remove(csvPrice.getOfferingClass(), "standard")) })
            .filter(Objects::nonNull).collect(Collectors.joining(", ")));

    // Handle leasing
    final Matcher matcher = LEASING_TIME
            .matcher(StringUtils.defaultIfBlank(csvPrice.getLeaseContractLength(), ""));
    if (matcher.find()) {
        // Convert years to months
        term.setPeriod(Integer.parseInt(matcher.group(1)) * 12);
    }
    iptRepository.saveAndFlush(term);
    return term;
}

From source file:org.ligoj.app.plugin.prov.aws.in.ProvAwsPriceImportResource.java

/**
 * Indicate the given region is enabled.
 *
 * @param region/*ww w.  j  av a2s.c  o m*/
 *            The region API name to test.
 * @return <code>true</code> when the configuration enable the given region.
 */
private boolean isEnabledRegion(final String region) {
    return region.matches(StringUtils.defaultIfBlank(configuration.get(CONF_REGIONS), ".*"));
}

From source file:org.mayocat.cms.contact.ContactResource.java

@POST
public Response postContactMessage(MultivaluedMap<String, String> form) {
    String redirectTo = form.getFirst(PARAMETER_REDIRECT_TO);

    if (Strings.isNullOrEmpty(redirectTo)) {
        return Response.status(Response.Status.BAD_REQUEST).build();
    }/*www  .  jav a 2 s  .  c  o m*/

    String subject = StringUtils.defaultIfBlank(form.getFirst(PARAMETER_SUBJECT), DEFAULT_SUBJECT);

    String text = "";

    for (String name : form.keySet()) {
        if (!Arrays.asList(PARAMETER_REDIRECT_TO, PARAMETER_SUBJECT, PARAMETER_HONEYPOT).contains(name)) {
            text += (name.toUpperCase() + ": " + form.getFirst(name) + "\n");
        }
    }

    Mail mail = mailService.emailToTenant().subject(subject).text(text);

    try {
        URI returnTo = new URI(redirectTo);
        try {
            if (Strings.isNullOrEmpty(form.getFirst(PARAMETER_HONEYPOT))) {
                logger.debug("Sending contact form [{}]", subject);
                mailService.sendEmail(mail);

                // Note: If spam, don't act anything different but not sending the mail.
                // i.e. return success as well.
            }
            context.flash("postContactMessage", "Success");
            return Response.seeOther(returnTo).build();
        } catch (MailException e) {
            context.flash("postContactMessage", "Failure");
            return Response.seeOther(returnTo).build();
        }
    } catch (URISyntaxException e) {
        return Response.serverError().build();
    }
}

From source file:org.meruvian.yama.service.jpa.JpaRoleManager.java

@Override
public Page<JpaRole> findRoleByKeyword(String keyword, Pageable pageable) {
    keyword = StringUtils.defaultIfBlank(keyword, "");

    return roleRepository.find(keyword, pageable);
}

From source file:org.meruvian.yama.service.jpa.JpaRoleManager.java

@Override
public Page<JpaRole> findActiveRoleByKeyword(String keyword, Pageable pageable) {
    keyword = StringUtils.defaultIfBlank(keyword, "");

    return roleRepository.find(keyword, LogInformation.ACTIVE, pageable);
}

From source file:org.meruvian.yama.service.jpa.JpaUserManager.java

@Override
public Page<JpaUser> findUserByKeyword(String keyword, Pageable pageable) {
    keyword = StringUtils.defaultIfBlank(keyword, "");
    return userRepository.find(keyword, pageable);
}

From source file:org.meruvian.yama.service.jpa.JpaUserManager.java

@Override
public Page<JpaUser> findActiveUserByKeyword(String keyword, Pageable pageable) {
    keyword = StringUtils.defaultIfBlank(keyword, "");
    return userRepository.find(keyword, LogInformation.ACTIVE, pageable);
}

From source file:org.meruvian.yama.showcase.action.application.ApplicationAction.java

@Action(method = HttpMethod.GET)
public ActionResult appList(@ActionParam("q") String q, @ActionParam("max") int max,
        @ActionParam("page") int page) {
    max = max == 0 ? 10 : max;/*from   w  w w. j a va 2 s .  c  om*/
    q = StringUtils.defaultIfBlank(q, "");

    Page<? extends Application> apps = appManager.findApplicationByNamespace(q, new PageRequest(page, max));

    return new ActionResult("freemarker", "/view/application/application-list.ftl").addToModel("apps", apps);
}