Skip to content

Commit

Permalink
Fix qualifiedName of the contract
Browse files Browse the repository at this point in the history
  • Loading branch information
bichitra95 committed Apr 24, 2024
1 parent 2e30f63 commit 32104e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public enum SupportedFileExtensions { XLSX, XLS, CSV }
public static final String ATTR_ASSET_STARRED_BY = "assetStarredBy";
public static final String ATTR_ASSET_STARRED_AT = "assetStarredAt";
public static final String ATTR_CERTIFICATE_STATUS = "certificateStatus";

public static final String ATTR_CONTRACT = "dataContractJson";
public static final String STRUCT_STARRED_DETAILS = "StarredDetails";

public static final String KEYCLOAK_ROLE_ADMIN = "$admin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ private void verifyAccess(AtlasEntityHeader entityHeader, AtlasPrivilege privile
AtlasAuthorizationUtils.verifyAccess(new AtlasEntityAccessRequest(typeRegistry, privilege, entityHeader), errorMessage);
}

AtlasEntity.AtlasEntityWithExtInfo getAssociatedAsset(String contractQName, String typeName) throws AtlasBaseException {
String datasetQName = contractQName.substring(0, contractQName.lastIndexOf('/'));
AtlasEntity.AtlasEntityWithExtInfo getAssociatedAsset(String datasetQName, String typeName) throws AtlasBaseException {

Map<String, Object> uniqAttributes = new HashMap<>();
uniqAttributes.put(QUALIFIED_NAME, datasetQName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import static org.apache.atlas.AtlasErrorCode.*;
import static org.apache.atlas.repository.Constants.ATTR_CERTIFICATE_STATUS;
import static org.apache.atlas.repository.Constants.QUALIFIED_NAME;
import static org.apache.atlas.repository.Constants.ATTR_CONTRACT;
import static org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId;

public class ContractPreProcessor extends AbstractContractPreProcessor {
private static final Logger LOG = LoggerFactory.getLogger(ContractPreProcessor.class);
public static final String ATTR_CONTRACT = "dataContractJson";
public static final String ATTR_VERSION = "dataContractVersion";
public static final String REL_ATTR_GOVERNED_ASSET = "dataContractAsset";
public static final String REL_ATTR_GOVERNED_ASSET_CERTIFIED = "dataContractAssetCertified";
Expand Down Expand Up @@ -102,15 +102,17 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con

String contractString = (String) entity.getAttribute(ATTR_CONTRACT);
DataContract contract = DataContract.deserialize(contractString);
AtlasEntityWithExtInfo associatedAsset = getAssociatedAsset(contractQName, contract.type.name());
String datasetQName = contractQName.substring(0, contractQName.lastIndexOf('/'));
contractQName = String.format("%s/%s/%s", datasetQName, contract.type.name(), CONTRACT_QUALIFIED_NAME_SUFFIX);
AtlasEntityWithExtInfo associatedAsset = getAssociatedAsset(datasetQName, contract.type.name());

authorizeContractCreateOrUpdate(entity, associatedAsset);

contractAttributeSync(entity, contract);
contractString = DataContract.serialize(contract);
entity.setAttribute(ATTR_CONTRACT, contractString);

ContractVersionUtils versionUtil = new ContractVersionUtils(entity, context, entityRetriever, typeRegistry, entityStore, graph, discovery);
ContractVersionUtils versionUtil = new ContractVersionUtils(contractQName, context, entityRetriever, typeRegistry, entityStore, graph, discovery);
AtlasEntity currentVersionEntity = versionUtil.getCurrentVersion();
int newVersionNumber = 1;
if (currentVersionEntity != null) {
Expand Down Expand Up @@ -138,7 +140,7 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con

}
}
entity.setAttribute(QUALIFIED_NAME, String.format("%s/%s/V%s", contractQName, VERSION_PREFIX, newVersionNumber));
entity.setAttribute(QUALIFIED_NAME, String.format("%s/V%s", contractQName, newVersionNumber));
entity.setAttribute(ATTR_VERSION, newVersionNumber);
entity.setRelationshipAttribute(REL_ATTR_GOVERNED_ASSET, getAtlasObjectId(associatedAsset.getEntity()));
if (Objects.equals(entity.getAttribute(ATTR_CERTIFICATE_STATUS), DataContract.STATUS.VERIFIED.name()) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,40 @@ public class ContractVersionUtils {
public final EntityGraphRetriever entityRetriever;
private final AtlasTypeRegistry atlasTypeRegistry;
private AtlasEntityStore entityStore;

private AtlasEntity entity;
private String contractQName;

public final AtlasGraph graph;
private List<AtlasEntityHeader> versionList;
private EntityDiscoveryService discovery;

public ContractVersionUtils(AtlasEntity entity, EntityMutationContext context, EntityGraphRetriever entityRetriever,
public ContractVersionUtils(String contractQName, EntityMutationContext context, EntityGraphRetriever entityRetriever,
AtlasTypeRegistry atlasTypeRegistry, AtlasEntityStore entityStore, AtlasGraph graph,
EntityDiscoveryService discovery) {
this.context = context;
this.entityRetriever = entityRetriever;
this.atlasTypeRegistry = atlasTypeRegistry;
this.graph = graph;
this.entityStore = entityStore;
this.entity = entity;
this.contractQName = contractQName;
this.discovery = discovery;
}

private void extractAllVersions() throws AtlasBaseException {
String contractQName = (String) entity.getAttribute(QUALIFIED_NAME);
String datasetQName = contractQName.substring(0, contractQName.lastIndexOf("/contract"));
List<AtlasEntityHeader> ret = new ArrayList<>();

IndexSearchParams indexSearchParams = new IndexSearchParams();
Map<String, Object> dsl = new HashMap<>();

List mustClauseList = new ArrayList();
mustClauseList.add(mapOf("term", mapOf("__typeName.keyword", CONTRACT_ENTITY_TYPE)));
mustClauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, String.format("%s/contract/version/*", datasetQName))));
mustClauseList.add(mapOf("wildcard", mapOf(QUALIFIED_NAME, String.format("%s/*", contractQName))));

dsl.put("query", mapOf("bool", mapOf("must", mustClauseList)));
Set<String> attributes = new HashSet<>();
attributes.add(ATTR_CONTRACT);

indexSearchParams.setDsl(dsl);
indexSearchParams.setAttributes(attributes);
indexSearchParams.setSuppressLogs(true);

AtlasSearchResult result = discovery.directIndexSearch(indexSearchParams);
Expand Down

0 comments on commit 32104e9

Please sign in to comment.