Example usage for org.apache.commons.lang StringUtils defaultString

List of usage examples for org.apache.commons.lang StringUtils defaultString

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultString.

Prototype

public static String defaultString(String str) 

Source Link

Document

Returns either the passed in String, or if the String is null, an empty String ("").

Usage

From source file:eionet.meta.dao.domain.DataElement.java

/**
 * MD5 hash of the value similar to the DB unique key without concept id.
 *
 * @return md5 hash of element values.//  w w  w  .ja v a  2s  .  c  o  m
 */
public String getUniqueValueHash() {
    return Util
            .md5((getId() + "," + (getRelatedConceptId() != null ? getRelatedConceptId() : getAttributeValue())
                    + "@" + StringUtils.defaultString(getAttributeLanguage())));
}

From source file:mitm.common.security.ca.CAImpl.java

private boolean handleNextAction() {
    logger.debug("Check for next request.");

    CertificateRequest request = certificateRequestStore.getNextRequest();

    if (request != null) {
        if (!isExpired(request)) {
            try {
                handlePendingRequest(request);
            } catch (Throwable t) {
                /*//from   w w w  .  java2 s . c o  m
                 * We won't throw an exception because otherwise it will keep on throwing exception in 
                 * great succession. We will set the last message of the request.
                 */
                request.setLastMessage("An error occured handling the request. Message: "
                        + ExceptionUtils.getRootCauseMessage(t));

                logger.error("An error occured handling the request", t);
            } finally {
                request.setLastUpdated(new Date());
                request.setIteration(request.getIteration() + 1);

                setNextUpdate(request);
            }

        } else {
            logger.warn("Certificate request for email " + StringUtils.defaultString(request.getEmail())
                    + " is expired. Request will be removed.");

            deleteRequest(request);
        }
    }

    return request != null;
}

From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java

Chunk getValueChunk(String value) {
    return new Chunk(StringUtils.defaultString(value), VALUE_FONT);
}

From source file:com.medicaid.mmis.util.DataLoader.java

/**
 * Parses the names and sets it to the owner.
 * @param person the person to set to//from w  ww.  ja  va  2s  .c  o  m
 * @param fullname the full name
 */
private void parseFullnameToOwnerName(PersonBeneficialOwner person, String fullname) {
    if (StringUtils.isBlank(fullname)) {
        return;
    }
    String[] tokens = fullname.split(" ");
    if (tokens.length == 1) { // we can only set the last name
        person.setLastName(tokens[0]);
    } else if (tokens.length > 1) { // first name, last name
        for (int index = tokens.length - 1; index > -1; index--) {
            if (index == tokens.length - 1) {
                // last word always part of the last name
                person.setLastName(tokens[index]);
            } else if (index == tokens.length - 2 && SURNAME_PREFIX.contains(tokens[index])) {
                person.setLastName(tokens[index] + " " + person.getLastName());
            } else if (index == 0) {
                person.setFirstName(tokens[index]);
            } else {
                person.setMiddleName(
                        (tokens[index] + " " + StringUtils.defaultString(person.getMiddleName())).trim());
            }
        }
    }
}

From source file:fr.paris.lutece.plugins.directory.modules.pdfproducer.web.PDFProducerJspBean.java

/**
 * Create a new configuration//w  ww.j a v a  2s .  c  om
 * @param request request
 * @return message to confirm the creation or not
 */
public String doCreateConfigProducer(HttpServletRequest request) {
    String strIdDirectory = request.getParameter(PARAMETER_ID_DIRECTORY);

    if (!isAuthorized(strIdDirectory)) {
        return AdminMessageService.getMessageUrl(request, Messages.USER_ACCESS_DENIED, AdminMessage.TYPE_STOP);
    }

    String strNameConfig = request.getParameter(PARAMETER_CREATECONFIG_NAME);
    String strIdEntryFileName = request.getParameter(PARAMETER_ID_ENTRY_FILE_NAME);
    String strTypeConfigFileName = request.getParameter(PARAMETER_TYPE_CONFIG_FILE_NAME);
    String strTextFileName = request.getParameter(PARAMETER_TEXT_FILE_NAME);
    String strExtractNotEmpty = request.getParameter(PARAMETER_EXTRACT_NOT_EMPTY);

    String[] listStrIdEntry = request.getParameterValues(PARAMETER_CONFIG_ENTRY);
    List<Integer> listIdEntry = new ArrayList<Integer>();

    if (listStrIdEntry != null) {
        for (int i = 0; i < listStrIdEntry.length; i++) {
            if (StringUtils.isNotBlank(listStrIdEntry[i]) && StringUtils.isNumeric(listStrIdEntry[i])) {
                listIdEntry.add(Integer.valueOf(listStrIdEntry[i]));
            }
        }
    }

    checkEntryGroup(listIdEntry);

    UrlItem url = new UrlItem(JSP_CREATE_CONFIG_PRODUCER);

    if (request.getParameterMap().containsKey(PARAMETER_CREATECONFIG_SAVE)) {
        url.addParameter(PARAMETER_ID_DIRECTORY, strIdDirectory);
        url.addParameter(PARAMETER_TYPE_CONFIG_FILE_NAME, strTypeConfigFileName);
        url.addParameter(PARAMETER_TEXT_FILE_NAME, strTextFileName);
        url.addParameter(PARAMETER_EXTRACT_NOT_EMPTY, StringUtils.defaultString(strExtractNotEmpty));

        if (!listIdEntry.isEmpty()) {
            for (Integer idEntry : listIdEntry) {
                url.addParameter(PARAMETER_CONFIG_ENTRY, String.valueOf(idEntry));
            }
        }

        if (StringUtils.isBlank(strNameConfig)) {
            url.addParameter(PARAMETER_ID_ENTRY_FILE_NAME, strIdEntryFileName);

            return AdminMessageService.getMessageUrl(request, MESSAGE_NAME_CONFIG_MISSED, url.getUrl(),
                    AdminMessage.TYPE_ERROR);
        } else if (StringUtils.isBlank(strIdEntryFileName) && (StringUtils.isEmpty(strTypeConfigFileName)
                || strTypeConfigFileName.equals(CONSTANT_DIRECTORY_ENTRY))) {
            url.addParameter(PARAMETER_CREATECONFIG_NAME, strIdEntryFileName);

            return AdminMessageService.getMessageUrl(request, MESSAGE_ENTRY_FILE_NAME_MISSED, url.getUrl(),
                    AdminMessage.TYPE_ERROR);
        } else {
            url = new UrlItem(JSP_MANAGE_CONFIG_PRODUCER);
            url.addParameter(PARAMETER_ID_DIRECTORY, strIdDirectory);

            ConfigProducer configProducer = new ConfigProducer();
            configProducer.setName(strNameConfig);
            configProducer.setIdEntryFileName(DirectoryUtils.convertStringToInt(strIdEntryFileName));
            configProducer.setIdDirectory(DirectoryUtils.convertStringToInt(strIdDirectory));
            configProducer.setType(TYPE_CONFIG_PDF);
            configProducer.setTextFileName(strTextFileName);
            configProducer.setTypeConfigFileName(strTypeConfigFileName);

            if (StringUtils.isNotBlank(strExtractNotEmpty)) {
                configProducer.setExtractNotFilled(false);
            } else {
                configProducer.setExtractNotFilled(true);
            }

            _manageConfigProducerService.addNewConfig(getPlugin(), configProducer, listIdEntry);

            return AdminMessageService.getMessageUrl(request, MESSAGE_ADD_NEW_CONFIG, url.getUrl(),
                    AdminMessage.TYPE_INFO);
        }
    } else if (request.getParameterMap().containsKey(PARAMETER_CREATECONFIG_CANCEL)) {
        url = new UrlItem(JSP_MANAGE_CONFIG_PRODUCER);
        url.addParameter(PARAMETER_ID_DIRECTORY, strIdDirectory);

        return AdminMessageService.getMessageUrl(request, MESSAGE_CANCEL_CREATE, url.getUrl(),
                AdminMessage.TYPE_INFO);
    } else {
        url = new UrlItem(JSP_CREATE_CONFIG_PRODUCER_BIS);

        return doCheckAll(url, strIdDirectory, listIdEntry, strNameConfig, strIdEntryFileName, strTextFileName,
                strTypeConfigFileName);
    }
}

From source file:mitm.application.djigzo.ws.impl.X509CertStoreWSImpl.java

@Override
@StartTransaction/*from ww w. j  a va 2s .  c o  m*/
public List<X509CertificateDTO> searchByIssuer(String issuer, Expired expired, MissingKeyAlias missingKeyAlias,
        Integer firstResult, Integer maxResults) throws WebServiceCheckedException {
    issuer = StringUtils.defaultString(issuer);

    if (expired == null) {
        throw new WebServiceCheckedException("expired is missing.");
    }

    if (missingKeyAlias == null) {
        throw new WebServiceCheckedException("missingKeyAlias is missing.");
    }

    try {
        return searchByIssuerAction(issuer, expired, missingKeyAlias, firstResult, maxResults);
    } catch (WebServiceCheckedException e) {
        logger.error("searchByIssuer failed.", e);

        throw new WebServiceCheckedException(WSExceptionUtils.getExceptionMessage(e));
    } catch (RuntimeException e) {
        logger.error("searchByIssuer failed.", e);

        throw new WebServiceCheckedException(WSExceptionUtils.getExceptionMessage(e));
    }
}

From source file:com.opengamma.masterdb.portfolio.DbPortfolioMaster.java

/**
 * Recursively create the arguments to insert into the tree existing nodes.
 * /*from  w ww  .  ja  v  a 2 s  . co m*/
 * @param portfolioUid the portfolio unique identifier, not null
 * @param parentNodeUid the parent node unique identifier, not null
 * @param node the root node, not null
 * @param update true if updating portfolio, false if adding new portfolio
 * @param portfolioId the portfolio id, not null
 * @param portfolioOid the portfolio oid, not null
 * @param parentNodeId the parent node id, null if root node
 * @param parentNodeOid the parent node oid, null if root node
 * @param counter the counter to create the node id, use {@code getAndIncrement}, not null
 * @param depth the depth of the node in the portfolio
 * @param argsList the list of arguments to build, not null
 * @param posList the list of arguments to for inserting positions, not null
 */
protected void insertBuildArgs(final UniqueId portfolioUid, final UniqueId parentNodeUid,
        final ManageablePortfolioNode node, final boolean update, final Long portfolioId,
        final Long portfolioOid, final Long parentNodeId, final Long parentNodeOid, final AtomicInteger counter,
        final int depth, final List<DbMapSqlParameterSource> argsList,
        final List<DbMapSqlParameterSource> posList) {
    // need to insert parent before children for referential integrity
    final Long nodeId = nextId("prt_master_seq");
    final Long nodeOid = (update && node.getUniqueId() != null ? extractOid(node.getUniqueId()) : nodeId);
    UniqueId nodeUid = createUniqueId(nodeOid, nodeId);
    node.setUniqueId(nodeUid);
    node.setParentNodeId(parentNodeUid);
    node.setPortfolioId(portfolioUid);
    final DbMapSqlParameterSource treeArgs = new DbMapSqlParameterSource().addValue("node_id", nodeId)
            .addValue("node_oid", nodeOid).addValue("portfolio_id", portfolioId)
            .addValue("portfolio_oid", portfolioOid).addValue("parent_node_id", parentNodeId, Types.BIGINT)
            .addValue("parent_node_oid", parentNodeOid, Types.BIGINT).addValue("depth", depth)
            .addValue("name", StringUtils.defaultString(node.getName()));
    argsList.add(treeArgs);

    // store position links
    Set<ObjectId> positionIds = new LinkedHashSet<ObjectId>(node.getPositionIds());
    node.getPositionIds().clear();
    node.getPositionIds().addAll(positionIds);
    for (ObjectId positionId : positionIds) {
        final DbMapSqlParameterSource posArgs = new DbMapSqlParameterSource().addValue("node_id", nodeId)
                .addValue("key_scheme", positionId.getScheme()).addValue("key_value", positionId.getValue());
        posList.add(posArgs);
    }

    // store the left/right before/after the child loop and back fill into stored args row
    treeArgs.addValue("tree_left", counter.getAndIncrement());
    for (ManageablePortfolioNode childNode : node.getChildNodes()) {
        insertBuildArgs(portfolioUid, nodeUid, childNode, update, portfolioId, portfolioOid, nodeId, nodeOid,
                counter, depth + 1, argsList, posList);
    }
    treeArgs.addValue("tree_right", counter.getAndIncrement());
}

From source file:gov.nih.nci.caarray.dao.SampleDaoImpl.java

private <T extends AbstractBioMaterial> Query getSearchQuery(boolean count, PageSortParams<T> params,
        String keyword, Set<Class<? extends AbstractBioMaterial>> biomaterialSubclasses,
        BiomaterialSearchCategory... categories) {
    @SuppressWarnings("deprecation")
    JoinableSortCriterion<T> sortCrit = params != null ? (JoinableSortCriterion<T>) params.getSortCriterion()
            : null;// ww w.  j ava 2 s .c om
    StringBuffer sb = new StringBuffer();
    if (count) {
        sb.append("SELECT COUNT(DISTINCT s)");
    } else {
        sb.append(SELECT_DISTINCT + "s");
    }

    sb.append(generateSearchClause(count, sortCrit, biomaterialSubclasses, categories));

    if (!count && sortCrit != null) {
        sb.append(ORDER_BY).append(getOrderByField(sortCrit));
        if (params.isDesc()) {
            sb.append(" desc");
        }
    }
    Query q = getCurrentSession().createQuery(sb.toString());
    q.setString(KEYWORD_SUB, "%" + StringUtils.defaultString(keyword) + "%");
    if (biomaterialSubclasses.size() > 1) {
        Set<String> discriminators = new HashSet<String>();
        for (Class<? extends AbstractBioMaterial> bmClass : biomaterialSubclasses) {
            discriminators.add(getDiscriminator(bmClass));
        }
        q.setParameterList("klass", discriminators);
    }
    return q;
}

From source file:mitm.application.djigzo.ws.impl.X509CertStoreWSImpl.java

@Override
@StartTransaction/*from   w w  w .j  av a 2 s  .c om*/
public long getSearchByIssuerCount(String issuer, Expired expired, MissingKeyAlias missingKeyAlias)
        throws WebServiceCheckedException {
    issuer = StringUtils.defaultString(issuer);

    if (expired == null) {
        throw new WebServiceCheckedException("expired is missing.");
    }

    if (missingKeyAlias == null) {
        throw new WebServiceCheckedException("missingKeyAlias is missing.");
    }

    try {
        return certStore.getSearchByIssuerCount(issuer, expired, missingKeyAlias);
    } catch (CertStoreException e) {
        logger.error("getSearchByIssuerCount failed.", e);

        throw new WebServiceCheckedException(WSExceptionUtils.getExceptionMessage(e));
    } catch (RuntimeException e) {
        logger.error("getSearchByIssuerCount failed.", e);

        throw new WebServiceCheckedException(WSExceptionUtils.getExceptionMessage(e));
    }
}

From source file:jp.co.nemuzuka.service.impl.TicketServiceImpl.java

/**
 * Model./*from   www  .  j  a  v  a  2 s. c  o m*/
 * @param model Model
 * @param form Form
 * @throws NotExistTicketException ??????No??
 * @throws ParentSelfTicketException ????No??
 */
private void setModel(TicketModel model, TicketForm form)
        throws NotExistTicketException, ParentSelfTicketException {
    SimpleDateFormat sdf = DateTimeUtils.createSdf("yyyyMMdd");
    model.setTitle(form.title);
    model.setContent(new Text(StringUtils.defaultString(form.content)));
    model.setEndCondition(new Text(StringUtils.defaultString(form.endCondition)));
    model.setPriority(form.priority);
    model.setStatus(form.status);
    model.setTargetKind(form.targetKind);
    model.setCategory(form.category);

    Key milestoneKey = null;
    if (StringUtils.isNotEmpty(form.milestone)) {
        milestoneKey = Datastore.stringToKey(form.milestone);
    }
    model.setMilestone(milestoneKey);

    model.setTargetVersion(form.targetVersion);

    Key targetMemberKey = null;
    if (StringUtils.isNotEmpty(form.targetMember)) {
        targetMemberKey = Datastore.stringToKey(form.targetMember);
    }
    model.setTargetMemberKey(targetMemberKey);

    model.setStartDate(ConvertUtils.toDate(form.startDate, sdf));
    model.setPeriod(ConvertUtils.toDate(form.period, sdf));

    Key parentKey = null;
    if (StringUtils.isNotEmpty(form.parentKey)) {
        //??No????Ticket???????Exception
        parentKey = ticketDao.getWithNoAndProjectKey(ConvertUtils.toLong(form.parentKey),
                model.getProjectKey());
        if (parentKey == null) {
            throw new NotExistTicketException();
        }

        if (parentKey.equals(model.getKey())) {
            //?????????Exception
            throw new ParentSelfTicketException();
        }
    }
    model.setParentTicketKey(parentKey);
}