|
1 | 1 | package com.linkedin.datahub.graphql.analytics.service;
|
2 | 2 |
|
| 3 | +import static com.linkedin.metadata.Constants.CORP_USER_EDITABLE_INFO_ASPECT_NAME; |
| 4 | +import static com.linkedin.metadata.Constants.CORP_USER_ENTITY_NAME; |
3 | 5 | import static com.linkedin.metadata.Constants.CORP_USER_INFO_ASPECT_NAME;
|
4 | 6 |
|
5 | 7 | import com.google.common.collect.ImmutableSet;
|
6 | 8 | import com.linkedin.common.urn.Urn;
|
7 | 9 | import com.linkedin.common.urn.UrnUtils;
|
8 | 10 | import com.linkedin.dashboard.DashboardInfo;
|
9 |
| -import com.linkedin.datahub.graphql.generated.BarSegment; |
10 |
| -import com.linkedin.datahub.graphql.generated.Cell; |
11 |
| -import com.linkedin.datahub.graphql.generated.Entity; |
12 |
| -import com.linkedin.datahub.graphql.generated.EntityProfileParams; |
13 |
| -import com.linkedin.datahub.graphql.generated.LinkParams; |
14 |
| -import com.linkedin.datahub.graphql.generated.NamedBar; |
15 |
| -import com.linkedin.datahub.graphql.generated.Row; |
16 |
| -import com.linkedin.datahub.graphql.generated.SearchParams; |
| 11 | +import com.linkedin.datahub.graphql.generated.*; |
17 | 12 | import com.linkedin.datahub.graphql.types.common.mappers.UrnToEntityMapper;
|
18 | 13 | import com.linkedin.dataplatform.DataPlatformInfo;
|
19 | 14 | import com.linkedin.dataset.DatasetProperties;
|
|
22 | 17 | import com.linkedin.entity.EnvelopedAspect;
|
23 | 18 | import com.linkedin.entity.client.EntityClient;
|
24 | 19 | import com.linkedin.glossary.GlossaryTermInfo;
|
| 20 | +import com.linkedin.identity.CorpUserEditableInfo; |
25 | 21 | import com.linkedin.identity.CorpUserInfo;
|
26 | 22 | import com.linkedin.metadata.Constants;
|
27 | 23 | import com.linkedin.metadata.key.GlossaryTermKey;
|
|
35 | 31 | import java.util.Set;
|
36 | 32 | import java.util.function.Function;
|
37 | 33 | import java.util.stream.Collectors;
|
| 34 | +import java.util.stream.Stream; |
38 | 35 | import javax.annotation.Nonnull;
|
39 | 36 | import javax.annotation.Nullable;
|
40 | 37 | import lombok.extern.slf4j.Slf4j;
|
@@ -169,36 +166,79 @@ public static void convertToUserInfoRows(
|
169 | 166 | final Map<Urn, EntityResponse> gmsResponseByUser =
|
170 | 167 | entityClient.batchGetV2(
|
171 | 168 | opContext,
|
172 |
| - CORP_USER_INFO_ASPECT_NAME, |
| 169 | + CORP_USER_ENTITY_NAME, |
173 | 170 | userUrns,
|
174 |
| - ImmutableSet.of(CORP_USER_INFO_ASPECT_NAME)); |
175 |
| - final Map<Urn, CorpUserInfo> urnToCorpUserInfo = |
| 171 | + ImmutableSet.of(CORP_USER_INFO_ASPECT_NAME, CORP_USER_EDITABLE_INFO_ASPECT_NAME)); |
| 172 | + final Stream<Map.Entry<Urn, EntityResponse>> entityStream = |
176 | 173 | gmsResponseByUser.entrySet().stream()
|
177 | 174 | .filter(
|
178 | 175 | entry ->
|
179 | 176 | entry.getValue() != null
|
180 |
| - && entry.getValue().getAspects().containsKey(CORP_USER_INFO_ASPECT_NAME)) |
181 |
| - .collect( |
182 |
| - Collectors.toMap( |
183 |
| - Map.Entry::getKey, |
184 |
| - entry -> |
| 177 | + && (entry.getValue().getAspects().containsKey(CORP_USER_INFO_ASPECT_NAME) |
| 178 | + || entry |
| 179 | + .getValue() |
| 180 | + .getAspects() |
| 181 | + .containsKey(CORP_USER_EDITABLE_INFO_ASPECT_NAME))); |
| 182 | + final Map<Urn, Pair<CorpUserInfo, CorpUserEditableInfo>> urnToCorpUserInfo = |
| 183 | + entityStream.collect( |
| 184 | + Collectors.toMap( |
| 185 | + Map.Entry::getKey, |
| 186 | + entry -> { |
| 187 | + CorpUserInfo userInfo = null; |
| 188 | + CorpUserEditableInfo editableInfo = null; |
| 189 | + try { |
| 190 | + userInfo = |
185 | 191 | new CorpUserInfo(
|
186 | 192 | entry
|
187 | 193 | .getValue()
|
188 | 194 | .getAspects()
|
189 | 195 | .get(CORP_USER_INFO_ASPECT_NAME)
|
190 | 196 | .getValue()
|
191 |
| - .data()))); |
| 197 | + .data()); |
| 198 | + } catch (Exception e) { |
| 199 | + // nothing to do |
| 200 | + } |
| 201 | + try { |
| 202 | + |
| 203 | + editableInfo = |
| 204 | + new CorpUserEditableInfo( |
| 205 | + entry |
| 206 | + .getValue() |
| 207 | + .getAspects() |
| 208 | + .get(CORP_USER_EDITABLE_INFO_ASPECT_NAME) |
| 209 | + .getValue() |
| 210 | + .data()); |
| 211 | + } catch (Exception e) { |
| 212 | + // nothing to do |
| 213 | + } |
| 214 | + |
| 215 | + return Pair.of(userInfo, editableInfo); |
| 216 | + })); |
192 | 217 | // Populate a row with the user link, title, and email.
|
193 | 218 | rows.forEach(
|
194 | 219 | row -> {
|
195 | 220 | Urn urn = UrnUtils.getUrn(row.getCells().get(0).getValue());
|
196 | 221 | EntityResponse response = gmsResponseByUser.get(urn);
|
197 | 222 | String maybeDisplayName = response != null ? getUserName(response).orElse(null) : null;
|
198 |
| - String maybeEmail = |
199 |
| - urnToCorpUserInfo.containsKey(urn) ? urnToCorpUserInfo.get(urn).getEmail() : null; |
200 |
| - String maybeTitle = |
201 |
| - urnToCorpUserInfo.containsKey(urn) ? urnToCorpUserInfo.get(urn).getTitle() : null; |
| 223 | + String maybeEmail = null; |
| 224 | + String maybeTitle = null; |
| 225 | + if (urnToCorpUserInfo.containsKey(urn)) { |
| 226 | + Pair<CorpUserInfo, CorpUserEditableInfo> pair = urnToCorpUserInfo.get(urn); |
| 227 | + if (pair.getLeft() != null) { |
| 228 | + CorpUserInfo userInfo = pair.getLeft(); |
| 229 | + maybeEmail = userInfo.getEmail(); |
| 230 | + maybeTitle = userInfo.getTitle(); |
| 231 | + } |
| 232 | + if (pair.getRight() != null) { |
| 233 | + CorpUserEditableInfo userInfo = pair.getRight(); |
| 234 | + if (maybeEmail == null) { |
| 235 | + maybeEmail = userInfo.getEmail(); |
| 236 | + } |
| 237 | + if (maybeTitle == null) { |
| 238 | + maybeTitle = userInfo.getTitle(); |
| 239 | + } |
| 240 | + } |
| 241 | + } |
202 | 242 | if (maybeDisplayName != null) {
|
203 | 243 | row.getCells().get(0).setValue(maybeDisplayName);
|
204 | 244 | }
|
|
0 commit comments