List of usage examples for org.springframework.util StringUtils isEmpty
public static boolean isEmpty(@Nullable Object str)
From source file:cn.guoyukun.spring.jpa.plugin.serivce.BaseTreeableService.java
/** * /*from w ww . ja v a 2 s.co m*/ * * @param parentIds * @return */ public List<M> findAncestor(String parentIds) { if (StringUtils.isEmpty(parentIds)) { return Collections.EMPTY_LIST; } String[] ids = StringUtils.tokenizeToStringArray(parentIds, "/"); return Lists.reverse( findAllWithNoPageNoSort(Searchable.newSearchable().addSearchFilter("id", SearchOperator.in, ids))); }
From source file:com.chexiang.idb.controller.DatabaseSlowSelController.java
public int getTime(Object time) { if (StringUtils.isEmpty(time)) { return 0; }// w ww . j a v a 2 s. c o m String[] times = time.toString().split(":"); int intTime = 0; int hours = Integer.parseInt(times[0]); intTime += (hours * 3600); int minute = Integer.parseInt(times[1]); intTime += (minute * 60); int second = Integer.parseInt(times[2]); intTime += second; return intTime; }
From source file:org.psikeds.knowledgebase.xml.impl.XMLParser.java
private long parseXmlElements(final Reader xml) throws XMLStreamException, JAXBException { if (this.callbackHandler != null) { if (this.elementClass != null) { return parseXmlElements(xml, this.elementClass, this.callbackHandler, this.eventFilter, this.numOfSkippedElements); }/* ww w .jav a 2s . c o m*/ if (!StringUtils.isEmpty(this.packageName)) { return parseXmlElements(xml, this.packageName, this.callbackHandler, this.eventFilter, this.numOfSkippedElements); } } throw new IllegalArgumentException( "Unsupported configuration settings! Must specify a Callback-Handler and either a Package-Name or an Element-Class."); }
From source file:com.formkiq.core.form.service.FormValidatorServiceImpl.java
/** * Validate Form JSON Field./*w w w . j a va 2 s .c o m*/ * * @param archive {@link ArchiveDTO} * @param form {@link FormJSON} * @param field {@link FormJSONField} * @param errors {@link Map} * @param types {@link FormJSONRequiredType} */ private void validateFormJSONField(final ArchiveDTO archive, final FormJSON form, final FormJSONField field, final Map<String, String> errors, final FormJSONRequiredType... types) { if (!field.isHide() && !BUTTON.equals(field.getType())) { boolean isRequired = isRequired(field, types); String value = Objects.toString(field.getValue(), ""); List<String> values = field.getValues(); if (!hasText(value) && !isEmpty(values)) { value = values.stream().collect(Collectors.joining()); } if (isRequired) { if (StringUtils.isEmpty(value)) { errors.put(String.valueOf(field.getId()), "Field required"); } } validateFieldCustomFormatter(form, field, value, errors); validateFieldFormula(form, field, errors); if (isRequired || hasText(value)) { validateFieldVariable(archive, form, field, value, errors); } } }
From source file:uk.ac.ebi.ep.controller.BrowseTaxonomyController.java
@RequestMapping(value = FILTER_BY_FACETS, method = RequestMethod.GET) public String filterByFacets(@ModelAttribute("searchModel") SearchModel searchModel, @RequestParam(value = "taxId", required = true) Long taxId, @RequestParam(value = "organismName", required = false) String organismName, Model model, HttpServletRequest request, HttpSession session, RedirectAttributes attributes) { List<Species> species = enzymePortalService.findSpeciesByTaxId(taxId); List<Compound> compouds = enzymePortalService.findCompoundsByTaxId(taxId); List<Disease> diseases = enzymePortalService.findDiseasesByTaxId(taxId); List<EcNumber> enzymeFamilies = enzymePortalService.findEnzymeFamiliesByTaxId(taxId); SearchFilters filters = new SearchFilters(); filters.setSpecies(species);/*from w w w. j ava2 s .c om*/ filters.setCompounds(compouds); filters.setDiseases(diseases); filters.setEcNumbers(enzymeFamilies); SearchParams searchParams = searchModel.getSearchparams(); searchParams.setText(organismName); searchParams.setSize(SEARCH_PAGESIZE); searchModel.setSearchparams(searchParams); SearchResults searchResults = new SearchResults(); searchResults.setSearchfilters(filters); searchModel.setSearchresults(searchResults); SearchParams searchParameters = searchModel.getSearchparams(); String compound_autocompleteFilter = request.getParameter("searchparams.compounds"); String specie_autocompleteFilter = request.getParameter("_ctempList_selected"); String diseases_autocompleteFilter = request.getParameter("_DtempList_selected"); // Filter: List<String> specieFilter = searchParameters.getSpecies(); List<String> compoundFilter = searchParameters.getCompounds(); List<String> diseaseFilter = searchParameters.getDiseases(); List<Integer> ecFilter = searchParameters.getEcFamilies(); //remove empty string in the filter to avoid unsual behavior of the filter facets if (specieFilter.contains("")) { specieFilter.remove(""); } if (compoundFilter.contains("")) { compoundFilter.remove(""); } if (diseaseFilter.contains("")) { diseaseFilter.remove(""); } //to ensure that the seleted item is used in species filter, add the selected to the list. this is a workaround. different JS were used for auto complete and normal filter if ((specie_autocompleteFilter != null && StringUtils.hasLength(specie_autocompleteFilter) == true) && StringUtils.isEmpty(compound_autocompleteFilter) && StringUtils.isEmpty(diseases_autocompleteFilter)) { specieFilter.add(specie_autocompleteFilter); } if ((diseases_autocompleteFilter != null && StringUtils.hasLength(diseases_autocompleteFilter) == true) && StringUtils.isEmpty(compound_autocompleteFilter) && StringUtils.isEmpty(specie_autocompleteFilter)) { diseaseFilter.add(diseases_autocompleteFilter); } //both from auto complete and normal selection. selected items are displayed on top the list and returns back to the orignial list when not selected. //SearchResults searchResults = resultSet; List<Species> defaultSpeciesList = searchResults.getSearchfilters().getSpecies(); resetSelectedSpecies(defaultSpeciesList); searchParameters.getSpecies().stream().forEach((selectedItems) -> { defaultSpeciesList.stream() .filter((theSpecies) -> (selectedItems.equals(theSpecies.getScientificname()))) .forEach((theSpecies) -> { theSpecies.setSelected(true); }); }); List<Compound> defaultCompoundList = searchResults.getSearchfilters().getCompounds(); resetSelectedCompounds(defaultCompoundList); searchParameters.getCompounds().stream().forEach((SelectedCompounds) -> { defaultCompoundList.stream().filter((theCompound) -> (SelectedCompounds.equals(theCompound.getName()))) .forEach((theCompound) -> { theCompound.setSelected(true); }); }); List<Disease> defaultDiseaseList = searchResults.getSearchfilters().getDiseases(); resetSelectedDisease(defaultDiseaseList); searchParameters.getDiseases().stream().forEach((selectedDisease) -> { defaultDiseaseList.stream().filter((disease) -> (selectedDisease.equals(disease.getName()))) .forEach((disease) -> { disease.setSelected(true); }); }); List<EcNumber> defaultEcNumberList = searchResults.getSearchfilters().getEcNumbers(); resetSelectedEcNumber(defaultEcNumberList); searchParameters.getEcFamilies().stream().forEach((selectedEcFamily) -> { defaultEcNumberList.stream().filter((ec) -> (selectedEcFamily.equals(ec.getEc()))).forEach((ec) -> { ec.setSelected(true); }); }); Pageable pageable = new PageRequest(0, SEARCH_PAGESIZE, Sort.Direction.ASC, "function", "entryType"); Page<UniprotEntry> page = new PageImpl<>(new ArrayList<>(), pageable, 0); //specie only if (specieFilter.isEmpty() && compoundFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecie(taxId, pageable); } //specie only if (!specieFilter.isEmpty() && compoundFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecie(taxId, pageable); } // compounds only if (!compoundFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompounds(taxId, compoundFilter, pageable); } // disease only if (compoundFilter.isEmpty() && !diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndDiseases(taxId, diseaseFilter, pageable); } //ec only if (compoundFilter.isEmpty() && diseaseFilter.isEmpty() && !ecFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndEc(taxId, ecFilter, pageable); } //compound and diseases if (!compoundFilter.isEmpty() && !diseaseFilter.isEmpty() && ecFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompoundsAndDiseases(taxId, compoundFilter, diseaseFilter, pageable); } //compound and ec if (!compoundFilter.isEmpty() && !ecFilter.isEmpty() && diseaseFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompoundsAndEc(taxId, compoundFilter, ecFilter, pageable); } //disease and ec if (!ecFilter.isEmpty() && !diseaseFilter.isEmpty() && compoundFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndDiseasesAndEc(taxId, diseaseFilter, ecFilter, pageable); } //disease and compounds and ec if (!ecFilter.isEmpty() && !diseaseFilter.isEmpty() && !compoundFilter.isEmpty()) { page = enzymePortalService.filterBySpecieAndCompoundsAndDiseasesAndEc(taxId, compoundFilter, diseaseFilter, ecFilter, pageable); } model.addAttribute("searchFilter", filters); List<UniprotEntry> result = page.getContent(); int current = page.getNumber() + 1; int begin = Math.max(1, current - 5); int end = Math.min(begin + 10, page.getTotalPages()); model.addAttribute("page", page); model.addAttribute("beginIndex", begin); model.addAttribute("endIndex", end); model.addAttribute("currentIndex", current); model.addAttribute("organismName", organismName); model.addAttribute("taxId", taxId); model.addAttribute("summaryEntries", result); searchResults.setTotalfound(page.getTotalElements()); searchResults.setSearchfilters(filters); searchResults.setSummaryentries(result); searchModel.setSearchresults(searchResults); model.addAttribute("searchModel", searchModel); model.addAttribute("searchConfig", searchConfig); String searchKey = getSearchKey(searchModel.getSearchparams()); cacheSearch(session.getServletContext(), searchKey, searchResults); setLastSummaries(session, searchResults.getSummaryentries()); clearHistory(session); addToHistory(session, searchModel.getSearchparams().getType(), searchKey); return RESULT; }
From source file:org.kmnet.com.fw.common.exception.ExceptionLogger.java
/** * Formats the message for log output.// w w w .j a v a 2 s . c o m * <p> * Formats exception code and exception message and creates message for log output. <br> * </p> * [Default format of message for log output]<br> * <ul> * <li>If exception code is resolved: "[${exceptionCode}] ${exceptionMessage}" format</li> * <li>If exception code is not resolved: "${exceptionMessage}" format</li> * </ul> * @param exceptionCode exception code * @param exceptionMessage exception message * @return message ready for log output */ protected String formatLogMessage(String exceptionCode, String exceptionMessage) { String bindingExceptionCode = exceptionCode; String bindingExceptionMessage = exceptionMessage; if (StringUtils.isEmpty(bindingExceptionCode)) { bindingExceptionCode = defaultCode; } if (StringUtils.isEmpty(bindingExceptionMessage)) { bindingExceptionMessage = defaultMessage; } String message = MessageFormat.format(logMessageFormat, bindingExceptionCode, bindingExceptionMessage); if (trimLogMessage) { message = message.trim(); } return message; }
From source file:com.ocs.dynamo.ui.container.hierarchical.ModelBasedHierarchicalContainer.java
protected AttributeModel findRelatedAttributeModel(MessageService messageService, EntityModel<?> entityModel, Class<?> entityClassOther, AttributeType attributeType, String messageKey) { AttributeModel related = null;//w ww . ja va 2 s . c o m String msg = messageService.getEntityMessage(entityModel.getReference(), messageKey); if (!StringUtils.isEmpty(msg) && entityModel.getAttributeModel(msg) != null) { related = entityModel.getAttributeModel(msg); } else { List<AttributeModel> ms = entityModel.getAttributeModelsForType(attributeType, entityClassOther); if (!ms.isEmpty()) { related = ms.get(0); } } return related; }
From source file:com.hemou.android.account.AccountUtils.java
/** * Is the given {@link Exception} due to a 401 Unauthorized API response? * //from w w w. j a v a2 s .c om * @param e * @return true if 401, false otherwise */ public static boolean isUnauthorized(final Exception e) { Log.e(TAG, "Exception occured[" + Thread.currentThread().getId() + "]:{type:" + e.getClass().getName() + "," + e.getLocalizedMessage() + "}"); String errorMess = e.getMessage(); if (!StringUtils.isEmpty(errorMess) && (errorMess.contains("The authorization has expired") || errorMess.contains("401 Unauthorized") || errorMess.contains("403 Forbidden"))) return true; if (e instanceof NotAuthorizedException) { Log.e(TAG, "?..."); return true; } // if (e instanceof ResourceAccessException) // return true; if (e instanceof HttpClientErrorException) { HttpClientErrorException expt = (HttpClientErrorException) e; HttpStatus status = expt.getStatusCode(); if (Arrays.asList(HttpStatus.UNAUTHORIZED, HttpStatus.NETWORK_AUTHENTICATION_REQUIRED, HttpStatus.NON_AUTHORITATIVE_INFORMATION, HttpStatus.PROXY_AUTHENTICATION_REQUIRED, //403?????? HttpStatus.FORBIDDEN).contains(status)) return true; } return false; }
From source file:com.depas.utils.FileUtils.java
public static boolean createDirectory(String path) { if (StringUtils.isEmpty(path)) { return false; }/*from w ww .java 2 s . c o m*/ File dir = new File(path); if (!dir.exists()) { return dir.mkdir(); } else { return true; } }
From source file:com.viewer.controller.ViewerController.java
@RequestMapping(value = "/LoadFileBrowserTreeData", method = RequestMethod.POST, headers = { "Content-type=application/json" }) @ResponseBody/*from ww w. ja va 2s . c o m*/ public FileBrowserTreeDataResponse loadFileBrowserTreeData( @RequestBody LoadFileBrowserTreeDataParameters parameters, HttpServletRequest request) throws Exception { String path = _storagePath; try { if (!StringUtils.isEmpty(parameters.getPath())) path = path + parameters.getPath(); FileTreeOptions options = new FileTreeOptions(path); FileTreeContainer tree = _htmlHandler.loadFileTree(options); FileBrowserTreeDataResponse result = new FileBrowserTreeDataResponse(); result.setNodes(Utils.ToFileTreeNodes(parameters.getPath(), tree.getFileTree())); List<FileDescription> mytree = tree.getFileTree(); result.setCount(mytree.size()); return result; } catch (Exception e) { e.printStackTrace(); } FileBrowserTreeDataResponse result = new FileBrowserTreeDataResponse(); return result; }