List of usage examples for org.springframework.util CollectionUtils isEmpty
public static boolean isEmpty(@Nullable Map<?, ?> map)
From source file:org.openmhealth.shim.fitbit.FitbitShim.java
/** * Each 'dayResponse', when normalized, will have a type->list[objects] for the day. * So we collect each daily map to create an aggregate map of the full * time range.//from ww w .jav a 2s . c om */ @SuppressWarnings("unchecked") private ShimDataResponse aggregateNormalized(List<ShimDataResponse> dayResponses) { if (CollectionUtils.isEmpty(dayResponses)) { return ShimDataResponse.empty(FitbitShim.SHIM_KEY); } List<DataPoint> aggregateDataPoints = Lists.newArrayList(); for (ShimDataResponse dayResponse : dayResponses) { if (dayResponse.getBody() != null) { List<DataPoint> dayList = (List<DataPoint>) dayResponse.getBody(); for (DataPoint dataPoint : dayList) { aggregateDataPoints.add(dataPoint); } } } return ShimDataResponse.result(FitbitShim.SHIM_KEY, aggregateDataPoints); }
From source file:org.wallride.service.PageService.java
@CacheEvict(value = WallRideCacheConfiguration.PAGE_CACHE, allEntries = true) public Page createPage(PageCreateRequest request, Post.Status status, AuthorizedUser authorizedUser) { LocalDateTime now = LocalDateTime.now(); String code = request.getCode(); if (code == null) { try {//w w w. j a va2 s. c o m code = new CodeFormatter().parse(request.getTitle(), LocaleContextHolder.getLocale()); } catch (ParseException e) { throw new ServiceException(e); } } if (!StringUtils.hasText(code)) { if (!status.equals(Post.Status.DRAFT)) { throw new EmptyCodeException(); } } if (!status.equals(Post.Status.DRAFT)) { Post duplicate = postRepository.findOneByCodeAndLanguage(code, request.getLanguage()); if (duplicate != null) { throw new DuplicateCodeException(code); } } Page page = new Page(); if (!status.equals(Post.Status.DRAFT)) { page.setCode(code); page.setDraftedCode(null); } else { page.setCode(null); page.setDraftedCode(code); } Page parent = (request.getParentId() != null) ? pageRepository.findOneByIdAndLanguage(request.getParentId(), request.getLanguage()) : null; int rgt = 0; if (parent == null) { rgt = pageRepository.findMaxRgt(); rgt++; } else { rgt = parent.getRgt(); pageRepository.unshiftRgt(rgt); pageRepository.unshiftLft(rgt); } page.setParent(parent); Media cover = null; if (request.getCoverId() != null) { cover = entityManager.getReference(Media.class, request.getCoverId()); } page.setCover(cover); page.setTitle(request.getTitle()); page.setBody(request.getBody()); page.setAuthor(entityManager.getReference(User.class, authorizedUser.getId())); LocalDateTime date = request.getDate(); if (Post.Status.PUBLISHED.equals(status)) { if (date == null) { date = now; } else if (date.isAfter(now)) { status = Post.Status.SCHEDULED; } } page.setDate(date); page.setStatus(status); page.setLanguage(request.getLanguage()); page.getCategories().clear(); SortedSet<Category> categories = new TreeSet<>(); for (long categoryId : request.getCategoryIds()) { categories.add(entityManager.getReference(Category.class, categoryId)); } page.setCategories(categories); page.getTags().clear(); Set<String> tagNames = StringUtils.commaDelimitedListToSet(request.getTags()); if (!CollectionUtils.isEmpty(tagNames)) { for (String tagName : tagNames) { Tag tag = tagRepository.findOneForUpdateByNameAndLanguage(tagName, request.getLanguage()); if (tag == null) { tag = new Tag(); tag.setName(tagName); tag.setLanguage(request.getLanguage()); page.setCreatedAt(now); page.setCreatedBy(authorizedUser.toString()); page.setUpdatedAt(now); page.setUpdatedBy(authorizedUser.toString()); tag = tagRepository.saveAndFlush(tag); } page.getTags().add(tag); } } page.getRelatedPosts().clear(); Set<Post> relatedPosts = new HashSet<>(); for (long relatedId : request.getRelatedPostIds()) { relatedPosts.add(entityManager.getReference(Post.class, relatedId)); } page.setRelatedToPosts(relatedPosts); Seo seo = new Seo(); seo.setTitle(request.getSeoTitle()); seo.setDescription(request.getSeoDescription()); seo.setKeywords(request.getSeoKeywords()); page.setSeo(seo); page.setLft(rgt); page.setRgt(rgt + 1); List<Media> medias = new ArrayList<>(); if (StringUtils.hasText(request.getBody())) { // Blog blog = blogService.getBlogById(Blog.DEFAULT_ID); String mediaUrlPrefix = wallRideProperties.getMediaUrlPrefix(); Pattern mediaUrlPattern = Pattern.compile(String.format("%s([0-9a-zA-Z\\-]+)", mediaUrlPrefix)); Matcher mediaUrlMatcher = mediaUrlPattern.matcher(request.getBody()); while (mediaUrlMatcher.find()) { Media media = mediaRepository.findOneById(mediaUrlMatcher.group(1)); medias.add(media); } } page.setMedias(medias); page.setCreatedAt(now); page.setCreatedBy(authorizedUser.toString()); page.setUpdatedAt(now); page.setUpdatedBy(authorizedUser.toString()); page.getCustomFieldValues().clear(); if (!CollectionUtils.isEmpty(request.getCustomFieldValues())) { for (CustomFieldValueEditForm valueForm : request.getCustomFieldValues()) { CustomFieldValue value = new CustomFieldValue(); value.setCustomField(entityManager.getReference(CustomField.class, valueForm.getCustomFieldId())); value.setPost(page); if (valueForm.getFieldType().equals(CustomField.FieldType.CHECKBOX)) { if (!ArrayUtils.isEmpty(valueForm.getTextValues())) { value.setTextValue(String.join(",", valueForm.getTextValues())); } else { value.setTextValue(null); } } else { value.setTextValue(valueForm.getTextValue()); } value.setStringValue(valueForm.getStringValue()); value.setNumberValue(valueForm.getNumberValue()); value.setDateValue(valueForm.getDateValue()); value.setDatetimeValue(valueForm.getDatetimeValue()); if (!value.isEmpty()) { page.getCustomFieldValues().add(value); } } } return pageRepository.save(page); }
From source file:org.springmodules.cache.interceptor.caching.AbstractCachingInterceptor.java
private void validateModels() throws FatalCacheException { if (CollectionUtils.isEmpty(modelMap)) throw new FatalCacheException("The map of caching models should not be empty"); CacheModelValidator validator = cache.modelValidator(); String id = null;/*from w ww. ja v a 2 s .co m*/ try { for (Iterator i = modelMap.keySet().iterator(); i.hasNext();) { id = (String) i.next(); validator.validateCachingModel(modelMap.get(id)); } } catch (Exception exception) { throw new FatalCacheException("Unable to validate caching model with id " + StringUtils.quote(id), exception); } }
From source file:at.porscheinformatik.common.spring.web.extended.config.SpringWebExtendedConfigurerConfig.java
public void configureMessageSource(ReloadableResourceBundleMessageSource messageSource) { ApplicationConfiguration appConfig = appConfig(); MessageSourceConfig config = new DefaultMessageSourceConfig(); config.addBaseName("WEB-INF/messages/Messages"); config.setCacheSeconds(appConfig.isOptimizeResources() ? -1 : DEFAULT_REFRESH_INTERVALL); config.setDefaultEncoding("UTF-8"); configurer.configureMessageSource(config); messageSource.setCacheSeconds(config.getCacheSeconds() != null ? config.getCacheSeconds() : -1); if (!CollectionUtils.isEmpty(config.getBaseNames())) { messageSource.setBasenames(config.getBaseNames().toArray(new String[config.getBaseNames().size()])); }/*from ww w . j a v a 2 s . c o m*/ messageSource.setDefaultEncoding(config.getDefaultEncoding()); }
From source file:at.porscheinformatik.common.spring.web.extended.config.SpringWebExtendedConfig.java
@Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(new RequestResponseContextHandlerInterceptor()); List<LocaleSource> sources = configurerConfig.getLocaleSources(); if (!CollectionUtils.isEmpty(sources)) { LocaleHandlerInterceptor interceptor = new LocaleHandlerInterceptor(sources); interceptor.setAvailableLocales(configurerConfig.appConfig().getSupportedLocales()); registry.addInterceptor(interceptor); }//from w w w .j ava 2s . c o m }
From source file:pe.gob.mef.gescon.web.ui.PerfilMB.java
public void save(ActionEvent event) { try {//from w w w. ja v a 2s. co m if (CollectionUtils.isEmpty(this.getListaPerfils())) { this.setListaPerfils(Collections.EMPTY_LIST); } Perfil perfil = new Perfil(); perfil.setVnombre(this.getNombre()); perfil.setVdescripcion(this.getDescripcion()); if (!errorValidation(perfil)) { LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); PerfilService service = (PerfilService) ServiceFinder.findBean("PerfilService"); perfil.setNperfilid(service.getNextPK()); perfil.setVnombre(StringUtils.upperCase(this.getNombre().trim())); perfil.setVdescripcion(StringUtils.capitalize(this.getDescripcion().trim())); perfil.setNactivo(BigDecimal.ONE); perfil.setDfechacreacion(new Date()); perfil.setVusuariocreacion(user.getVlogin()); service.saveOrUpdate(perfil); this.setListaPerfils(service.getPerfils()); this.cleanAttributes(); RequestContext.getCurrentInstance().execute("PF('newDialog').hide();"); } } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } }
From source file:ru.anr.base.BaseParent.java
/** * Retrieves the first object of a collection. * /* ww w . j av a2 s . c om*/ * @param coll * An original collection * @return The found object or null is the collection is empty * * @param <S> * The type of elements */ public static <S> S first(Collection<S> coll) { return CollectionUtils.isEmpty(coll) ? null : coll.iterator().next(); }
From source file:com.mysoft.b2b.event.scheduler.job.EventJob.java
/** *?log//from www. java 2 s. c o m *@param event *@param appSubscribes app? */ private boolean parseLog(Event event, List<AppSubscribe> appSubscribes) { if (!CollectionUtils.isEmpty(appSubscribes)) { for (AppSubscribe sub : appSubscribes) { EventLog eventLog = new EventLog(); eventLog.setCreatedBy(event.getCreatedBy()); eventLog.setCreatedTime(new Date()); eventLog.setEventContent(event.getEventContent()); eventLog.setEventId(event.getEventId()); //eventLog.setRemark(event.getRemark()); //eventLogremark? eventLog.setStatus(EventLogStatus.DEFAULT.getValue()); eventLog.setTypeCode(event.getTypeCode()); eventLog.setAppId(sub.getAppId()); eventService.insertEventLog(eventLog); log.info("???LOG-->?log?ID" + event.getEventId() + " appid:" + sub.getAppId()); } return true; } else { log.info("???LOG-->:" + event.getTypeCode() + ",app???log"); } return false; }
From source file:com.iana.dver.dao.impl.DverDetailsDaoImpl.java
@Override public int countAllFailNotifs() throws DataAccessException { logger.info("Count All Failed Notifications ...."); List result = getHibernateTemplate().find(COUNT_FAIL_NOTIFICATIONS); return CollectionUtils.isEmpty(result) ? 0 : Integer.valueOf(result.get(0).toString()); }
From source file:org.agatom.springatom.cmp.wizards.data.result.WizardResult.java
public WizardResult setValidationMessages(final Set<Message> validationMessages) { if (CollectionUtils.isEmpty(validationMessages)) { return this; }//w ww .j a v a 2s . com if (this.validationMessages == null) { this.validationMessages = validationMessages; return this; } else { this.validationMessages.addAll(validationMessages); } return this; }