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.baidu.rigel.biplatform.tesseract.node.service.impl.IsNodeServiceImpl.java

@Override
public Node getFreeSearchNodeByIndexShard(IndexShard idxShard, String clusterName) {
    if (idxShard == null || StringUtils.isEmpty(idxShard.getNodeKey())
            && CollectionUtils.isEmpty(idxShard.getReplicaNodeKeyList())) {
        throw new IllegalArgumentException();
    }//from ww  w  .java2 s .  co m
    List<Node> currNodeList = getAvailableNodeListByIndexShard(idxShard, clusterName);
    int minRequestCount = 0;
    Node result = null;

    for (int i = 0; i < currNodeList.size(); i++) {
        Node node = currNodeList.get(i);
        if (i == 0) {
            minRequestCount = node.getSearchRequestCount();
        }
        if (node.getSearchRequestCount() <= minRequestCount) {
            minRequestCount = node.getSearchRequestCount();
            result = node;
        }
    }
    return result;
}

From source file:com.formkiq.core.service.UserServiceImpl.java

@Override
public void updatePassword(final String email, final String resettoken, final String newPassword) {

    boolean updated = false;

    if (!StringUtils.isEmpty(resettoken)) {

        User user = this.userDao.findUser(email);

        if (user != null) {

            if (isMatch(resettoken, user.getResetToken())) {

                Date now = this.dateservice.now();
                Date date = DateUtils.addMinutes(now, -getUserTokenExpiryInMinutes());

                if (user.getResetInsertedDate().after(date)) {

                    user.setResetInsertedDate(null);
                    user.setResetToken(null);
                    updated = true;//from  w w  w  .  j  a v  a 2 s  . c o m
                }

            } else {

                updated = isMatch(resettoken, user.getPassword());
            }

            if (updated) {

                if (UserStatus.INVITE.equals(user.getStatus())) {
                    user.setStatus(UserStatus.ACTIVE);
                }

                setUserPassword(user, newPassword);

                this.userDao.saveUser(user);
            }
        }
    }

    if (!updated) {
        throw new PreconditionFailedException("Invalid Old Password or Reset Token");
    }
}

From source file:com.emergya.spring.security.oauth.google.GoogleAuthorizationCodeAccessTokenProvider.java

private UserRedirectRequiredException getRedirectForAuthorization(GoogleAuthCodeResourceDetails resource,
        AccessTokenRequest request) {/*  ww w  .  j  av a2  s.  c  o  m*/

    // we don't have an authorization code yet. So first get that.
    TreeMap<String, String> requestParameters = new TreeMap<>();
    requestParameters.put("response_type", "code"); // oauth2 spec, section 3
    requestParameters.put("client_id", resource.getClientId());
    // Client secret is not required in the initial authorization request

    String redirectUri = resource.getRedirectUri(request);
    if (redirectUri != null) {
        requestParameters.put("redirect_uri", redirectUri);
    }

    if (resource.isScoped()) {

        StringBuilder builder = new StringBuilder();
        List<String> scope = resource.getScope();

        if (scope != null) {
            Iterator<String> scopeIt = scope.iterator();
            while (scopeIt.hasNext()) {
                builder.append(scopeIt.next());
                if (scopeIt.hasNext()) {
                    builder.append(' ');
                }
            }
        }

        requestParameters.put("scope", builder.toString());
    }

    requestParameters.put("approval_prompt", resource.getApprovalPrompt());

    if (StringUtils.isEmpty(resource.getLoginHint())) {
        requestParameters.put("login_hint", resource.getLoginHint());
    }

    requestParameters.put("access_type", "online");

    UserRedirectRequiredException redirectException = new UserRedirectRequiredException(
            resource.getUserAuthorizationUri(), requestParameters);

    String stateKey = stateKeyGenerator.generateKey(resource);
    redirectException.setStateKey(stateKey);
    request.setStateKey(stateKey);
    redirectException.setStateToPreserve(redirectUri);
    request.setPreservedState(redirectUri);

    return redirectException;

}

From source file:com.formkiq.core.equifax.service.EquifaxResponseProcessor.java

/**
 * Secondary Check to find SCOR segment in string.
 * @param factory {@link SegmentFactory}
 * @param responseData {@link String}//from w w w  .  j av a  2 s. c  om
 * @return {@link ScorSegment}
 */
private ScorSegment findScorSegmentSecondCheck(final SegmentFactory factory, final String responseData) {

    ScorSegment scor = null;

    try {

        if (!StringUtils.isEmpty(responseData)) {

            int pos = responseData.indexOf("##SCOR");
            if (pos > -1) {

                pos += 2;
                String substring = responseData.substring(pos, pos + ScorSegment.LENGTH);

                List<Segment> segments = factory.readSegments(substring);

                scor = (ScorSegment) findSegment(segments, ScorSegment.class);
            }
        }

    } catch (Exception e) {
        scor = null;
    }

    return scor;
}

From source file:cz.muni.fi.mir.db.dao.impl.FormulaDAOImpl.java

@Override
public SearchResponse<Formula> findFormulas(FormulaSearchRequest formulaSearchRequest, Pagination pagination) {
    FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
    org.hibernate.search.jpa.FullTextQuery ftq = null; // actual query hitting database
    boolean isEmpty = true;

    QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Formula.class)
            .overridesForField("co.annotation", "standardAnalyzer")
            .overridesForField("co.element", "keywordAnalyzer").get();

    BooleanJunction<BooleanJunction> junction = qb.bool();

    if (formulaSearchRequest.getSourceDocument() != null
            && formulaSearchRequest.getSourceDocument().getId() != null) {
        junction.must(qb.keyword().onField("sourceDocument.id")
                .matching(formulaSearchRequest.getSourceDocument().getId()).createQuery());

        isEmpty = false;/*from w  ww  . j av a 2 s  .c  o  m*/
    }

    if (formulaSearchRequest.getConfiguration() != null
            && formulaSearchRequest.getConfiguration().getId() != null) {
        junction.must(qb.keyword().onField("co.configuration.id").ignoreFieldBridge()
                .matching(formulaSearchRequest.getConfiguration().getId()).createQuery());

        isEmpty = false;
    }

    if (formulaSearchRequest.getRevision() != null && formulaSearchRequest.getRevision().getId() != null) {
        junction.must(qb.keyword().onField("co.revision.id").ignoreFieldBridge()
                .matching(formulaSearchRequest.getRevision().getId()).createQuery());

        isEmpty = false;
    }

    if (formulaSearchRequest.getApplicationRun() != null
            && formulaSearchRequest.getApplicationRun().getId() != null) {
        junction.must(qb.keyword().onField("co.applicationrun.id").ignoreFieldBridge()
                .matching(formulaSearchRequest.getApplicationRun().getId()).createQuery());

        isEmpty = false;
    }

    if (formulaSearchRequest.getProgram() != null && formulaSearchRequest.getProgram().getId() != null) {
        junction.must(qb.keyword().onField("program.id").matching(formulaSearchRequest.getProgram().getId())
                .createQuery());

        isEmpty = false;
    }

    if (formulaSearchRequest.getElements() != null && !formulaSearchRequest.getElements().isEmpty()) {
        BooleanJunction<BooleanJunction> junctionElements = qb.bool();
        for (Element e : formulaSearchRequest.getElements().keySet()) {
            junctionElements.must(qb.keyword().onField("co.element").ignoreFieldBridge()
                    .matching(e.getElementName() + "=" + formulaSearchRequest.getElements().get(e))
                    .createQuery());

            isEmpty = false;
        }

        junction.must(junctionElements.createQuery());
    }

    if (formulaSearchRequest.getAnnotationContent() != null
            && !StringUtils.isEmpty(formulaSearchRequest.getAnnotationContent())) {
        junction.must(qb.keyword().onField("co.annotation").ignoreFieldBridge()
                .matching(formulaSearchRequest.getAnnotationContent()).createQuery());

        isEmpty = false;
    }

    if (formulaSearchRequest.getFormulaContent() != null
            && !StringUtils.isEmpty(formulaSearchRequest.getFormulaContent())) {
        junction.must(qb.keyword().wildcard().onField("co.distanceForm").ignoreFieldBridge()
                .matching(formulaSearchRequest.getFormulaContent() + "*").createQuery());

        isEmpty = false;
    }

    if (formulaSearchRequest.getCoRuns() != null) {
        junction.must(qb.keyword().onField("coRuns").ignoreFieldBridge()
                .matching(formulaSearchRequest.getCoRuns()).createQuery());

        isEmpty = false;
    }

    SearchResponse<Formula> fsr = new SearchResponse<Formula>();

    if (!isEmpty) {
        Query query = junction.createQuery();
        logger.info(query);

        ftq = fullTextEntityManager.createFullTextQuery(query, Formula.class);
        fsr.setTotalResultSize(ftq.getResultSize());

        if (pagination != null) {
            ftq.setFirstResult(pagination.getPageSize() * (pagination.getPageNumber() - 1));
            ftq.setMaxResults(pagination.getPageSize());
        }
        fsr.setResults(ftq.getResultList());
    } else {
        if (pagination != null) {
            fsr.setResults(getAllFormulas(pagination));
        } else {
            fsr.setResults(getAllFormulas());
        }
        fsr.setTotalResultSize(getNumberOfRecords());
    }

    return fsr;
}

From source file:se.vgregion.usdservice.USDServiceImpl.java

private static Issue resolveIssue(String refNum, int i, String fallbackType, String associated, Document doc)
        throws XPathExpressionException {
    Issue issue = new Issue();
    issue.setRefNum(refNum);//from   w w  w  .j  a  v a2  s.  com

    // Get summary
    String summary = extractAttribute(i, "summary", XPathConstants.STRING, doc);
    issue.setSummary(summary);

    // Get description
    String description = extractAttribute(i, "description", XPathConstants.STRING, doc);
    issue.setDescription(description);

    // Get status
    String statusSym = extractAttribute(i, "status.sym", XPathConstants.STRING, doc);
    issue.setStatus(statusSym);

    // Get web_url
    String webUrl = extractAttribute(i, "web_url", XPathConstants.STRING, doc);
    webUrl = webUrl.replaceFirst("vgms0005", "vgrusd.vgregion.se");
    issue.setUrl(webUrl);

    // Get type
    String type = extractAttribute(i, "type", XPathConstants.STRING, doc);
    if (StringUtils.isEmpty(type)) {
        type = fallbackType;
    }
    issue.setType(type);

    issue.setAssociated(associated);

    return issue;
}

From source file:ru.anr.base.BaseParent.java

/**
 * A short-cut for the often used variant
 * /*www . ja v a 2  s . c o  m*/
 * @param s
 *            A string
 * @return true, if the string is empty
 */
public static boolean isEmpty(Object s) {

    return StringUtils.isEmpty(s);
}

From source file:org.carewebframework.shell.plugins.PluginDefinition.java

/**
 * Returns a value's default if the initial value is null or empty.
 * /*from   w w  w .ja  v  a  2 s. c o  m*/
 * @param value The initial value.
 * @param manifestKey The manifest key from which to obtain the default value.
 * @return The initial value or, if it was null or empty, the default value.
 */
private String getValueWithDefault(String value, String manifestKey) {
    if (StringUtils.isEmpty(value) && manifest != null) {
        value = manifest.getMainAttributes().getValue(manifestKey);
    }

    return value;
}

From source file:architecture.ee.web.community.spring.controller.SocialConnectController.java

/**
 * Render the status of the connections to the service provider to the user
 * as HTML in their web browser./*from w w  w.ja  va 2 s  .c  o m*/
 */
@RequestMapping(value = "/{providerId}", method = RequestMethod.GET)
// @ResponseBody
public Object connect(@PathVariable String providerId, NativeWebRequest request, Model model) {
    setNoCache(request);
    SocialConnectController.setOutputFormat(request);
    log.debug("status connections ==================");
    User user = SecurityHelper.getUser();
    SocialConnect account = null;
    if (!user.isAnonymous()) {
        try {
            account = socialConnectManager.getSocialConnect(user, providerId);
            model.addAttribute("profile", account.getConnection().fetchUserProfile());
        } catch (Exception e) {
            model.addAttribute("error", e.getMessage());
        }
    } else {
        String onetime = (String) sessionStrategy.getAttribute(request, "onetime");
        log.debug("using onetime:" + onetime);
        if (!StringUtils.isEmpty(onetime)) {
            account = (SocialConnect) getOnetimeObject(onetime);
            if (account != null) {

                if (architecture.common.util.StringUtils.equals(account.getProviderId(), providerId)) {
                    try {
                        log.debug("getting profile.");
                        UserProfile userProfile = account.getConnection().fetchUserProfile();
                        log.debug("user profile:" + userProfile);
                        model.addAttribute("profile", userProfile);
                    } catch (Exception e) {
                        log.warn(e);
                        model.addAttribute("error", e.getMessage());
                    }
                } else {
                    account = socialConnectManager.createSocialConnect(user,
                            ServiceProviderHelper.toMedia(providerId));
                }
            }
        }
    }
    if (account == null) {
        account = socialConnectManager.createSocialConnect(user, ServiceProviderHelper.toMedia(providerId));
    }
    model.addAttribute("user", user);
    model.addAttribute("connect", account);
    request.getNativeResponse(HttpServletResponse.class).setContentType("text/html;charset=UTF-8");
    return "/html/connect/social-status";
}

From source file:com.krypc.hl.pr.controller.PatientRecordController.java

@RequestMapping(value = "/getPatientRecordRequestList", method = { RequestMethod.POST, RequestMethod.GET })
public ResponseWrapper getPatientRecordRequestList(HttpServletRequest request, HttpServletResponse response) {
    logger.info("PatientRecordController---getPatientRecordRequestList()--STARTS");
    ResponseWrapper wrapper = new ResponseWrapper();
    String data = request.getParameter("data");
    try {//from ww  w  .j av  a 2s .com
        if (utils.verifychaincode()) {
            if (data != null && !data.isEmpty()) {
                JSONObject queryData = (JSONObject) new JSONParser().parse(data);
                String patientSSN = ((String) queryData.get("patientSSN"));
                String user = ((String) queryData.get("user"));
                if (!StringUtils.isEmpty(patientSSN) && !StringUtils.isEmpty(user)) {
                    ArrayList<String> argss = new ArrayList<>(
                            Arrays.asList(Constants.MethodName.getpatientrecordrequest.toString()));
                    argss.addAll(Arrays.asList(patientSSN));
                    QueryRequest queryrequest = new QueryRequest();
                    queryrequest.setArgs(argss);
                    queryrequest.setChaincodeID(utils.getChaincodeName().getChainCodeID());
                    queryrequest.setChaincodeName(utils.getChaincodeName().getTransactionID());
                    queryrequest.setChaincodeLanguage(ChaincodeLanguage.JAVA);
                    Member member = peerMembershipServicesAPI.getChain().getMember(user);
                    wrapper.resultObject = member.query(queryrequest);
                    wrapper = convertQueryResponse(wrapper);
                } else {
                    wrapper.setError(ERROR_CODES.MANDATORY_FIELDS_MISSING);
                }
            } else {
                wrapper.setError(ERROR_CODES.MANDATORY_FIELDS_MISSING);
            }
        } else {
            wrapper.setError(ERROR_CODES.CHAINCODE_NOT_DEPLOYED);
        }
    } catch (Exception e) {
        wrapper.setError(ERROR_CODES.INTERNAL_ERROR);
        logger.error("PatientRecordController---getPatientRecordRequestList()--ERROR " + e);
    }
    logger.info("PatientRecordController---getPatientRecordRequestList()--ENDS");
    return wrapper;
}