mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-19 06:38:04 +00:00
metadata-models 38.1.6 -> 38.1.8:
38.1.8: Add getFilter method as a search util 38.1.7: Add index builder for corp groups MP_VERSION=corp-identity-gms:1.0.25 MP_VERSION=metadata-models:38.1.8 MP_VERSION=wherehows-samza:1.0.30 This commit is automaticaly generated by li-opensource tool.
This commit is contained in:
parent
8e809e383d
commit
f29a88c365
@ -1,5 +1,7 @@
|
||||
package com.linkedin.metadata.builders.search;
|
||||
|
||||
import com.linkedin.common.CorpGroupUrnArray;
|
||||
import com.linkedin.common.CorpuserUrnArray;
|
||||
import com.linkedin.common.MultiLocaleString;
|
||||
import com.linkedin.common.Owner;
|
||||
import com.linkedin.common.Ownership;
|
||||
@ -7,6 +9,7 @@ import com.linkedin.common.urn.CorpuserUrn;
|
||||
import com.linkedin.common.urn.Urn;
|
||||
import com.linkedin.data.template.StringArray;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ -47,6 +50,28 @@ public final class BuilderUtils {
|
||||
return ldap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given {@link CorpuserUrnArray} return list of corp user names from each of the urns
|
||||
*
|
||||
* @param corpuserUrns {@link CorpuserUrnArray}
|
||||
* @return list of user names extracted from urns
|
||||
*/
|
||||
@Nonnull
|
||||
public static StringArray getCorpUsernames(@Nonnull CorpuserUrnArray corpuserUrns) {
|
||||
return corpuserUrns.stream().map(urn -> urn.getUsernameEntity()).collect(Collectors.toCollection(StringArray::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given {@link CorpGroupUrnArray} return list of corp group names from each of the urns
|
||||
*
|
||||
* @param corpgroupUrns {@link CorpGroupUrnArray}
|
||||
* @return list of group names extracted from urns
|
||||
*/
|
||||
@Nonnull
|
||||
public static StringArray getCorpGroupnames(@Nonnull CorpGroupUrnArray corpgroupUrns) {
|
||||
return corpgroupUrns.stream().map(urn -> urn.getGroupNameEntity()).collect(Collectors.toCollection(StringArray::new));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a Multi locale String to users preferred language
|
||||
* @param multiLocaleString
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.linkedin.metadata.builders.search;
|
||||
|
||||
import com.linkedin.common.urn.CorpGroupUrn;
|
||||
import com.linkedin.data.template.RecordTemplate;
|
||||
import com.linkedin.identity.CorpGroupInfo;
|
||||
import com.linkedin.metadata.search.CorpGroupDocument;
|
||||
import com.linkedin.metadata.snapshot.CorpGroupSnapshot;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Nonnull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public class CorpGroupIndexBuilder extends BaseIndexBuilder<CorpGroupDocument> {
|
||||
|
||||
public CorpGroupIndexBuilder() {
|
||||
super(Collections.singletonList(CorpGroupSnapshot.class), CorpGroupDocument.class);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private CorpGroupDocument getDocumentToUpdateFromAspect(@Nonnull CorpGroupUrn urn,
|
||||
@Nonnull CorpGroupInfo corpGroupInfo) {
|
||||
return new CorpGroupDocument().setUrn(urn)
|
||||
.setAdmins(BuilderUtils.getCorpUsernames(corpGroupInfo.getAdmins()))
|
||||
.setMembers(BuilderUtils.getCorpUsernames(corpGroupInfo.getMembers()))
|
||||
.setGroups(BuilderUtils.getCorpGroupnames(corpGroupInfo.getGroups()))
|
||||
.setEmail(corpGroupInfo.getEmail());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private List<CorpGroupDocument> getDocumentsToUpdateFromSnapshotType(@Nonnull CorpGroupSnapshot corpGroupSnapshot) {
|
||||
final CorpGroupUrn urn = corpGroupSnapshot.getUrn();
|
||||
return corpGroupSnapshot.getAspects().stream().map(aspect -> {
|
||||
if (aspect.isCorpGroupInfo()) {
|
||||
return getDocumentToUpdateFromAspect(urn, aspect.getCorpGroupInfo());
|
||||
}
|
||||
return null;
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public final List<CorpGroupDocument> getDocumentsToUpdate(@Nonnull RecordTemplate genericSnapshot) {
|
||||
if (genericSnapshot instanceof CorpGroupSnapshot) {
|
||||
return getDocumentsToUpdateFromSnapshotType((CorpGroupSnapshot) genericSnapshot);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public Class<CorpGroupDocument> getDocumentType() {
|
||||
return CorpGroupDocument.class;
|
||||
}
|
||||
}
|
@ -70,6 +70,7 @@ public class CorpUserInfoIndexBuilder extends BaseIndexBuilder<CorpUserInfoDocum
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public Class<CorpUserInfoDocument> getDocumentType() {
|
||||
return CorpUserInfoDocument.class;
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package com.linkedin.metadata.builders.search;
|
||||
|
||||
import com.linkedin.common.CorpGroupUrnArray;
|
||||
import com.linkedin.common.CorpuserUrnArray;
|
||||
import com.linkedin.common.urn.CorpGroupUrn;
|
||||
import com.linkedin.common.urn.CorpuserUrn;
|
||||
import com.linkedin.identity.CorpGroupInfo;
|
||||
import com.linkedin.metadata.aspect.CorpGroupAspect;
|
||||
import com.linkedin.metadata.aspect.CorpGroupAspectArray;
|
||||
import com.linkedin.metadata.search.CorpGroupDocument;
|
||||
import com.linkedin.metadata.snapshot.CorpGroupSnapshot;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
|
||||
public class CorpGroupIndexBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testGetDocumentsToUpdateFromDatasetSnapshot() {
|
||||
CorpGroupUrn corpGroupUrn = new CorpGroupUrn("foo");
|
||||
CorpGroupSnapshot corpGroupSnapshot = new CorpGroupSnapshot().setUrn(corpGroupUrn).setAspects(new CorpGroupAspectArray());
|
||||
String groupName = "bar";
|
||||
String member = "baz";
|
||||
String email = "xyz@linkedin.com";
|
||||
String admin1 = "admin1";
|
||||
String admin2 = "admin2";
|
||||
CorpuserUrn corpMember = new CorpuserUrn(member);
|
||||
CorpGroupUrn corpGroup = new CorpGroupUrn(groupName);
|
||||
CorpuserUrn corpAdmin1 = new CorpuserUrn(admin1);
|
||||
CorpuserUrn corpAdmin2 = new CorpuserUrn(admin2);
|
||||
CorpGroupInfo corpGroupInfo = new CorpGroupInfo().setAdmins(new CorpuserUrnArray(Arrays.asList(corpAdmin1, corpAdmin2))).setEmail(email)
|
||||
.setGroups(new CorpGroupUrnArray(Collections.singleton(corpGroup)))
|
||||
.setMembers(new CorpuserUrnArray(Collections.singleton(corpMember)));
|
||||
CorpGroupAspect corpGroupAspect = new CorpGroupAspect();
|
||||
corpGroupAspect.setCorpGroupInfo(corpGroupInfo);
|
||||
corpGroupSnapshot.getAspects().add(corpGroupAspect);
|
||||
|
||||
List<CorpGroupDocument> actualDocs = new CorpGroupIndexBuilder().getDocumentsToUpdate(corpGroupSnapshot);
|
||||
|
||||
assertEquals(actualDocs.size(), 1);
|
||||
assertEquals(actualDocs.get(0).getUrn(), corpGroupUrn);
|
||||
assertEquals(actualDocs.get(0).getAdmins(), Arrays.asList(admin1, admin2));
|
||||
assertEquals(actualDocs.get(0).getMembers(), Collections.singletonList(member));
|
||||
assertEquals(actualDocs.get(0).getGroups(), Collections.singletonList(groupName));
|
||||
assertEquals(actualDocs.get(0).getEmail(), email);
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.linkedin.metadata.dao.utils;
|
||||
|
||||
import com.linkedin.metadata.query.Criterion;
|
||||
import com.linkedin.metadata.query.Filter;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
public class SearchUtilsTest {
|
||||
@Test
|
||||
public void testGetFilter() {
|
||||
final Map requestMap = Collections.unmodifiableMap(new HashMap() {
|
||||
{
|
||||
put("key1", "value1");
|
||||
put("key2", "value2");
|
||||
}
|
||||
});
|
||||
final Filter filter = SearchUtils.getFilter(requestMap);
|
||||
assertEquals(filter.getCriteria().stream().collect(Collectors.toMap(Criterion::getField, Criterion::getValue)),
|
||||
requestMap);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
{
|
||||
"type": "record",
|
||||
"name": "CorpGroupDocument",
|
||||
"namespace": "com.linkedin.metadata.search",
|
||||
"doc": "Data model for Corp Group entity search",
|
||||
"include": [
|
||||
"BaseDocument"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"name": "urn",
|
||||
"type": "com.linkedin.common.CorpGroupUrn",
|
||||
"doc": "Urn for the Corp group."
|
||||
},
|
||||
{
|
||||
"name": "email",
|
||||
"type": "string",
|
||||
"doc": "Email of the corp group",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "members",
|
||||
"type": {
|
||||
"type": "array",
|
||||
"items": "string"
|
||||
},
|
||||
"doc": "ldap usernames of corp users who are direct members of this group",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "admins",
|
||||
"type": {
|
||||
"type": "array",
|
||||
"items": "string"
|
||||
},
|
||||
"doc": "ldap usernames of corp users who are direct admins of this group",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "groups",
|
||||
"type": {
|
||||
"type": "array",
|
||||
"items": "string"
|
||||
},
|
||||
"doc": "List of group names who are part of this group",
|
||||
"optional": true
|
||||
}
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user