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:me.doshou.admin.monitor.web.controller.JPAQLExecutorController.java

@PageableDefaults(pageNumber = 0, value = 10)
@RequestMapping(value = "/ql", method = RequestMethod.POST)
public String executeQL(final @RequestParam("ql") String ql, final Model model, final Pageable pageable) {

    model.addAttribute("sessionFactory", HibernateUtils.getSessionFactory(em));

    try {/*from www. ja  v a 2s .c  om*/
        new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
            @Override
            public Void doInTransaction(TransactionStatus status) {
                //1?ql
                try {
                    Query query = em.createQuery(ql);
                    int updateCount = query.executeUpdate();
                    model.addAttribute("updateCount", updateCount);
                    return null;
                } catch (Exception e) {
                }
                //2 ?ql
                String findQL = ql;
                String alias = QueryUtils.detectAlias(findQL);
                if (StringUtils.isEmpty(alias)) {
                    Pattern pattern = Pattern.compile("^(.*\\s*from\\s+)(.*)(\\s*.*)",
                            Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
                    findQL = pattern.matcher(findQL).replaceFirst("$1$2 o $3");
                }
                String countQL = QueryUtils.createCountQueryFor(findQL);
                Query countQuery = em.createQuery(countQL);
                Query findQuery = em.createQuery(findQL);
                findQuery.setFirstResult(pageable.getOffset());
                findQuery.setMaxResults(pageable.getPageSize());

                Page page = new PageImpl(findQuery.getResultList(), pageable,
                        (Long) countQuery.getSingleResult());

                model.addAttribute("resultPage", page);
                return null;
            }
        });
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        model.addAttribute(Constants.ERROR, sw.toString());
    }

    return showQLForm();
}

From source file:cn.guoyukun.spring.web.controller.permission.PermissionList.java

public void assertHasPermission(String permission, String errorCode) {
    if (StringUtils.isEmpty(errorCode)) {
        errorCode = getDefaultErrorCode();
    }/*w  ww .  ja va 2s .  c om*/
    String resourcePermission = resourcePermissions.get(permission);
    if (resourcePermission == null) {
        resourcePermission = this.resourceIdentity + ":" + permission;
    }
    if (!SecurityUtils.getSubject().isPermitted(resourcePermission)) {
        throw new UnauthorizedException(MessageUtils.message(errorCode, resourcePermission));
    }
}

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

/**
 * Get job applications<br/>/*  w ww  .j  a  va2  s  .com*/
 * If a job ID is not given, the method will get all applications<br/>
 * Otherwise it will get the applications which point to the job with job ID<br/>
 * 
 * @param _jobId
 *            job ID
 * @return applications list
 */
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<List<JobApplicationResource>> jobApplications(
        @RequestParam(name = "_jobId", required = false) String _jobId,
        @RequestParam(name = "status", required = false) String status) {
    List<JobApplication> appsList = new ArrayList<>();
    System.out.println("status=" + status);
    if (!StringUtils.isEmpty(_jobId) && !StringUtils.isEmpty(status)) { // by
        // two
        // factors
        System.out.println("getting according to two factors, jobappdao=" + (jobAppDao == null));
        List<JobApplication> appsByJobIdList = jobAppDao.findByJobPostingId(_jobId);
        if (appsByJobIdList != null) {

            for (JobApplication app : appsByJobIdList) {
                System.out.println("found appsbyjobid size: " + appsByJobIdList.size());
                System.out.println("appstatus=" + app.getStatus());
                System.out.println("hooray!");
                if (app.getStatus().equals(status)) {
                    appsList.add(app);
                }
            }
        }
    } else if (!StringUtils.isEmpty(_jobId)) {
        appsList = jobAppDao.findByJobPostingId(_jobId);
    } else if (!StringUtils.isEmpty(status)) {
        appsList = jobAppDao.findByStatus(status);
    } else {
        appsList = jobAppDao.findAll();
    }

    if (appsList == null) {
        appsList = new ArrayList<>();
    }

    System.out.println("appsList size: " + appsList.size());

    List<JobApplicationResource> appListResource = appResourceAssembler.toResources(appsList);
    return new ResponseEntity<List<JobApplicationResource>>(appListResource, HttpStatus.OK);
}

From source file:com.phoenixnap.oss.ramlapisync.generation.rules.spring.SpringRestClientMethodBodyRule.java

public SpringRestClientMethodBodyRule(String restTemplateFieldName, String baseUrlFieldName) {
    if (StringUtils.hasText(restTemplateFieldName)) {
        this.restTemplateFieldName = restTemplateFieldName;
    }//from   ww  w .  j  av  a2 s  . com
    if (!StringUtils.isEmpty(baseUrlFieldName)) {
        this.baseUrlFieldName = baseUrlFieldName;
    }
}

From source file:org.wallride.web.controller.admin.customfield.CustomFieldSearchController.java

@RequestMapping(method = RequestMethod.GET)
public String search(@PathVariable String language,
        @Validated @ModelAttribute("form") CustomFieldSearchForm form, BindingResult result,
        @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest)
        throws UnsupportedEncodingException {
    Page<CustomField> customFields = customfieldService.getCustomFields(form.toCustomFieldSearchRequest(),
            pageable);/*from ww  w .j  av  a  2 s. c om*/

    model.addAttribute("customFields", customFields);
    model.addAttribute("pageable", pageable);
    model.addAttribute("pagination", new Pagination<>(customFields, 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"));
    }

    return "customfield/index";
}

From source file:org.obiba.mica.micaConfig.service.EntityConfigService.java

private String getResourceAsString(String path, String defaultValue) {

    if (StringUtils.isEmpty(path))
        return defaultValue;

    Resource resource = new DefaultResourceLoader().getResource(path);
    try (Scanner s = new Scanner(resource.getInputStream())) {
        return s.useDelimiter("\\A").hasNext() ? s.next() : "";
    } catch (IOException e) {
        return defaultValue;
    }/*ww w . j av a 2s. c o  m*/
}

From source file:org.wallride.web.controller.admin.comment.CommentSearchController.java

@RequestMapping(method = RequestMethod.GET)
public String search(@PathVariable String language, @Validated CommentSearchForm form, BindingResult result,
        @PageableDefault(value = 50, sort = "date", direction = Sort.Direction.DESC) Pageable pageable,
        Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException {
    Page<Comment> comments = commentService.getComments(form.toCommentSearchRequest(), pageable);

    model.addAttribute("form", form);
    model.addAttribute("comments", comments);
    model.addAttribute("pageable", pageable);
    model.addAttribute("pagination", new org.wallride.web.support.Pagination<>(comments, 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"));
    }/* ww  w . j  a  v a2s .  c  om*/

    return "comment/index";
}

From source file:$.AccountRepositoryImpl.java

@Override
    public List<AccountDTO> loadAccountsByOperationAndTypeAndUsername(String accountType, String username)
            throws Exception {
        final StringBuilder queryString = new StringBuilder();
        queryString.append("select account from AccountDTO account where account.accountUser.owner.username='")
                .append(username).append("'");
        if (!StringUtils.isEmpty(accountType) && !ALL_FILTER.equalsIgnoreCase(accountType)) {
            queryString.append(" and account.accountType.code='" + accountType + "'");
        }/* w w  w .  ja  va2 s . com*/
        final QueryJpaCallback<AccountDTO> query = new QueryJpaCallback<AccountDTO>(queryString.toString(), false);
        return retrieveList(query);

    }

From source file:com.dickthedeployer.dick.web.controller.ProjectController.java

@RequestMapping(method = GET)
public List<ProjectModel> getProjects(@RequestParam("page") int page, @RequestParam("size") int size,
        @RequestParam(required = false, name = "name") String name) {
    if (StringUtils.isEmpty(name)) {
        return projectService.getProjects(page, size);
    } else {//w  w w  . j  av a2  s . c o m
        return projectService.getProjectsLikeName(name, page, size);
    }
}