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:be.roots.taconic.pricingguide.domain.Pricing.java

@JsonIgnore
public String getCategoryCode() {
    if (!StringUtils.isEmpty(category)) {
        return category.replaceAll(DefaultUtil.PRICING_CATEGORY_NON_PROFIT, "").toUpperCase().trim();
    }/* w  w w .  j a v  a 2  s.co m*/
    return category;
}

From source file:com.zxy.commons.apidocs.conf.ApplicationSwaggerConfig.java

@Bean
public Docket appApi() {
    Docket docket = new Docket(DocumentationType.SWAGGER_2);
    //        if(groupName!=null && groupName.length() > 0) {
    //            docket.groupName(groupName);
    //        }//from   w w  w.j  a v a  2s.  c o  m
    String host = env.getProperty("apidocs.host", "");
    String port = env.getProperty("apidocs.port", "");
    String basePath = env.getProperty("apidocs.basepath", "");
    if (StringUtils.isEmpty(host)) {
        try {
            host = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            host = "localhost";
        }
    }
    if (!StringUtils.isEmpty(port)) {
        docket.host(host + ":" + port);
    } else {
        docket.host(host);
    }
    if (!StringUtils.isEmpty(basePath)) {
        docket.pathProvider(new AbstractPathProvider() {

            @Override
            protected String getDocumentationPath() {
                return "/";
            }

            @Override
            protected String applicationPath() {
                return basePath;
            }
        });
    }
    ApiSelectorBuilder builder = docket.apiInfo(apiInfo())
            //          .enable(enabled)
            .forCodeGeneration(true).select();
    Predicate<String> paths = appPaths();
    if (paths != null) {
        builder.paths(paths);
    }
    return builder.build();
}

From source file:org.wallride.web.controller.admin.tag.TagSearchController.java

@RequestMapping
public String search(@PathVariable String language, @Validated @ModelAttribute("form") TagSearchForm form,
        BindingResult errors, @PageableDefault(50) Pageable pageable, Model model,
        HttpServletRequest servletRequest) throws UnsupportedEncodingException {
    Page<Tag> tags = tagService.getTags(form.toTagSearchRequest(), pageable);

    model.addAttribute("tags", tags);
    model.addAttribute("pageable", pageable);
    model.addAttribute("pagination", new Pagination<>(tags, servletRequest));

    UriComponents uriComponents = ServletUriComponentsBuilder.fromRequest(servletRequest)
            .queryParams(ControllerUtils.convertBeanForQueryParams(form, conversionService)).build();
    if (!StringUtils.isEmpty(uriComponents.getQuery())) {
        model.addAttribute("query", URLDecoder.decode(uriComponents.getQuery(), "UTF-8"));
    }//from  ww  w . j  a v a2 s . c o m

    return "tag/index";
}

From source file:com.web.mavenproject6.controller.CameraController.java

@ResponseBody
@RequestMapping(value = "/camera", method = RequestMethod.POST)
public String upload(@RequestParam(value = "imgdata", required = false) String imgdata,
        HttpServletRequest request)/* w w  w  . j a va2 s  . c  o m*/
        throws FileNotFoundException, IOException, GeneralSecurityException, JSONException {

    if (StringUtils.isEmpty(imgdata)) {
        //return (new Date()).toString();
    }

    JSONObject o = new JSONObject(imgdata);
    imgdata = new String(Base64.getDecoder().decode(o.getString("qr")));

    JSONArray ar = new JSONArray();
    JSONObject resultJson = new JSONObject();
    JSONObject obj = new JSONObject();

    obj.put("propNumber", "0000001");
    obj.put("propDate", (new Date()).toString());
    obj.put("fname", "?");
    obj.put("sname", "");//
    obj.put("tname", "?");//
    obj.put("pasport", "898999");//
    obj.put("level", "10");
    obj.put("userId", "10");
    ar.add(obj);
    resultJson.put("user", ar);

    simpleLog.add(obj);
    return resultJson.toString();
}

From source file:org.ihtsdo.otf.refset.security.RefsetIdentityService.java

protected UserDetails authenticate(String userName, String token) {

    LOGGER.debug("Authenticating user {} ", userName);

    User user = getGuestUser();/*ww  w  .  j  av a  2s .  c  om*/

    MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>();
    params.add("username", userName);
    params.add("password", token);
    params.add("queryName", "getUserByNameAuth");

    try {

        if (StringUtils.isEmpty(userName) || StringUtils.isEmpty(token)) {

            throw new AccessDeniedException("User is unauthorized. Please check user name and password");
        }
        Assert.notNull(rt, "Rest template can not be empty");

        LOGGER.debug("Calling authentication service with URL {}, User {} and Parameters {} ", otfServiceUrl,
                userName);

        JsonNode obj = rt.postForObject(otfServiceUrl, params, JsonNode.class);

        LOGGER.debug("authentication service call successfully returned with {} ", obj);

        //populate user with other user details
        populateUser(user, obj);

        //now check if user has access to Refset app.
        params = new LinkedMultiValueMap<String, String>();
        params.add("username", userName);
        params.add("queryName", "getUserApps");

        LOGGER.debug("Calling autorization service with URL {}, User {} and Parameters {} ", otfServiceUrl,
                userName);

        JsonNode appJson = rt.postForObject(otfServiceUrl, params, JsonNode.class);

        LOGGER.debug("autorization service call successfully returned with {} ", appJson);

        JsonNode apps = appJson.get("apps");
        Collection<RefsetRole> roles = new ArrayList<RefsetRole>();

        for (JsonNode object : apps) {

            if (object != null && object.asText().equals(APP_NAME)) {

                RefsetRole role = new RefsetRole();
                role.setAuthority(ROLE_USER);
                roles.add(role);
                break;
            }
        }
        user.setAuthorities(roles);

        if (isUserHasRole(user)) {

            String info = userName + ":" + token;
            Token key = service.allocateToken(info);
            user.setToken(key.getKey());
        }

    } catch (Exception e) {

        LOGGER.error("Error during authentication for user:password - {} ", userName + ":" + token, e);

        throw new AccessDeniedException("User is unauthorized. Please check user name and password");
    }

    return user;

}

From source file:org.home.petclinic2.controller.PetController.java

/**
 * Retrieves all owners or allows for last name search
 * //from  www  .ja  v a2 s .co m
 * @param owner
 * @param result
 * @param model
 * @return
 */
@RequestMapping(value = "/pet", method = RequestMethod.GET)
public String processFindForm(Pet pet, BindingResult result, Model model) {

    // allow parameterless GET request for /pet to return all records
    Collection<Pet> results = null;
    if (StringUtils.isEmpty(pet.getName())) {
        // find all pets
        results = clinicService.findAllPets();
    } else {
        // find owners by last name
        results = clinicService.findPetByName(pet.getName());
    }

    if (results == null) {
        throw new IllegalStateException("Results were null. This should not happen");
    } else if (results.size() < 1) {
        // no pets found
        result.rejectValue("name", "notFound", "not found");
        return "pet/findPet";
    } else if (results.size() > 1) {
        // multiple pets found
        // here we've specified how we want to reference the model object
        model.addAttribute("selections", results);
        return "pet/pets";
    } else {
        // 1 pet found
        pet = results.iterator().next();
        return "redirect:/pet/" + pet.getId();
    }
}

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

protected String defaultViewPrefix() {
    String currentViewPrefix = "";
    RequestMapping requestMapping = AnnotationUtils.findAnnotation(getClass(), RequestMapping.class);
    if (requestMapping != null && requestMapping.value().length > 0) {
        currentViewPrefix = requestMapping.value()[0];
    }//  w w  w.jav  a  2 s.c o  m

    if (StringUtils.isEmpty(currentViewPrefix)) {
        currentViewPrefix = this.entityClass.getSimpleName();
    }

    return currentViewPrefix;
}

From source file:be.roots.taconic.pricingguide.domain.Toc.java

public String getPageSequence() {

    int currentPageNumber = 1;
    int nextPageNumber = 1;

    String pageSequence = "";
    for (TocEntry entry : getEntriesSorted()) {

        // setting the correct page number
        if (entry.isNotSecondItemOnSamePage()) {
            currentPageNumber = nextPageNumber;
        }//from   ww w.j a  v  a2  s  . c  om
        entry.setFinalPageNumber(currentPageNumber);
        if (entry.isNotSecondItemOnSamePage() && !entry.isModelHeader()) {
            nextPageNumber = currentPageNumber + entry.getNumberOfPages();
        }

        // calculating the pagesequence
        if (entry.getNumberOfPages() > 0) {
            if (!StringUtils.isEmpty(pageSequence)) {
                pageSequence += ",";
            }
            if (entry.getNumberOfPages() == 1) {
                pageSequence += entry.getOriginalPageNumber();
            } else {
                pageSequence += entry.getOriginalPageNumber() + "-"
                        + (entry.getOriginalPageNumber() + entry.getNumberOfPages() - 1);
            }
        }
    }

    return pageSequence;

}

From source file:net.turnbig.jdbcx.utilities.JsonMapper.java

public <T> T getBean(String jsonString, Class<T> beanClazz) {
    if (StringUtils.isEmpty(jsonString)) {
        return null;
    }//ww w. j a  v  a 2 s.  c o  m

    try {
        return mapper.readValue(jsonString, beanClazz);
    } catch (Exception e) {
        logger.warn("convert string to bean.", e);
        return null;
    }
}

From source file:it.geosolutions.opensdi2.configurations.model.OSDIConfigurationKVP.java

@Override
public boolean validateIDs() {
    if (StringUtils.isEmpty(scopeID) || StringUtils.containsWhitespace(scopeID)
            || !org.apache.commons.lang.StringUtils.isAlphanumeric(scopeID)) {
        return false;
    }/*from   w  w w .j  a v a2s . co  m*/
    if (StringUtils.isEmpty(instanceID) || StringUtils.containsWhitespace(instanceID)
            || !org.apache.commons.lang.StringUtils.isAlphanumeric(instanceID)) {
        return false;
    }
    return true;
}