List of usage examples for org.springframework.util StringUtils isEmpty
public static boolean isEmpty(@Nullable Object str)
From source file:com.capitalone.dashboard.collector.TeamDataClient.java
/** * Validates current entry and removes new entry if an older item exists in * the repo//from w ww . j a va2s . co m * * @param localId * local repository item ID (not the precise mongoID) */ protected Boolean removeExistingEntity(String localId) { if (StringUtils.isEmpty(localId)) return false; List<ScopeOwnerCollectorItem> teamIdList = teamRepo.getTeamIdById(localId); if (CollectionUtils.isEmpty(teamIdList)) return false; ScopeOwnerCollectorItem socItem = teamIdList.get(0); if (!localId.equalsIgnoreCase(socItem.getTeamId())) return false; this.setOldTeamId(socItem.getId()); this.setOldTeamEnabledState(socItem.isEnabled()); teamRepo.delete(socItem.getId()); return true; }
From source file:com.sastix.cms.server.services.content.impl.CommonResourceServiceImpl.java
public String updateLocalFile(final String uuri, final String tenantID, final byte[] binary, final String binaryURI) throws ContentValidationException, ResourceAccessError { //save resource in volume String relativePath;//from ww w . j a v a2 s. c o m try { if (binary != null && !StringUtils.isEmpty(binaryURI)) { throw new ContentValidationException( "Field errors: resourceBinary OR resourceExternalURI should be null"); } else if (binary != null && binary.length > 0) { relativePath = hashedDirectoryService.replaceFile(uuri, tenantID, binary); } else if (!StringUtils.isEmpty(binaryURI)) { relativePath = hashedDirectoryService.replaceFile(uuri, tenantID, binaryURI); } else { throw new ContentValidationException( "Field errors: resourceBinary OR resourceExternalURI may not be null"); } } catch (Exception e) { if (e instanceof ContentValidationException) { throw (ContentValidationException) e; } throw new ResourceAccessError(e.toString()); } return relativePath; }
From source file:com.ge.predix.web.cors.CORSFilter.java
private boolean isCrossOriginRequest(final HttpServletRequest request) { if (StringUtils.isEmpty(request.getHeader(HttpHeaders.ORIGIN))) { return false; }/*w ww.j a v a 2s. c o m*/ return true; }
From source file:com.scf.core.EnvTest.java
private static Date[] getDeliveryMidHour() { String deliveryMidHour = "23:00:00,24:00:00"; //?/* ww w. j av a2 s. c o m*/ if (StringUtils.isEmpty(deliveryMidHour)) { throw new AppException(ExCode.SYS_002); } String[] deliveryMidHourArr = deliveryMidHour.split(","); if (deliveryMidHourArr == null || deliveryMidHourArr.length != 2) { throw new AppException(ExCode.SYS_002); } Date[] dateArr = new Date[2]; for (int i = 0; i < deliveryMidHourArr.length; i++) { try { dateArr[i] = DatetimeUtilies.parse(DatetimeUtilies.TIME, deliveryMidHourArr[i]); } catch (ParseException e) { throw new AppException(ExCode.SYS_002); } } return dateArr; }
From source file:com.rbmhtechnology.apidocserver.service.RepositoryService.java
@PostConstruct void init() {/*from w w w . j a v a 2 s . c o m*/ ConstructDocumentationDownloadUrl cacheLoader = new ConstructDocumentationDownloadUrl(); SnapshotRemovalListener removalListener = new SnapshotRemovalListener(); // snapshots will expire 30 minutes after their last construction (same for all) snapshotDownloadUrlCache = CacheBuilder.newBuilder().maximumSize(1000) .expireAfterWrite(snapshotsCacheTimeoutSeconds, TimeUnit.SECONDS).removalListener(removalListener) .build(cacheLoader); latestVersionCache = CacheBuilder.newBuilder().maximumSize(1000) .expireAfterWrite(snapshotsCacheTimeoutSeconds, TimeUnit.SECONDS) .build(new MavenXmlVersionRefResolver(MavenVersionRef.LATEST)); releaseDownloadUrlCache = CacheBuilder.newBuilder().maximumSize(1000).build(cacheLoader); releaseVersionCache = CacheBuilder.newBuilder().maximumSize(1000) .build(new MavenXmlVersionRefResolver(RELEASE)); if (localJarStorage == null) { localJarStorage = Files.createTempDir(); } // http client CredentialsProvider credsProvider = new BasicCredentialsProvider(); if (!StringUtils.isEmpty(repositoryUser) && !StringUtils.isEmpty(repositoryPassword)) { credsProvider.setCredentials(new AuthScope(repositoryUrl.getHost(), repositoryUrl.getPort()), new UsernamePasswordCredentials(repositoryUser, repositoryPassword)); } httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); }
From source file:burstcoin.jminer.core.network.Network.java
public void checkLastWinner(long blockNumber) { // find winner of lastBlock on new round, if server available String server = !poolMining ? soloServer : walletServer != null ? walletServer : null; if (!StringUtils.isEmpty(server)) { NetworkRequestLastWinnerTask networkRequestLastWinnerTask = context .getBean(NetworkRequestLastWinnerTask.class); networkRequestLastWinnerTask.init(server, blockNumber, connectionTimeout, winnerRetriesOnAsync, winnerRetryIntervalInMs); networkPool.execute(networkRequestLastWinnerTask); }/*from w w w. jav a2 s .c om*/ }
From source file:cn.guoyukun.spring.jpa.web.bind.method.annotation.PageableMethodArgumentResolver.java
private Sort getSort(String sortNamePrefix, Map<String, String[]> sortMap, Pageable defaultPageRequest, NativeWebRequest webRequest) {/*ww w .j av a 2 s .c o m*/ Sort sort = null; List<OrderedSort> orderedSortList = Lists.newArrayList(); for (String name : sortMap.keySet()) { //sort1.abc int propertyIndex = name.indexOf(".") + 1; int order = 0; String orderStr = name.substring(sortNamePrefix.length(), propertyIndex - 1); try { if (!StringUtils.isEmpty(orderStr)) { order = Integer.valueOf(orderStr); } } catch (Exception e) { } String property = name.substring(propertyIndex); assertSortProperty(property); Sort.Direction direction = Sort.Direction.fromString(sortMap.get(name)[0]); orderedSortList.add(new OrderedSort(property, direction, order)); } Collections.sort(orderedSortList); for (OrderedSort orderedSort : orderedSortList) { Sort newSort = new Sort(orderedSort.direction, orderedSort.property); if (sort == null) { sort = newSort; } else { sort = sort.and(newSort); } } if (sort == null) { return defaultPageRequest.getSort(); } return sort; }
From source file:io.github.howiefh.jeews.modules.oauth2.controller.AuthorizeController.java
private boolean login(Subject subject, HttpServletRequest request) { if ("get".equalsIgnoreCase(request.getMethod())) { return false; }/*from w w w .jav a 2 s . c o m*/ String username = request.getParameter("username"); String password = request.getParameter("password"); if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) { return false; } UsernamePasswordToken token = new UsernamePasswordToken(username, password); try { subject.login(token); return true; } catch (Exception e) { throw new RuntimeException("login error: " + e.getMessage()); } }
From source file:cz.muni.fi.mir.tools.SiteTitleInterceptor.java
private void resolveClassLevelSubTitle(SiteTitle siteTitle, SiteTitleContainer result) { if (!StringUtils.isEmpty(siteTitle.value())) { result.setSubTitle(siteTitle.value()); } else {//from ww w . j a v a 2s . c om result.setSubTitle(this.subTitle); } }
From source file:dk.dma.ais.downloader.QueryService.java
/** * Asynchronously loads the given file/*from w w w .j a v a 2 s . c om*/ * @param url the URL to load * @param path the path to save the file to */ private Future<Path> asyncLoadFile(final String url, final Path path) { Callable<Path> job = () -> { long t0 = System.currentTimeMillis(); // For the resulting file, drop the ".download" suffix String name = path.getFileName().toString(); name = name.substring(0, name.length() - DOWNLOAD_SUFFIX.length()); try { // Set up a few timeouts and fetch the attachment URLConnection con = new URL(url).openConnection(); con.setConnectTimeout(60 * 1000); // 1 minute con.setReadTimeout(60 * 60 * 1000); // 1 hour if (!StringUtils.isEmpty(authHeader)) { con.setRequestProperty("Authorization", authHeader); } try (ReadableByteChannel rbc = Channels.newChannel(con.getInputStream()); FileOutputStream fos = new FileOutputStream(path.toFile())) { fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } log.info(String.format("Copied %s -> %s in %d ms", url, path, System.currentTimeMillis() - t0)); } catch (Exception e) { log.log(Level.SEVERE, "Failed downloading " + url + ": " + e.getMessage()); // Delete the old file if (Files.exists(path)) { try { Files.delete(path); } catch (IOException e1) { log.finer("Failed deleting old file " + path); } } // Save an error file Path errorFile = path.getParent().resolve(name + ".err.txt"); try (PrintStream err = new PrintStream(new FileOutputStream(errorFile.toFile()))) { e.printStackTrace(err); } catch (IOException ex) { log.finer("Failed generating error file " + errorFile); } return errorFile; } Path resultPath = path.getParent().resolve(name); try { Files.move(path, resultPath); } catch (IOException e) { log.log(Level.SEVERE, "Failed renaming path " + path + ": " + e.getMessage()); } return resultPath; }; log.info("Submitting new job: " + url); return processPool.submit(job); }