Search in sources :

Example 1 with UserInfoEnrichedAdapter

use of com.ctrip.framework.apollo.portal.enricher.adapter.UserInfoEnrichedAdapter in project apollo by ctripcorp.

the class AdditionalUserInfoEnrichServiceImpl method enrichAdditionalUserInfo.

@Override
public <T> void enrichAdditionalUserInfo(List<? extends T> list, Function<? super T, ? extends UserInfoEnrichedAdapter> mapper) {
    if (CollectionUtils.isEmpty(list)) {
        return;
    }
    if (CollectionUtils.isEmpty(this.enricherList)) {
        return;
    }
    List<UserInfoEnrichedAdapter> adapterList = this.adapt(list, mapper);
    if (CollectionUtils.isEmpty(adapterList)) {
        return;
    }
    Set<String> userIdSet = this.extractOperatorId(adapterList);
    if (CollectionUtils.isEmpty(userIdSet)) {
        return;
    }
    List<UserInfo> userInfoList = this.userService.findByUserIds(new ArrayList<>(userIdSet));
    if (CollectionUtils.isEmpty(userInfoList)) {
        return;
    }
    Map<String, UserInfo> userInfoMap = userInfoList.stream().collect(Collectors.toMap(UserInfo::getUserId, Function.identity()));
    for (UserInfoEnrichedAdapter adapter : adapterList) {
        for (AdditionalUserInfoEnricher enricher : this.enricherList) {
            enricher.enrichAdditionalUserInfo(adapter, userInfoMap);
        }
    }
}
Also used : UserInfo(com.ctrip.framework.apollo.portal.entity.bo.UserInfo) AdditionalUserInfoEnricher(com.ctrip.framework.apollo.portal.enricher.AdditionalUserInfoEnricher) UserInfoEnrichedAdapter(com.ctrip.framework.apollo.portal.enricher.adapter.UserInfoEnrichedAdapter)

Example 2 with UserInfoEnrichedAdapter

use of com.ctrip.framework.apollo.portal.enricher.adapter.UserInfoEnrichedAdapter in project apollo by ctripcorp.

the class AdditionalUserInfoEnrichServiceImpl method adapt.

private <T> List<UserInfoEnrichedAdapter> adapt(List<? extends T> dtoList, Function<? super T, ? extends UserInfoEnrichedAdapter> mapper) {
    List<UserInfoEnrichedAdapter> adapterList = new ArrayList<>(dtoList.size());
    for (T dto : dtoList) {
        if (dto == null) {
            continue;
        }
        UserInfoEnrichedAdapter enrichedAdapter = mapper.apply(dto);
        adapterList.add(enrichedAdapter);
    }
    return adapterList;
}
Also used : ArrayList(java.util.ArrayList) UserInfoEnrichedAdapter(com.ctrip.framework.apollo.portal.enricher.adapter.UserInfoEnrichedAdapter)

Aggregations

UserInfoEnrichedAdapter (com.ctrip.framework.apollo.portal.enricher.adapter.UserInfoEnrichedAdapter)2 AdditionalUserInfoEnricher (com.ctrip.framework.apollo.portal.enricher.AdditionalUserInfoEnricher)1 UserInfo (com.ctrip.framework.apollo.portal.entity.bo.UserInfo)1 ArrayList (java.util.ArrayList)1