Example usage for org.springframework.util CollectionUtils isEmpty

List of usage examples for org.springframework.util CollectionUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util CollectionUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Map<?, ?> map) 

Source Link

Document

Return true if the supplied Map is null or empty.

Usage

From source file:com.deloitte.smt.service.SignalDetectionService.java

public SignalDetection createOrUpdateSignalDetection(SignalDetection signalDetection)
        throws ApplicationException {
    try {//  w ww .ja va2s .c o m
        if (signalDetection.getId() == null) {
            Long signalDetectionExist = signalDetectionRepository
                    .countByNameIgnoreCase(signalDetection.getName());
            if (signalDetectionExist > 0) {
                throw exceptionBuilder.buildException(ErrorType.DETECTION_NAME_DUPLICATE, null);
            }
        }

        Calendar c = Calendar.getInstance();
        if (signalDetection.getId() == null) {
            signalDetection.setCreatedDate(c.getTime());
            signalDetection.setLastModifiedDate(c.getTime());
        } else {
            signalDetection.setLastModifiedDate(c.getTime());
        }
        signalDetection.setNextRunDate(
                SignalUtil.getNextRunDate(signalDetection.getRunFrequency(), signalDetection.getCreatedDate()));
        SignalDetection clone = signalDetection;
        clone = signalDetectionRepository.save(clone);
        List<TopicSignalDetectionAssignmentAssignees> detectionAssigneesList = clone
                .getTopicSignalDetectionAssignmentAssignees();
        if (!CollectionUtils.isEmpty(detectionAssigneesList)) {
            for (TopicSignalDetectionAssignmentAssignees assignee : detectionAssigneesList) {
                assignee.setDetectionId(clone.getId());
            }
        }
        signalDetection.setId(clone.getId());
        List<Ingredient> ingredients = signalDetection.getIngredients();
        if (!CollectionUtils.isEmpty(ingredients)) {
            for (Ingredient ingredient : ingredients) {
                ingredient.setDetectionId(signalDetection.getId());
            }
            ingredients = ingredientRepository.save(ingredients);

            saveProduct(signalDetection, ingredients);
            saveLicense(signalDetection, ingredients);
        }
        saveSoc(signalDetection);
        saveSmq(signalDetection);
        saveIncludeAE(signalDetection);
        saveDenominatorForPoisson(signalDetection);
        saveQueryBuilder(signalDetection);
        return signalDetection;
    } catch (ApplicationException ex) {
        throw new ApplicationException("Problem Creating Signal Detection", ex);
    }
}

From source file:nl.surfnet.coin.api.service.MockServiceImpl.java

private GroupMembersEntry getPreparedGroupMembers(String groupId) {
    GroupMembersEntry entry = new GroupMembersEntry();
    List<String> memberKeys = MEMBERSHIPS_IN_MEMORY.get(groupId);
    List<Person> members = new ArrayList<Person>();
    if (!CollectionUtils.isEmpty(memberKeys)) {
        for (String id : memberKeys) {
            members.add(PERSONS_IN_MEMORY.get(id));
        }/*from   w  w  w.  j a v  a 2 s.  c o  m*/
    }
    entry.setEntry(members);
    entry.setTotalResults(members.size());
    return entry;
}

From source file:com.sinet.gage.delta.DomainUpdatesImporter.java

/**
 * Performs the delta updates for Domains
 * /*from w w w  .j a  va2s  .  c om*/
 * @param domainIdsToProcessUpdates
 */
public void processUpdatesForDomains(Set<Integer> domainIdsToProcessUpdates) {
    Set<Integer> domainIdsForUpdate;
    List<DomainResponse> domainResponseList;
    List<Domain> domainList = new ArrayList<>();

    for (Integer domainId : domainIdsToProcessUpdates) {

        domainIdsForUpdate = signalManager.getDomainIdsForDeltaImportsForADomain(domainId,
                serverSettings.getEntityChangedSignalTypeCode());

        if (!CollectionUtils.isEmpty(domainIdsForUpdate)) {
            log.debug("Domain Ids to be updated: " + domainIdsForUpdate);
            String idsString = domainIdsForUpdate.stream().map(Object::toString)
                    .collect(Collectors.joining(", "));
            domainResponseList = getDomainsWithData(domainId, idsString);

            for (DomainResponse domainResponse : domainResponseList) {

                DomainResponse parentDomainResponse = dlapDomainClient.getDomain(null,
                        Long.parseLong(domainId.toString()));

                Domain domain = mapToDomain(domainResponse);
                if (domainResponse.getData() != null && domainResponse.getData().getCustomization() != null
                        && domainResponse.getData().getCustomization().getEdivatelearn() != null) {
                    if ("DISTRICT".equalsIgnoreCase(
                            domainResponse.getData().getCustomization().getEdivatelearn().getDomaintype())) {
                        domain.setStateDomainId(Long.parseLong(parentDomainResponse.getId()));
                        domain.setStateDomainName(parentDomainResponse.getName());
                        domain.setParentDomainName(parentDomainResponse.getName());
                    } else if ("SCHOOL".equalsIgnoreCase(
                            domainResponse.getData().getCustomization().getEdivatelearn().getDomaintype())) {
                        DomainResponse stateDomainResponse = dlapDomainClient.getDomain(null,
                                Long.parseLong(parentDomainResponse.getParentid()));
                        domain.setStateDomainId(Long.parseLong(stateDomainResponse.getId()));
                        domain.setStateDomainName(stateDomainResponse.getName());
                        domain.setParentDomainName(parentDomainResponse.getName());
                    }
                } else {
                    domain.setStateDomainId(Long.parseLong(parentDomainResponse.getId()));
                    domain.setStateDomainName(parentDomainResponse.getName());
                    domain.setParentDomainName(parentDomainResponse.getName());
                }
                domainList.add(domain);
            }
            log.debug("Updating domain ids: " + domainId);
            if (!CollectionUtils.isEmpty(domainList)) {
                domainsRepository.updateDomains(domainList);
            }
        }
    }
}

From source file:com.zuoxiaolong.blog.cache.service.UserArticleServiceManager.java

/**
 * ???/* ww  w .j a  v  a2s  .c om*/
 *
 * @return
 */
@Cacheable(value = GuavaCacheConfig.BLOG_CACHE, key = "#root.methodName")
public List<ArticleRankResponseDto> getArticlesRank() {
    List<ArticleCategory> articleCategories = articleCategoryServiceManager.getAllArticleCategory();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();

    List<ArticleRankResponseDto> articleRankResponseDtos = Lists.newArrayList();

    //??
    ArticleRankResponseDto recommentArticleRankResponseDto = new ArticleRankResponseDto();
    recommentArticleRankResponseDto.setActionType(CacheConstants.ACTION_TYPE_RECOMMEND);

    Map<String, Object> recommendMap = Maps.newHashMap();
    List<UserArticle> recommendUserArticles;
    List<ArticleRankResponseDataResult> recommendArticleRankResponseDataResultList = Lists.newArrayList();
    ArticleRankResponseDataResult recommendDataResult;
    for (ArticleCategory articleCategory : articleCategories) {
        recommendMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        recommendMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        recommendUserArticles = this.getTopRecommendArticlesByCategoryIdAndTime(recommendMap);
        if (!CollectionUtils.isEmpty(recommendUserArticles)) {
            recommendDataResult = new ArticleRankResponseDataResult();
            recommendDataResult.setCategoryInfo(articleCategory);
            recommendDataResult.setArticleInfo(recommendUserArticles.get(TOP_NUM - 1));
            recommendArticleRankResponseDataResultList.add(recommendDataResult);
        }
    }
    recommentArticleRankResponseDto.setDataResult(recommendArticleRankResponseDataResultList);
    articleRankResponseDtos.add(recommentArticleRankResponseDto);

    //
    ArticleRankResponseDto readArticleRankResponseDto = new ArticleRankResponseDto();
    readArticleRankResponseDto.setActionType(CacheConstants.ACTION_TYPE_READ);

    Map<String, Object> readMap = Maps.newHashMap();
    List<UserArticle> readUserArticles;
    ArticleRankResponseDataResult readDataResult;
    List<ArticleRankResponseDataResult> readArticleRankResponseDataResultList = Lists.newArrayList();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();
    for (ArticleCategory articleCategory : articleCategories) {
        readMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        readMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        readUserArticles = this.getTopReadArticlesByCategoryIdAndTime(readMap);
        if (!CollectionUtils.isEmpty(readUserArticles)) {
            readDataResult = new ArticleRankResponseDataResult();
            readDataResult.setCategoryInfo(articleCategory);
            readDataResult.setArticleInfo(readUserArticles.get(TOP_NUM - 1));
            readArticleRankResponseDataResultList.add(readDataResult);
        }
    }
    readArticleRankResponseDto.setDataResult(readArticleRankResponseDataResultList);
    articleRankResponseDtos.add(readArticleRankResponseDto);

    //
    ArticleRankResponseDto commendArticleRankResponseDto = new ArticleRankResponseDto();
    commendArticleRankResponseDto.setActionType(CacheConstants.ACTION_TYPE_COMMEND);

    Map<String, Object> commendMap = Maps.newHashMap();
    List<UserArticle> commendUserArticles;
    ArticleRankResponseDataResult commendDataResult;
    List<ArticleRankResponseDataResult> commendArticleRankResponseDataResultList = Lists.newArrayList();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();
    for (ArticleCategory articleCategory : articleCategories) {
        commendMap.put(QUERY_PARAMETER_CATEGORY_ID, articleCategory.getId());
        commendMap.put(QUERY_PARAMETER_TIME,
                Timestamp.valueOf(LocalDateTime.now().minus(DEFAULT_DAYS_BEFORE, ChronoUnit.DAYS)));
        commendUserArticles = this.getTopCommendArticles(commendMap);
        if (!CollectionUtils.isEmpty(commendUserArticles)) {
            commendDataResult = new ArticleRankResponseDataResult();
            commendDataResult.setCategoryInfo(articleCategory);
            commendDataResult.setArticleInfo(commendUserArticles.get(TOP_NUM - 1));
            commendArticleRankResponseDataResultList.add(commendDataResult);
        }
    }
    commendArticleRankResponseDto.setDataResult(commendArticleRankResponseDataResultList);
    articleRankResponseDtos.add(commendArticleRankResponseDto);

    return articleRankResponseDtos;
}

From source file:pe.gob.mef.gescon.web.ui.ParametroMB.java

public void save(ActionEvent event) {
    try {/*from   w  w  w  .  ja va 2  s. com*/
        if (CollectionUtils.isEmpty(this.getListaParametro())) {
            this.setListaParametro(Collections.EMPTY_LIST);
        }
        Parametro parametro = new Parametro();
        parametro.setVnombre(this.getNombre());
        parametro.setVvalor(this.getValor());
        parametro.setVdescripcion(this.getDescripcion());
        if (!errorValidation(parametro)) {
            LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
            User user = loginMB.getUser();
            ParametroService service = (ParametroService) ServiceFinder.findBean("ParametroService");
            parametro.setNparametroid(service.getNextPK());
            parametro.setVnombre(StringUtils.upperCase(this.getNombre().trim()));
            parametro.setVvalor(this.getValor());
            parametro.setVdescripcion(StringUtils.capitalize(this.getDescripcion().trim()));
            parametro.setNactivo(BigDecimal.ONE);
            parametro.setDfechacreacion(new Date());
            parametro.setVusuariocreacion(user.getVlogin());
            service.saveOrUpdate(parametro);
            this.setListaParametro(service.getParametros());
            this.cleanAttributes();
            RequestContext.getCurrentInstance().execute("PF('newDialog').hide();");
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:com.frank.search.solr.repository.query.SolrQueryMethod.java

/**
 * @return true if {@link Facet#queries()} is not empty
 *//*from w w  w.j  a va 2  s.  c  o  m*/
public boolean hasFacetQueries() {
    if (hasFacetAnnotation()) {
        return !CollectionUtils.isEmpty(getFacetQueries());
    }
    return false;
}

From source file:fr.mby.saml2.sp.opensaml.query.engine.AuthnResponseQueryProcessor.java

@Override
protected void process() throws SamlProcessingException, SamlSecurityException, UnsupportedSamlOperation {
    final Response authnResponse = this.getOpenSamlObject();
    this.authentications = this.extractSamlAuthentications(authnResponse);

    if (CollectionUtils.isEmpty(this.authentications)) {
        throw new SamlProcessingException("No Authentication statement found in AuthnResponse !");
    }/*from w w  w  .  ja  v a 2  s . c o  m*/
}

From source file:pe.gob.mef.gescon.web.ui.RangoMB.java

public void setSelectedRow(ActionEvent event) {
    try {// w w  w. java2  s . c  o m
        if (event != null) {
            int index = Integer.parseInt((String) JSFUtils.getRequestParameter("index"));
            if (!CollectionUtils.isEmpty(this.getFilteredListaRango())) {
                this.setSelectedRango(this.getFilteredListaRango().get(index));
            } else {
                this.setSelectedRango(this.getListaRango().get(index));
            }
            this.setFilteredListaRango(new ArrayList());
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.scub.foundation.framework.core.oval.validator.OvalIntegrityValidatorImpl.java

/**
 * Get the report for the given dto./*from  w w  w . ja  v  a 2s  . co  m*/
 * @param object the dto to validate
 * @param profiles the profiles list
 * @param baseAttribute the base attribute.
 * @return the generated report.
 */
@Override
public ReportDto getReport(AbstractDto object, String[] profiles, String baseAttribute) {
    final ReportDto report = new ReportDto();
    if (StringUtils.isBlank(baseAttribute)) {
        assertObjectToValidateNotNull(object);
    } else {
        if (object == null) {
            String attribute = baseAttribute + "";
            attribute = attribute.replace("[[", "");
            attribute = attribute.replace("]]", "");
            report.addError(attribute, getMessage(replaceFlag(baseAttribute, "*") + ".NotNull"));
        }
    }

    if (object != null) {
        final ValidationInformation validationInformations = validateInformationObject(object, profiles,
                baseAttribute);

        // create all subReport
        if (validationInformations != null) {
            if (!CollectionUtils.isEmpty(validationInformations.getViolations())) {
                for (ConstraintViolationInformation constraintViolationInformation : validationInformations
                        .getViolations()) {
                    report.addError(constraintViolationInformation.getAttributeName(),
                            constraintViolationInformation.getErrorMessage());
                }
            }
            report.setValidatedFields(validationInformations.getValidatedFields());
        }
    }
    return report;
}