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.alibaba.otter.manager.biz.config.datacolumnpair.impl.DataColumnPairGroupServiceImpl.java

@Override
public List<ColumnGroup> listByDataMediaPairId(Long dataMediaPairId) {
    Assert.assertNotNull(dataMediaPairId);
    List<DataColumnPairGroupDO> dataColumnPairGroupDos = dataColumnPairGroupDao
            .ListByDataMediaPairId(dataMediaPairId);
    if (CollectionUtils.isEmpty(dataColumnPairGroupDos)) {
        return new ArrayList<ColumnGroup>();
    }// ww  w  .j  a  v  a  2s. c  o  m

    return doToModel(dataColumnPairGroupDos);
}

From source file:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImpl.java

/**
 * {@inheritDoc}/*  w ww.  j  a  va  2 s .  c  o m*/
*/
@Override
public Invitation findAllInvitationById(final String invitationId) {
    cleanupExpiredInvitations();
    List<Invitation> invitations = findByCriteria(Restrictions.eq("invitationHash", invitationId));
    return CollectionUtils.isEmpty(invitations) ? null : invitations.get(0);
}

From source file:com.senacor.domain.user.User.java

public ContactData getMainContact() {
    if (CollectionUtils.isEmpty(getContactData())) {
        return null;
    }
    return getContactData().iterator().next();
}

From source file:com.fredhopper.core.connector.index.generate.validator.ListAttributeValidator.java

@Override
protected void validateValue(final FhAttributeData attribute, final List<Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    for (final Optional<String> valueId : values.rowKeySet()) {
        final Map<Optional<Locale>, String> valueMap = values.row(valueId);
        if (CollectionUtils.isEmpty(valueMap) || valueMap.keySet().size() != 1
                || valueMap.containsKey(Optional.empty()) || valueMap.containsKey(null)) {
            rejectValue(attribute, violations, "The \"list\" attribute value unique Locale key must be set.");
            return;
        }/*  ww  w .  jav a 2  s .  c o m*/
        if (valueMap.containsValue(null) || valueMap.containsValue("")) {
            rejectValue(attribute, violations, "The \"list\" attribute value must not be blank.");
            return;
        }
    }
}

From source file:com.alibaba.china.talos.service.impl.InitAuthProvider.java

@Override
public void execute() {

    AuthProviderDO authProviderDO = new AuthProviderDO();
    authProviderDO.setProviderCode("zhongchengxin");
    authProviderDO.setName("");
    authProviderDO.setTelephone("0571-88052088");

    AuthProviderDO oldAuthProviderDO = authProviderDAO.getByCode("zhongchengxin");

    if (oldAuthProviderDO == null) {
        authProviderDAO.insert(authProviderDO);
    }/*  w  ww . j  a  v a2  s  . com*/

    AuthProviderAtomAuthDO authProviderAtomAuthDO = new AuthProviderAtomAuthDO();
    authProviderAtomAuthDO.setPackageCode("AV");
    authProviderAtomAuthDO.setProviderId(authProviderDAO.getByCode("zhongchengxin").getId());

    AuthProviderAtomAuthDO oldAuthProviderAtomAuthDO = authProviderAtomAuthDAO
            .getByProviderIdAndPackageCode(authProviderDAO.getByCode("zhongchengxin").getId(), "AV");
    if (oldAuthProviderAtomAuthDO == null) {
        authProviderAtomAuthDAO.insert(authProviderAtomAuthDO);
    }

    List<AreaInfoObj> areaInfoObjList = areaQueryService.getProvinces(CHINA_CODE, true);

    if (CollectionUtils.isEmpty(areaInfoObjList)) {
        logger.error("invoke InitAuthProvider,the areaInfoObjList is empty.");
        return;
    }

    Long providerAtomAuthId = authProviderAtomAuthDAO
            .getByProviderIdAndPackageCode(authProviderDAO.getByCode("zhongchengxin").getId(), "AV").getId();
    for (AreaInfoObj areaInfoObj : areaInfoObjList) {
        try {
            AuthDispatcherRuleDO authDispatcherRuleDO = new AuthDispatcherRuleDO();
            authDispatcherRuleDO.setProviderAtomAuthId(providerAtomAuthId);
            authDispatcherRuleDO.setProvince(areaInfoObj.getValue());
            authDispatcherRuleDO.setCalCount(0);
            authDispatcherRuleDO.setWeight(1.0);

            AuthDispatcherRuleParam authDispatcherRuleParam = new AuthDispatcherRuleParam();
            authDispatcherRuleParam.setProvince(areaInfoObj.getValue());
            List<Long> providerAtomAuthIdList = new ArrayList<Long>();
            providerAtomAuthIdList.add(providerAtomAuthId);
            authDispatcherRuleParam.setProviderAtomAuthIdList(providerAtomAuthIdList);
            List<AuthDispatcherRuleDO> authDispatcherRuleDOList = authDispatcherRuleDAO
                    .getListByParam(authDispatcherRuleParam);
            if (CollectionUtils.isEmpty(authDispatcherRuleDOList)) {
                authDispatcherRuleDAO.insert(authDispatcherRuleDO);
            }
            logger.info("InitAuthProvider success,the province=" + areaInfoObj.getName());
        } catch (Exception e) {
            logger.error("InitAuthProvider error,the province=" + areaInfoObj.getName() + ",exception message="
                    + e.getMessage());
        }
    }

}

From source file:fr.mby.portal.coreimpl.auth.BasicAuthenticationManager.java

@Override
public IAuthentication authenticate(final IAuthentication authentication) throws AuthenticationException {
    Assert.notNull(authentication, "No Authentication supplied !");
    Assert.notNull(authentication.getPrincipal(), "No Principal found in Authentication !");
    Assert.notNull(authentication.getCredentials(), "No Credentials found in Authentication !");

    IAuthentication resultingAuth = null;

    // Try to authenticate with internal providers
    final Iterator<IAuthenticationProvider> internalProviderIt = this.internalAuthenticationProviders
            .iterator();//from w ww .j  a v  a2s.  com
    while ((resultingAuth == null || !resultingAuth.isAuthenticated()) && internalProviderIt.hasNext()) {
        final IAuthenticationProvider provider = internalProviderIt.next();
        if (provider != null && provider.supports(authentication)) {
            try {
                resultingAuth = provider.authenticate(authentication);
            } catch (final AuthenticationException e) {
                // Nothing to do : try the next provider
            }
        }
    }

    // Try to authenticate with external providers
    if (!CollectionUtils.isEmpty(this.externalAuthenticationProviders)) {
        final Iterator<IAuthenticationProvider> externalProviderIt = this.externalAuthenticationProviders
                .iterator();
        while ((resultingAuth == null || !resultingAuth.isAuthenticated()) && externalProviderIt.hasNext()) {
            final IAuthenticationProvider provider = externalProviderIt.next();
            if (provider != null && provider.supports(authentication)) {
                try {
                    resultingAuth = provider.authenticate(authentication);
                } catch (final AuthenticationException e) {
                    // Nothing to do : try the next provider
                }
            }
        }
    }

    if (resultingAuth == null) {
        throw new AuthenticationException(authentication,
                "No Provider was able to authenticate the supplied IAuthentication object !");
    }

    return resultingAuth;
}

From source file:fi.vm.kapa.identification.metadata.rest.MetadataResource.java

@GET
@Produces(MediaType.APPLICATION_JSON + "; charset=UTF-8")
public Response getMetadataByType(@QueryParam("type") String providerType) {
    Response response;//from   www. j a  va  2s .c  o m
    logger.debug("Got request for metadata query by type: {}", (providerType != null ? providerType : "ALL"));
    try {
        ProviderType type = (providerType != null ? ProviderType.valueOf(providerType) : null);
        List<Metadata> queryResults = metadataService.getMetadataByType(type);
        List<MetadataDTO> results = queryResults.stream().map(this::createDTO).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(results)) {
            response = Response.ok().entity(results).build();
        } else {
            response = Response.status(Response.Status.NOT_FOUND).build();
        }
    } catch (IllegalArgumentException iae) {
        logger.warn("Bad provider type received");
        response = Response.status(Response.Status.BAD_REQUEST).entity("Invalid provider type").build();
    } catch (Exception e) {
        logger.error("Error getting metadata from database", e);
        response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
    return response;
}

From source file:com.jim.im.topic.service.TopicServiceImpl.java

@Override
public Collection<TopicInfo> createTopic(Integer ownerId, String appId, String tenantId,
        TopicOwnerType topicOwnerType, TopicType[] topicTypes) throws ImParamException {

    List<String> topicNames = generateTopicName(ownerId, appId, tenantId, topicOwnerType, topicTypes);
    if (CollectionUtils.isEmpty(topicNames))
        throw new ImParamException("The set of topic type can be not empty.");
    if (!CollectionUtils.isEmpty(topicDao.findByTopicNames(topicNames))) {
        String errorMsg = String.format("The owner(%s - %s - %s) already had some topics in system.", appId,
                tenantId, ownerId);//from w  ww  . jav a2  s.  co m
        throw new ImParamException(errorMsg);
    }

    Set<TopicInfo> topicInfoSet = Sets.newHashSet();
    for (int index = 0; index < topicTypes.length; index++) {
        TopicInfo temple = TopicInfo.build(ownerId, appId, tenantId, topicOwnerType, topicTypes[index],
                topicNames.get(index));
        temple.setCreated(new Date());
        topicInfoSet.add(temple);
        topicDao.save(temple);
    }
    return topicInfoSet;
}

From source file:com.fredhopper.core.connector.index.generate.validator.SetAttributeValidator.java

@Override
protected void validateValue(final FhAttributeData attribute,
        final List<com.fredhopper.core.connector.index.report.Violation> violations) {
    final Table<Optional<String>, Optional<Locale>, String> values = attribute.getValues();
    for (final Optional<String> valueId : values.rowKeySet()) {
        final Map<Optional<Locale>, String> valueMap = values.row(valueId);
        if (CollectionUtils.isEmpty(valueMap) || valueMap.containsKey(Optional.empty())
                || valueMap.containsKey(null)) {
            rejectValue(attribute, violations, "The \"set\" attribute Locale key must be set.");
            return;
        }//from  ww w . j  a  v  a2  s  .  c o  m
        if (valueMap.containsValue(null) || valueMap.containsValue("")) {
            rejectValue(attribute, violations, "The \"set\" attribute value must not be blank.");
            return;
        }
    }
}

From source file:io.github.jianzhichun.springboot.starters.swagger2.config.AutoSwagger2Configuration.java

@Bean
@ConditionalOnMissingBean(Docket.class)
public Docket docket() {
    ApiInfo apiInfo = new ApiInfoBuilder().title(autoSwagger2Properties.getApiInfo().getTitle())
            .description(autoSwagger2Properties.getApiInfo().getDescription())
            .termsOfServiceUrl(autoSwagger2Properties.getApiInfo().getTermsOfServiceUrl())
            .contact(new Contact(autoSwagger2Properties.getApiInfo().getContact().getName(),
                    autoSwagger2Properties.getApiInfo().getContact().getUrl(),
                    autoSwagger2Properties.getApiInfo().getContact().getEmail()))
            .version(autoSwagger2Properties.getApiInfo().getVersion())
            .license(autoSwagger2Properties.getApiInfo().getLicense())
            .licenseUrl(autoSwagger2Properties.getApiInfo().getLicenseUrl()).build();
    return new Docket(DocumentationType.SWAGGER_2).host(autoSwagger2Properties.getHost())
            .protocols(newHashSet(autoSwagger2Properties.getProtocols()))
            .enable(autoSwagger2Properties.isEnable()).apiInfo(apiInfo).select()
            .apis(not(withMethodAnnotation(IgnoreMethod.class)))
            .apis(RequestHandlerSelectors.basePackage(autoSwagger2Properties.getBasePackage()))
            .paths(CollectionUtils.isEmpty(autoSwagger2Properties.getPaths().getOr()) ? PathSelectors.any()
                    : or(map2list(autoSwagger2Properties.getPaths().getOr(),
                            new Function<String, Predicate<String>>() {
                                @Override
                                public Predicate<String> apply(String path) {
                                    return regex(path);
                                }/*  w  w w  .  j  a  v  a  2  s.  c  om*/
                            })))
            .paths(CollectionUtils.isEmpty(autoSwagger2Properties.getPaths().getNot()) ? PathSelectors.any()
                    : and(map2list(autoSwagger2Properties.getPaths().getNot(),
                            new Function<String, Predicate<String>>() {
                                @Override
                                public Predicate<String> apply(String path) {
                                    return not(regex(path));
                                }
                            })))
            .build();

}