List of usage examples for org.springframework.util StringUtils isEmpty
public static boolean isEmpty(@Nullable Object str)
From source file:cn.guoyukun.spring.web.controller.permission.PermissionList.java
public void assertHasAllPermission(String[] permissions, String errorCode) { if (StringUtils.isEmpty(errorCode)) { errorCode = getDefaultErrorCode(); }//from ww w . j ava 2 s . c o m if (permissions == null || permissions.length == 0) { throw new UnauthorizedException( MessageUtils.message(errorCode, resourceIdentity + ":" + Arrays.toString(permissions))); } Subject subject = SecurityUtils.getSubject(); for (String permission : permissions) { String resourcePermission = resourcePermissions.get(permission); if (resourcePermission == null) { resourcePermission = this.resourceIdentity + ":" + permission; } if (!subject.isPermitted(resourcePermission)) { throw new UnauthorizedException( MessageUtils.message(errorCode, resourceIdentity + ":" + Arrays.toString(permissions))); } } }
From source file:org.psikeds.queryagent.interfaces.presenter.pojos.POJO.java
/** * @param obj//from w ww .j av a 2s . c o m * a POJO * @return the value 0 if argument Object is a POJO of same Class and its ID is equal to * the ID of this Object; * a value greater than 0 if the specified Object is a POJO but has no ID * or its ID is lexicographically less than the ID of this POJO; * a value less 0 else * @see java.lang.Object#equals(Object obj) * @see java.lang.String#equals(String str) * @throws IllegalArgumentException * if argument Object is null or not a POJO */ @Override public int compareTo(final Object obj) { // check that obj is not null and a pojo if (!(obj instanceof POJO)) { throw new IllegalArgumentException("Not a POJO: " + String.valueOf(obj)); } final POJO pojo = (POJO) obj; // check that this is the same type of pojo if (!pojo.getClass().equals(this.getClass())) { return pojo.getClass().getName().compareTo(this.getClass().getName()); } // pojos without IDs can never be compared if (StringUtils.isEmpty(pojo.getId())) { return 1; } if (StringUtils.isEmpty(this.getId())) { return -1; } // compare IDs return this.getId().compareTo(pojo.getId()); }
From source file:com.github.hateoas.forms.affordance.PartialUriTemplateComponents.java
public boolean hasVariables() { return baseUri.contains("{") || !StringUtils.isEmpty(queryTail) || fragmentIdentifier.contains("{"); }
From source file:com.biz.report.service.impl.CustomerServiceImpl.java
public List<Report3DataSet> readDataForBarChart(String customers, String year, String months) { if (!StringUtils.isEmpty(customers) && customers.contains("[")) { customers = customers.substring(1, customers.length() - 1); }//from w w w . j a v a2 s . c o m if (!StringUtils.isEmpty(months) && months.contains("[")) { months = months.substring(1, months.length() - 1); } List list = customerReportDao.readByMonth(customers, months, year); List<Report2> reportList = new MappingEngine().getPieChartReport(list); List<Report3DataSet> dataSets = new ArrayList<Report3DataSet>(); for (Report2 r : reportList) { dataSets.add(new Report3DataSet(r.getTypeName(), r.getAmount())); } return dataSets; }
From source file:org.appverse.web.framework.backend.frontfacade.mvc.schema.services.presentation.SchemaGeneratorServiceImpl.java
@RequestMapping(value = "/entity/{entity}/", method = RequestMethod.GET, produces = "application/schema+json") @Deprecated//from w w w . j a va2s . co m public String generateSchemaByEntityName(@PathVariable("entity") String entity) { String data = ""; if (StringUtils.isEmpty(entity)) { throw new PresentationException("invalid content"); } try { Class<?> clazz = Class.forName(entity); JsonSchema schema = entityConverter.convert(clazz, TypeDescriptor.valueOf(String.class), TypeDescriptor.valueOf(JsonSchema.class)); ObjectMapper mapper = new ObjectMapper(); mapper.configure(SerializationConfig.Feature.WRITE_ENUMS_USING_TO_STRING, true); mapper.configure(SerializationConfig.Feature.WRITE_NULL_PROPERTIES, false); mapper.configure(SerializationConfig.Feature.WRITE_NULL_MAP_VALUES, false); data = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(schema); } catch (ClassNotFoundException nsme) { throw new PresentationException("invalid class:" + entity, nsme); } catch (IOException e) { throw new PresentationException("schema generation exception", e); } catch (NullPointerException npe) { // workarround where entity have a setter without getter it fails to parse throw new PresentationException("entity have setter without getter", npe); } return data; }
From source file:org.wallride.web.controller.admin.article.ArticleSearchController.java
@RequestMapping(method = RequestMethod.GET) public String search(@PathVariable String language, @Validated @ModelAttribute("form") ArticleSearchForm form, BindingResult result, @PageableDefault(50) Pageable pageable, Model model, HttpServletRequest servletRequest) throws UnsupportedEncodingException { Page<Article> articles = articleService.getArticles(form.toArticleSearchRequest(), pageable); model.addAttribute("articles", articles); model.addAttribute("pageable", pageable); model.addAttribute("pagination", new Pagination<>(articles, 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")); }/*w ww . j a v a 2 s. c o m*/ return "article/index"; }
From source file:org.home.petclinic2.controller.OwnerController.java
/** * Retrieves all owners or allows for last name search * //from ww w .j a v a2 s.co m * @param owner * @param result * @param model * @return */ // be careful where you place the BindingResult, there are some rules about // where it must fall in the method signature. Typically, I place all of the // validated beans at the beginning and then follow each bean being // validated with the binding result @RequestMapping(value = "/owner", method = RequestMethod.GET) public String processFindForm(Owner owner, BindingResult result, Model model) { // allow parameterless GET request for /owner to return all records Collection<Owner> results = null; if (StringUtils.isEmpty(owner.getLastName())) { // find all owners results = clinicService.findAllOwners(); } else { // find owners by last name results = clinicService.findOwnerByLastName(owner.getLastName()); } // ensure that we received results, otherwise we have an issue on our // hands if (results == null) { throw new IllegalStateException("Results were null. This should not happen"); } else if (results.size() < 1) { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owner/findOwner"; } else if (results.size() > 1) { // multiple owners found // here we've specified how we want to reference the model object model.addAttribute("selections", results); return "owner/owners"; } else { // 1 owner found owner = results.iterator().next(); return "redirect:/owner/" + owner.getId(); } }
From source file:org.psikeds.resolutionengine.datalayer.vo.ValueObject.java
protected static String composeId(final ValueObject... vos) { final StringBuilder sb = new StringBuilder(); if (vos != null) { for (final ValueObject v : vos) { final String vid = (v == null ? null : v.getId()); if (!StringUtils.isEmpty(vid)) { if (sb.length() > 0) { sb.append(COMPOSE_ID_SEPARATOR); }/* w w w .j a va2 s . c om*/ sb.append(vid.trim()); } } } return sb.toString(); }
From source file:com.sastix.cms.server.services.cache.hazelcast.HazelcastCacheService.java
@Override public void cacheResource(CacheDTO cacheDTO) throws DataNotFound, CacheValidationException, IOException { LOG.info("HazelcastCacheService->cacheResource"); nullValidationChecker(cacheDTO, CacheDTO.class); String cacheKey = cacheDTO.getCacheKey(); String cacheRegion = cacheDTO.getCacheRegion(); byte[] blob;// w ww . j a va 2 s . c om String blobURI = cacheDTO.getCacheBlobURI(); if (!StringUtils.isEmpty(blobURI) && !StringUtils.isEmpty(cacheDTO.getCacheBlobBinary())) { throw new CacheValidationException( "Client should NOT be able to send both blob AND URI. Only one of them"); } if (blobURI != null) { blob = cacheFileUtilsService.downloadResource(new URL(blobURI)); cacheDTO.setCacheBlobBinary(blob); } if (cacheDTO.getCacheKey() == null) { throw new CacheValidationException("You cannot cache a resource with a null key"); } // Put value into cache. if (!StringUtils.isEmpty(cacheRegion)) { cm.getCache(cacheRegion).put(cacheKey, cacheDTO); } else { this.cache.put(cacheKey, cacheDTO); } }
From source file:dk.dma.ais.downloader.QueryService.java
/** * Initializes the repository//from w w w .ja v a 2s .co m */ @PostConstruct public void init() throws Exception { log.info("******** Using AIS View URL: " + aisViewUrl); // Create the repo root directory if (StringUtils.isEmpty(repoRootPath)) { repoRoot = Paths.get(System.getProperty("user.home")).resolve(".aisdownloader"); } else { repoRoot = Paths.get(repoRootPath); } log.info("******** Using repo root " + repoRoot); if (!Files.exists(getRepoRoot())) { try { Files.createDirectories(getRepoRoot()); } catch (IOException e) { log.log(Level.SEVERE, "Error creating repository dir " + getRepoRoot(), e); } } if (!StringUtils.isEmpty(authHeader)) { log.info("******** Using auth header: " + authHeader); } // Initialize process pool processPool = Executors.newFixedThreadPool(EXECUTOR_POOL_SIZE); log.info("Initialized the QueryService"); }