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.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java

@Test
public void restViewerJsonTest() throws IOException {
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON_UTF8);

    String qlQuery = "{viewer{ id }}";
    Map<String, Object> variables = new HashMap<>();
    variables.put("test-key", "key-0.9.0");
    ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.getForEntity(
            "http://localhost:" + port + "/graphql?query={0}&variables={1}", GraphQLServerResult.class, qlQuery,
            objectMapper.writeValueAsString(variables));

    GraphQLServerResult result = responseEntity.getBody();
    Assert.assertTrue(CollectionUtils.isEmpty(result.getErrors()));
    Assert.assertFalse(CollectionUtils.isEmpty(result.getData()));
    LOGGER.info(objectMapper.writeValueAsString(result.getData()));
}

From source file:com.zuoxiaolong.blog.service.impl.UserArticleServiceImpl.java

/**
 * ???/*from ww  w. jav a2s  . c  o m*/
 *
 * @return
 */
public List<ArticleRankResponseDto> getArticlesRank() {
    List<ArticleCategory> articleCategories = articleCategoryServiceManager.getAllArticleCategory();
    if (CollectionUtils.isEmpty(articleCategories))
        return Collections.emptyList();

    List<ArticleRankResponseDto> articleRankResponseDtos = new ArrayList<>();

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

    Map<String, Object> recommendMap = new HashMap<>();
    List<UserArticle> recommendUserArticles;
    List<ArticleRankResponseDataResult> recommendArticleRankResponseDataResultList = new ArrayList<>();
    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(ACTION_TYPE_READ);

    Map<String, Object> readMap = new HashMap<>();
    List<UserArticle> readUserArticles;
    ArticleRankResponseDataResult readDataResult;
    List<ArticleRankResponseDataResult> readArticleRankResponseDataResultList = new ArrayList<>();
    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(ACTION_TYPE_COMMENT);

    Map<String, Object> commendMap = new HashMap<>();
    List<UserArticle> commendUserArticles;
    ArticleRankResponseDataResult commendDataResult;
    List<ArticleRankResponseDataResult> commendArticleRankResponseDataResultList = new ArrayList<>();
    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.PerfilMB.java

public void setSelectedRow(ActionEvent event) {
    try {//from   w  ww. j  av  a2  s  . c  o m
        if (event != null) {
            int index = Integer.parseInt((String) JSFUtils.getRequestParameter("index"));
            if (!CollectionUtils.isEmpty(this.getFilteredListaPerfils())) {
                this.setSelectedPerfil(this.getFilteredListaPerfils().get(index));
            } else {
                this.setSelectedPerfil(this.getListaPerfils().get(index));
            }
            this.setFilteredListaPerfils(new ArrayList());
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.geosdi.geoplatform.experimental.dropwizard.auth.model.GPAuthenticatedPrincipal.java

@JsonIgnore
public boolean isGroupAware() {
    return !CollectionUtils.isEmpty(groups);
}

From source file:com.microsoft.exchange.impl.ExchangeEventConverterImpl.java

@Override
public Calendar convertToCalendar(Collection<ItemType> items, String upn) {
    Calendar result = new Calendar();

    result.getProperties().add(PROD_ID);
    result.getProperties().add(VERSION);

    int size = CollectionUtils.isEmpty(items) ? 0 : items.size();
    log.debug("attempting to convert " + size + " items");
    if (!CollectionUtils.isEmpty(items)) {

        for (ItemType item : items) {
            if (item instanceof CalendarItemType) {
                CalendarItemType calendarItem = (CalendarItemType) item;
                Pair<VEvent, ArrayList<VTimeZone>> pair = null;
                try {
                    pair = convertCalendarItemType(calendarItem, upn);
                } catch (ExchangeEventConverterException e) {
                    log.error("Failed to convert calendarItem:" + e.getMessage());
                }// www.  j av a  2s  .c  om

                if (null != pair) {
                    if (null != pair.getLeft()) {
                        result.getComponents().add(pair.getLeft());
                    } else {
                        log.warn("Failed to generate VEvent for CalendarItemType=" + calendarItem);
                    }
                    if (!CollectionUtils.isEmpty(pair.getRight())) {
                        log.debug("Generated " + pair.getRight().size()
                                + " VTimeZone components for CalendarItemType=" + calendarItem);
                        for (VTimeZone timeZone : pair.getRight()) {
                            result.getComponents().add(timeZone);
                        }
                    } else {
                        log.warn("Failed to generate VTimeZone for CalendarItemType=" + calendarItem);
                    }
                }

            } else if (item instanceof TaskType) {
                TaskType taskItem = (TaskType) item;
                Pair<VToDo, ArrayList<VTimeZone>> pair = convertTaskType(taskItem, upn);
                //TODO handle tasks
            } else {
                log.warn("Not an instanceof CalendarItemType | TaskType.  Cannot convert item: " + item);
            }
        }
    }

    return result;
}

From source file:org.spring.data.gemfire.cache.PeerCacheFunctionExecutionUsingRepositoryOnFilteredLocalDataSetTest.java

@SuppressWarnings("unchecked")
private <T> List<T> getFunctionResults(List<T> results) {
    if (!CollectionUtils.isEmpty(results)) {
        if (results.get(0) instanceof List) {
            assertThat(results.size(), is(equalTo(1)));
            return getFunctionResults((List<T>) results.get(0));
        }/* ww w  .  java  2s.co m*/
    }

    return results;
}

From source file:fr.mby.saml2.sp.impl.config.BasicSpConfig.java

/**
 * Process SP metadatas.//from   ww  w .j  a  va 2s  .c  o m
 * 
 * @throws MetadataProviderException
 * @throws XMLParserException
 */
protected void processSpMetadata() throws MetadataProviderException, XMLParserException {
    Assert.notNull(this.spMetadata, "No SP metadata provided !");
    Assert.isTrue(this.spMetadata.exists(),
            String.format("SP metadata [%s] cannot be found !", this.spMetadata.getFilename()));

    this.spMetadataProvider = OpenSamlHelper.buildMetadataProvider(this.spMetadata);
    Assert.notNull(this.spMetadataProvider, "SP metadata provider wasn't build !");

    final String spEntityId = this.getEntityId();
    final EntityDescriptor spEntityDescriptor = this.spMetadataProvider.getEntityDescriptor(spEntityId);
    Assert.notNull(spEntityDescriptor,
            String.format("No entity descriptor found in SP metadata for SP entityId [%s]", spEntityId));

    final SPSSODescriptor ssoDescriptors = spEntityDescriptor.getSPSSODescriptor(SAMLConstants.SAML20P_NS);
    if (ssoDescriptors != null) {
        // Retrieve Assertion Consumer endpoints URL.
        final List<AssertionConsumerService> acServices = ssoDescriptors.getAssertionConsumerServices();
        if (!CollectionUtils.isEmpty(acServices)) {
            for (final AssertionConsumerService acService : acServices) {
                if (acService != null) {
                    final SamlBindingEnum binding = SamlBindingEnum.fromSamlUri(acService.getBinding());
                    if (binding != null) {
                        this.spAssertionConsumerServices.put(binding, acService);
                    }
                }
            }
        }

        // Retrieve Single Logout endpoints URL.
        final List<SingleLogoutService> slServices = ssoDescriptors.getSingleLogoutServices();
        if (!CollectionUtils.isEmpty(slServices)) {
            for (final SingleLogoutService slService : slServices) {
                if (slService != null) {
                    final SamlBindingEnum binding = SamlBindingEnum.fromSamlUri(slService.getBinding());
                    if (binding != null) {
                        this.spSingleLogoutServices.put(binding, slService);
                    }
                }
            }
        }

        // Retrieve AttributeConsumingInformations.
        final List<AttributeConsumingService> attrConsumingServices = ssoDescriptors
                .getAttributeConsumingServices();
        if (!CollectionUtils.isEmpty(attrConsumingServices)) {
            for (final AttributeConsumingService attrConsumingService : attrConsumingServices) {
                if (attrConsumingService != null) {
                    this.attributeConsumingServices.put(attrConsumingService.getIndex(), attrConsumingService);
                }
            }
        }

        // Retrieve KeyDescriptors
        final List<KeyDescriptor> keyDescriptors = ssoDescriptors.getKeyDescriptors();
        if (!CollectionUtils.isEmpty(keyDescriptors)) {
            for (final KeyDescriptor keyDescriptor : keyDescriptors) {
                if (keyDescriptor != null) {
                    final UsageType usageType = keyDescriptor.getUse();
                    final org.opensaml.xml.signature.KeyInfo keyInfo = keyDescriptor.getKeyInfo();
                    if (keyInfo != null) {
                        final MetadataCredentialResolver mcr = new MetadataCredentialResolver(
                                this.spMetadataProvider);

                        final Criteria criteria1 = new UsageCriteria(keyDescriptor.getUse());
                        final Criteria criteria2 = new EntityIDCriteria(this.getEntityId());
                        final Criteria criteria3 = new MetadataCriteria(SPSSODescriptor.DEFAULT_ELEMENT_NAME,
                                null);
                        final CriteriaSet criteriaSet = new CriteriaSet(criteria1);
                        criteriaSet.add(criteria2);
                        criteriaSet.add(criteria3);
                        try {
                            final BasicX509Credential credentials = (BasicX509Credential) mcr
                                    .resolveSingle(criteriaSet);
                            this.spCredentials.put(usageType, credentials);
                        } catch (final SecurityException e) {
                            BasicSpConfig.LOGGER.error("Error while loading SP metadata credentials !", e);
                        }
                    }
                }
            }
        }
    }

    for (final SamlBindingEnum binding : SamlBindingEnum.values()) {
        final AssertionConsumerService service = this.spAssertionConsumerServices.get(binding);
        Assert.notNull(service, String.format(
                "No AssertionConsumingService for binding [%s] found in the SP metadata with entityId [%s] !",
                binding.getDescription(), spEntityId));
        Assert.isTrue(StringUtils.hasText(service.getLocation()), String.format(
                "No AssertionConsumingService location provided in SP metadata for binding [%s]", binding));
    }

    for (final SamlBindingEnum binding : SamlBindingEnum.values()) {
        final SingleLogoutService service = this.spSingleLogoutServices.get(binding);
        Assert.notNull(service,
                String.format(
                        "No SingleLogoutService for binding [%s] found in the SP metadata with entityId [%s] !",
                        binding.getDescription(), spEntityId));
        Assert.isTrue(StringUtils.hasText(service.getLocation()), String
                .format("No SingleLogoutService location provided in SP metadata for binding [%s]", binding));
    }

    final BasicX509Credential signingCredential = this.spCredentials.get(UsageType.SIGNING);
    Assert.notNull(signingCredential, "No signing credential provided in SP metadata !");

    final BasicX509Credential encryptionCredential = this.spCredentials.get(UsageType.ENCRYPTION);
    if (encryptionCredential == null) {
        this.spCredentials.put(UsageType.ENCRYPTION, signingCredential);
    }
}

From source file:com.alibaba.otter.shared.arbitrate.impl.setl.rpc.RpcStageController.java

/**
 * ????processIdloadedProcessId/*from  w  w w  .  j  a  v  a 2  s .c o  m*/
 */
private Long getMinTransformedProcessId(Long loadedProcessId) {
    ProcessMonitor processMonitor = ArbitrateFactory.getInstance(getPipelineId(), ProcessMonitor.class);
    List<Long> processIds = processMonitor.getCurrentProcessIds();
    // ??node??processloadrpcstage???progress
    if (!CollectionUtils.isEmpty(processIds) && !CollectionUtils.isEmpty(progress)) {
        // load??processId???:
        // 1. zk???current processIds?
        // 2. processId?????
        // if (loadedProcessId != null && !processIds.contains(loadedProcessId)) {
        // // ????leader?
        // processIds = processMonitor.getCurrentProcessIds(true);
        // }

        Long result = null;
        // ?processId load?
        // process?T????L?process?zookeeperwatcher??
        for (Long processId : processIds) {
            if (loadedProcessId == null || processId > loadedProcessId) {
                result = processId;
                break;
            }
        }

        // ??>loadedProcessId?processIdid+1
        // processId??
        if (result == null) {
            result = loadedProcessId + 1;
        }

        if (result != null) {
            StageProgress stage = progress.get(result);
            if (stage != null && stage.getStage().isTransform()) {
                return result;
            } else {
                logger.info("rpc compute [{}] but stage [{}]", result, stage == null ? null : stage.getStage());
                return null;
            }
        }
    }

    return null;
}

From source file:com.azaptree.services.spring.application.config.SpringApplicationServiceConfig.java

private void loadConfigurationClasses(final SpringApplicationService config) throws ClassNotFoundException {
    final ConfigurationClasses configurationClasses = config.getConfigurationClasses();
    if (configurationClasses != null && !CollectionUtils.isEmpty(configurationClasses.getClazz())) {
        final ClassLoader cl = getClass().getClassLoader();
        final List<Class<?>> configClasses = new ArrayList<>(configurationClasses.getClazz().size());
        for (final String clazz : configurationClasses.getClazz()) {
            final Class<?> c = cl.loadClass(clazz.trim());
            if (c.getAnnotation(Configuration.class) == null) {
                throw new IllegalArgumentException(String.format(
                        "Class must be annotated with @org.springframework.context.annotation.Configuration: {}",
                        clazz));// www .j a va2s . c  o m
            }
            configClasses.add(c);
        }
        this.configurationClasses = configClasses.toArray(new Class<?>[configClasses.size()]);
    }

}

From source file:com.mysoft.b2b.event.scheduler.job.EventJob.java

/**
 * app?/*  w  w  w .j ava 2 s.c  om*/
 * @param list 
 */
private Map<String, List<AppSubscribe>> getAppSubGroup(List<AppSubscribe> appSubscribes) {
    Map<String, List<AppSubscribe>> group = new HashMap<String, List<AppSubscribe>>();
    if (!CollectionUtils.isEmpty(appSubscribes)) {
        for (AppSubscribe sub : appSubscribes) {
            if (group.containsKey(sub.getEventTypeCode())) {
                group.get(sub.getEventTypeCode()).add(sub);
            } else {
                List<AppSubscribe> element = new ArrayList<AppSubscribe>();
                element.add(sub);
                group.put(sub.getEventTypeCode(), element);
            }
        }
    }
    return group;
}