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.ge.predix.web.cors.CORSFilter.java

private boolean isCorsXhrAllowedRequestUri(final String uri) {
    if (StringUtils.isEmpty(uri)) {
        return false;
    }//  w  w w .j  a va  2s .  com

    for (Pattern pattern : this.corsXhrAllowedUriPatterns) {
        // Making sure that the pattern matches
        if (pattern.matcher(uri).find()) {
            return true;
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("The '%s' URI does not allow CORS requests with the 'X-Requested-With' header.",
                uri));
    }
    return false;
}

From source file:your.microservice.core.util.YourServletUriComponentsBuilder.java

/**
 * Removes any path extension from the {@link HttpServletRequest#getRequestURI()
 * requestURI}. This method must be invoked before any calls to {@link #path(String)}
 * or {@link #pathSegment(String...)}./*  w w w .j  a  v a 2 s  .com*/
 * <pre>
 *  // GET http://foo.com/rest/books/6.json
 *
 *  YourServletUriComponentsBuilder builder = YourServletUriComponentsBuilder.fromRequestUri(this.request);
 *  String ext = builder.removePathExtension();
 *  String uri = builder.path("/pages/1.{ext}").buildAndExpand(ext).toUriString();
 *
 *  assertEquals("http://foo.com/rest/books/6/pages/1.json", result);
 * </pre>
 * @return the removed path extension for possible re-use, or {@code null}
 * @since 4.0
 */
public String removePathExtension() {
    String extension = null;
    if (this.servletRequestURI != null) {
        String filename = WebUtils.extractFullFilenameFromUrlPath(this.servletRequestURI);
        extension = StringUtils.getFilenameExtension(filename);
        if (!StringUtils.isEmpty(extension)) {
            int end = this.servletRequestURI.length() - extension.length() + 1;
            replacePath(this.servletRequestURI.substring(0, end));
        }
        this.servletRequestURI = null;
    }
    return extension;
}

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

@RequestMapping(value = "/signin.json", method = RequestMethod.POST)
@ResponseBody/*from w ww  . java  2  s  . c  o  m*/
public User signin(@RequestParam(value = "onetime", defaultValue = "", required = false) String onetime,
        HttpServletRequest request) {
    User user = SecurityHelper.getUser();
    if (StringUtils.isEmpty(onetime)) {
        onetime = (String) request.getSession().getAttribute("onetime");
    }
    log.debug("signin onetime:" + onetime);
    if (!StringUtils.isEmpty(onetime)) {
        SocialConnect socialConnect = (SocialConnect) getOnetimeObject(onetime);
        log.debug("signin account:" + socialConnect);
        if (socialConnect != null) {
            log.debug("signin account user :" + socialConnect.getProviderUserId());
            User foundUser;
            try {
                foundUser = findUser(2, socialConnect.getProviderId(), socialConnect.getProviderUserId());
                log.debug("signin  foundUser :" + foundUser);
                if (foundUser != null) {
                    createSecurityContext(foundUser, request);
                    UserTemplate template = new UserTemplate(foundUser);
                    template.setLastLoggedIn(new Date());
                    try {
                        userManager.updateUser(template);
                    } catch (Exception e) {
                    }

                    try {
                        log.debug("UPDATE SOCIAL CONNECT DATA ");
                        SocialConnect existSocialConnect = socialConnectManager.getSocialConnect(foundUser,
                                socialConnect.getProviderId());
                        if (isUpdated(existSocialConnect, socialConnect.getConnection())) {
                            setConnectionData(existSocialConnect, socialConnect.getConnection());
                            socialConnectManager.updateSocialConnect(existSocialConnect);
                        }
                    } catch (ConnectNotFoundException e) {
                        log.warn(e);
                    }
                    cleanUpOnetimeObject(onetime);
                    request.getSession().removeAttribute("onetime");

                    return foundUser;
                }
            } catch (UserNotFoundException e1) {
                log.debug(e1);
            }
        }
    }
    return user;
}

From source file:uk.gov.nationalarchives.discovery.taxonomy.common.repository.lucene.InMemoryIAViewRepository.java

private List<Field> getCopyIAViewFieldsToTaxonomyField(InformationAssetView iaView,
        InformationAssetViewFields texttax) {
    List<Field> listOfFields = new ArrayList<Field>();

    listOfFields.add(new TextField(texttax.toString(), iaView.getDESCRIPTION(), Field.Store.NO));
    if (!StringUtils.isEmpty(iaView.getTITLE())) {
        listOfFields.add(new TextField(texttax.toString(), iaView.getTITLE(), Field.Store.NO));
    }/*from  ww w  .  jav a  2s  . co m*/
    if (!StringUtils.isEmpty(iaView.getCONTEXTDESCRIPTION())) {
        listOfFields.add(new TextField(texttax.toString(), iaView.getCONTEXTDESCRIPTION(), Field.Store.NO));
    }
    if (iaView.getCORPBODYS() != null) {
        for (String corpBody : iaView.getCORPBODYS()) {
            listOfFields.add(new TextField(texttax.toString(), corpBody, Field.Store.NO));
        }
    }
    if (iaView.getSUBJECTS() != null) {
        for (String subject : iaView.getSUBJECTS()) {
            listOfFields.add(new TextField(texttax.toString(), subject, Field.Store.NO));
        }
    }

    if (iaView.getPERSON_FULLNAME() != null) {
        for (String person : iaView.getPERSON_FULLNAME()) {
            listOfFields.add(new TextField(texttax.toString(), person, Field.Store.NO));
        }
    }
    if (iaView.getPLACE_NAME() != null) {
        for (String place : iaView.getPLACE_NAME()) {
            listOfFields.add(new TextField(texttax.toString(), place, Field.Store.NO));
        }
    }
    if (iaView.getCATDOCREF() != null) {
        listOfFields.add(new TextField(texttax.toString(), iaView.getCATDOCREF(), Field.Store.NO));
    }
    return listOfFields;
}

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

@Override
public UserDTO findUser(final String email, final boolean includePassword)
        throws AuthenticationFailureException {

    UserDTO user = null;/*from w  w w. j a  va2  s .  co m*/

    if (!StringUtils.isEmpty(email)) {

        user = this.userDao.findUserDTO(email);

        if (user != null && !includePassword) {
            user.setPassword(null);
        }
    }

    if (user == null) {
        throw new AuthenticationFailureException("Authentication failed. " + "Please verify your email address "
                + "and password and try again.");
    }

    return user;
}

From source file:com.biz.report.service.impl.ReportServiceImpl.java

@Override
public List<ItemDTO> readItemByType(String type, String year, String month) {
    if (!StringUtils.isEmpty(month) && month.contains("[")) {
        month = month.substring(1, month.length() - 1);
    }/*from w w w. j ava  2  s. co  m*/
    if (!StringUtils.isEmpty(type) && !type.contains("'")) {
        type = "'" + type + "'";
    }
    List list = reportDao.readItemByType(type, year, month);
    List<ItemDTO> itemDTOs = new ArrayList<ItemDTO>();
    for (Object object : list) {
        ItemDTO itemDTO = constructItemDTO(object);
        itemDTOs.add(itemDTO);
    }
    return itemDTOs;
}

From source file:com.pubkit.platform.messaging.protocol.pkmp.PKMPInBoundEventHandler.java

private void handleUnSubscribe(PKMPUnSubscribe unsubscribe, WebSocketSession session) {
    String topic = unsubscribe.getTopic();
    if (topic == null || StringUtils.isEmpty(topic)) {
        LOG.error("Client {" + unsubscribe.getClientId() + "} failed to unsubscribe topic {"
                + unsubscribe.getTopic() + "}. Invalid topic");

        PKMPUnSubsAck errorAck = new PKMPUnSubsAck(unsubscribe.getClientId(), topic, PKMPSubsAck.INVALID_TOPIC);
        sendPayload(errorAck, session);//from   ww w.j a  v a 2 s  . c om

        return;
    }
    boolean tokenValid = validateAccessToken(unsubscribe.getClientId(), unsubscribe.getSessionToken(), session);
    if (!tokenValid) {
        LOG.error("Client {" + unsubscribe.getClientId() + "} failed to unsubscribe topic {" + topic
                + "}. Invalid token");
        PKMPUnSubsAck errorAck = new PKMPUnSubsAck(unsubscribe.getClientId(), topic, PKMPSubsAck.INVALID_TOKEN);
        sendPayload(errorAck, session);

        return;
    }

    PKMPConnection pKMPConnection = messageStoreService.getConnection(unsubscribe.getClientId());
    if (pKMPConnection != null && pKMPConnection.getSessionId().equals(session.getId())) {
        messageStoreService.subscribeTopic(topic, pKMPConnection);
        LOG.debug("Client id {" + unsubscribe.getClientId() + "} unsubscribed to topic {" + topic + "}");

        PKMPUnSubsAck pKMPUnSubsAck = new PKMPUnSubsAck(unsubscribe.getClientId(), topic);
        sendPayload(pKMPUnSubsAck, session);
    } else {
        LOG.error("Client {" + unsubscribe.getClientId() + "} failed to unsubscribe topic {" + topic
                + "}. No connection found so closing connection");

        PKMPUnSubsAck errorAck = new PKMPUnSubsAck(unsubscribe.getClientId(), topic,
                PKMPSubsAck.CONNECTION_ERROR);
        sendPayload(errorAck, session);
    }
}

From source file:com.baidu.rigel.biplatform.tesseract.node.service.impl.IsNodeServiceImpl.java

public Node getNodeByIpAndPort(Node node, String clusterName) {
    LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_BEGIN, "getNodeByIpAndPort",
            "[node:" + node + "][clusterName:" + clusterName + "]"));
    if (node == null || StringUtils.isEmpty(node.getAddress()) || node.getPort() <= 0
            || StringUtils.isEmpty(clusterName)) {
        LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_EXCEPTION, "getNodeByIpAndPort",
                "[node:" + node + "][clusterName:" + clusterName + "]"));
        throw new IllegalArgumentException();
    }//www.j  a  va  2 s .c  om
    List<Node> nodeList = this.getNodeListByClusterName(clusterName);
    Node result = null;
    if (nodeList != null) {
        for (Node currNode : nodeList) {
            if (currNode.equals(node)) {
                result = currNode;
                break;
            }
        }
    }
    LOGGER.info(String.format(LogInfoConstants.INFO_PATTERN_FUNCTION_END, "getNodeByIpAndPort",
            "[node:" + node + "][clusterName:" + clusterName + "]"));
    return result;
}

From source file:burstcoin.jminer.core.CoreProperties.java

/**
 * Gets solo server./*from   www  . j  a  v a 2s .  c  o  m*/
 *
 * @return the solo server
 */
public static String getSoloServer() {
    if (soloServer == null) {
        soloServer = asString("soloServer", DEFAULT_SOLO_SERVER);
        boolean poolMining = isPoolMining();
        if (!poolMining && soloServer.equals(DEFAULT_SOLO_SERVER)) {
            LOG.info("Default '" + DEFAULT_SOLO_SERVER + "' used for 'soloServer' property!");
        }
    }
    return !StringUtils.isEmpty(soloServer) ? soloServer : DEFAULT_SOLO_SERVER;
}

From source file:au.com.ors.rest.controller.JobAppController.java

/**
 * Update an application by its candidate<br/>
 * //w  w  w .ja  v  a2s .  co  m
 * @param application
 *            an application JSON object
 * @return a HATEOAS application after updated
 * @throws JobApplicationNotFoundException
 * @throws JobAppStatusCannotModifyException
 * @throws JobAppMalformatException
 * @throws TransformerException
 */
@RequestMapping(value = "/{_appId}", method = RequestMethod.PUT)
@ResponseBody
public ResponseEntity<JobApplicationResource> updateApplication(@PathVariable(value = "_appId") String _appId,
        @RequestBody JobApplication application) throws JobApplicationNotFoundException,
        JobAppStatusCannotModifyException, JobAppMalformatException, TransformerException {
    // check if the application exist
    JobApplication existApp = jobAppDao.findById(_appId);

    if (existApp == null) {
        throw new JobApplicationNotFoundException(
                "Job application with _appId=" + _appId + " not found in database.");
    }

    application.set_appId(_appId);
    application.setStatus(existApp.getStatus());

    // check if the application can be updated in current status
    String status = existApp.getStatus();
    if (StringUtils.isEmpty(status)
            || !status.equalsIgnoreCase(JobAppStatus.APP_SUBMITTED_NOT_PROCESSED.name())) {
        // only in submitted_but_not_processed status the application can be
        // updated
        throw new JobAppStatusCannotModifyException("Job application with _appId=" + _appId
                + " is in the status of: '" + status + "', and cannot be modified currently.");
    }

    // check if the application has been modified, only if so do update
    // method, otherwise return the application directly
    if (StringUtils.isEmpty(existApp.get_jobId()) || StringUtils.isEmpty(application.get_jobId())
            || !existApp.get_jobId().equals(application.get_jobId())) {
        // _jobId is not permitted to be updated
        throw new JobAppMalformatException("Job application malformat on _jobId: request ["
                + application.get_jobId() + "], database [" + existApp.get_jobId() + "]");
    }

    List<Boolean> needUpdateInfoList = new ArrayList<>();

    // check required information (cannot be null or empty)

    // check driver license
    String appDriverLicenseNumber = application.getDriverLicenseNumber();
    String driverLicenseNumber = existApp.getDriverLicenseNumber();
    boolean needUpdateDriverLicense = false;
    if (checkApplicationRequiredInfoEmpty(appDriverLicenseNumber, driverLicenseNumber)) {
        throw new JobAppMalformatException("Job application malformat on driver license number: request ["
                + appDriverLicenseNumber + "], database [" + driverLicenseNumber + "]");
    } else {
        needUpdateDriverLicense = checkNeedUpdate(appDriverLicenseNumber, driverLicenseNumber);
        needUpdateInfoList.add(needUpdateDriverLicense);
    }

    // check full name
    String appFullName = application.getFullName();
    String fullName = existApp.getFullName();
    boolean needUpdateFullName = false;
    if (checkApplicationRequiredInfoEmpty(appFullName, fullName)) {
        throw new JobAppMalformatException("Job application malformat on full name: request [" + appFullName
                + "], database [" + fullName + "]");
    } else {
        needUpdateFullName = checkNeedUpdate(appFullName, fullName);
        needUpdateInfoList.add(needUpdateFullName);
    }

    // check post code
    String appPostCode = application.getPostCode();
    String postCode = existApp.getPostCode();
    boolean needUpdatePostCode = false;
    if (checkApplicationRequiredInfoEmpty(appPostCode, postCode)) {
        throw new JobAppMalformatException("Job application malformat on post code: get from database ["
                + appPostCode + "], parameter [" + postCode + "]");
    } else {
        needUpdatePostCode = checkNeedUpdate(appPostCode, postCode);
        needUpdateInfoList.add(needUpdatePostCode);
    }

    // check not-required information

    // check text cover letter
    String appTextCoverLetter = application.getTextCoverLetter();
    String textCoverLetter = existApp.getTextCoverLetter();
    if (StringUtils.isEmpty(appTextCoverLetter)) {
        appTextCoverLetter = "";
        application.setTextCoverLetter("");
    }

    // String appTextCoverLetter = application.getTextCoverLetter();
    boolean needUpdateTextCoverLetter = checkNeedUpdate(appTextCoverLetter, textCoverLetter);
    needUpdateInfoList.add(needUpdateTextCoverLetter);

    // check text brief resume
    String appTextBriefResume = application.getTextBriefResume();
    String textBriefResume = existApp.getTextBriefResume();
    if (StringUtils.isEmpty(appTextBriefResume)) {
        appTextBriefResume = "";
        application.setTextBriefResume("");
    }

    boolean needUpdateTextBriefResume = checkNeedUpdate(appTextBriefResume, textBriefResume);
    needUpdateInfoList.add(needUpdateTextBriefResume);

    // check need update flag to decide whether do writing update into XML
    boolean needWriteUpdate = false;
    for (boolean need : needUpdateInfoList) {
        if (need) {
            needWriteUpdate = true;
            break;
        }
    }

    if (needWriteUpdate) {
        jobAppDao.update(application);
    }

    JobApplicationResource updatedAppResource = appResourceAssembler.toResource(application);

    return new ResponseEntity<JobApplicationResource>(updatedAppResource, HttpStatus.OK);
}