Skip to content

Commit

Permalink
Merge remote-tracking branch 'acryl/jj--adding-entity-secrvices' into…
Browse files Browse the repository at this point in the history
… jj--adding-entity-services
  • Loading branch information
jjoyce0510 committed Sep 14, 2022
2 parents 15a33fa + 0c77b7e commit d033d09
Show file tree
Hide file tree
Showing 15 changed files with 3,140 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static com.linkedin.datahub.graphql.resolvers.mutate.MutationUtils.*;


// TODO: Move to consuming from DomainService.
@Slf4j
public class DomainUtils {
private static final ConjunctivePrivilegeGroup ALL_PRIVILEGES_GROUP = new ConjunctivePrivilegeGroup(ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import static com.linkedin.datahub.graphql.resolvers.mutate.MutationUtils.*;


// TODO: Move to consuming GlossaryTermService, TagService.
@Slf4j
public class LabelUtils {
private static final ConjunctivePrivilegeGroup ALL_PRIVILEGES_GROUP = new ConjunctivePrivilegeGroup(ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import static com.linkedin.datahub.graphql.resolvers.mutate.MutationUtils.*;


// TODO: Move to consuming from OwnerService
@Slf4j
public class OwnerUtils {
private static final ConjunctivePrivilegeGroup ALL_PRIVILEGES_GROUP = new ConjunctivePrivilegeGroup(ImmutableList.of(
Expand Down
1 change: 1 addition & 0 deletions metadata-io/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {
compile project(path: ':metadata-models')
compile project(':metadata-service:restli-client')


compile spec.product.pegasus.data
compile spec.product.pegasus.generator

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package com.linkedin.metadata.entity;

import com.google.common.collect.ImmutableSet;
import com.linkedin.common.UrnArray;
import com.linkedin.common.urn.Urn;
import com.linkedin.data.template.RecordTemplate;
import com.linkedin.entity.Aspect;
import com.linkedin.entity.EntityResponse;
import com.linkedin.events.metadata.ChangeType;
import com.linkedin.metadata.query.ListResult;
import com.linkedin.metadata.search.SearchEntity;
import com.linkedin.metadata.search.SearchResult;
import com.linkedin.metadata.utils.EntityKeyUtils;
import com.linkedin.metadata.utils.GenericRecordUtils;
import com.linkedin.mxe.GenericAspect;
import com.linkedin.mxe.MetadataChangeProposal;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import com.linkedin.entity.client.EntityClient;
import com.datahub.authentication.Authentication;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;

@Slf4j
Expand All @@ -39,6 +51,46 @@ public static List<MetadataChangeProposal> getAdditionalChanges(
.collect(Collectors.toList());
}

@Nullable
public static Aspect getLatestAspect(
Urn urn,
String aspectName,
EntityClient entityClient,
Authentication authentication
) throws Exception {
EntityResponse response = entityClient.getV2(
urn.getEntityType(),
urn,
ImmutableSet.of(aspectName),
authentication);
if (response != null && response.getAspects().containsKey(aspectName)) {
return response.getAspects().get(aspectName).getValue();
}
return null;
}

public static Map<Urn, Aspect> batchGetLatestAspect(
String entity,
Set<Urn> urns,
String aspectName,
EntityClient entityClient,
Authentication authentication
) throws Exception {
final Map<Urn, EntityResponse> gmsResponse = entityClient.batchGetV2(
entity,
urns,
ImmutableSet.of(aspectName),
authentication);
final Map<Urn, Aspect> finalResult = new HashMap<>();
for (Urn urn : urns) {
EntityResponse response = gmsResponse.get(urn);
if (response != null && response.getAspects().containsKey(aspectName)) {
finalResult.put(urn, response.getAspects().get(aspectName).getValue());
}
}
return finalResult;
}

private static MetadataChangeProposal getProposalFromAspect(String aspectName, RecordTemplate aspect,
MetadataChangeProposal original) {
try {
Expand All @@ -52,4 +104,30 @@ private static MetadataChangeProposal getProposalFromAspect(String aspectName, R
}
return null;
}
}

public static MetadataChangeProposal buildMetadataChangeProposal(
@Nonnull Urn urn,
@Nonnull String aspectName,
@Nonnull RecordTemplate aspect) {
final MetadataChangeProposal proposal = new MetadataChangeProposal();
proposal.setEntityUrn(urn);
proposal.setEntityType(urn.getEntityType());
proposal.setAspectName(aspectName);
proposal.setAspect(GenericRecordUtils.serializeAspect(aspect));
proposal.setChangeType(ChangeType.UPSERT);
return proposal;
}

public static ListResult toListResult(final SearchResult searchResult) {
if (searchResult == null) {
return null;
}
final ListResult listResult = new ListResult();
listResult.setStart(searchResult.getFrom());
listResult.setCount(searchResult.getPageSize());
listResult.setTotal(searchResult.getNumEntities());
listResult.setEntities(
new UrnArray(searchResult.getEntities().stream().map(SearchEntity::getEntity).collect(Collectors.toList())));
return listResult;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.linkedin.metadata.resource;

import com.linkedin.common.urn.Urn;
import lombok.AllArgsConstructor;
import lombok.Data;


@Data
@AllArgsConstructor
public class ResourceReference {
/**
* The urn of an entity
*/
Urn urn;

/**
* The type of the SubResource
*/
SubResourceType subResourceType;

/**
* The subresource being targeted
*/
String subResource;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.linkedin.metadata.resource;

public enum SubResourceType {
/**
* A field in a dataset
*/
DATASET_FIELD
}
Loading

0 comments on commit d033d09

Please sign in to comment.