diff --git a/common/src/main/java/org/apache/atlas/repository/Constants.java b/common/src/main/java/org/apache/atlas/repository/Constants.java index b96e944fef..5051c5de8b 100644 --- a/common/src/main/java/org/apache/atlas/repository/Constants.java +++ b/common/src/main/java/org/apache/atlas/repository/Constants.java @@ -417,7 +417,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"; diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/AbstractContractPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/AbstractContractPreProcessor.java index 4ef8d0ee6d..9b063d38f5 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/AbstractContractPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/AbstractContractPreProcessor.java @@ -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 uniqAttributes = new HashMap<>(); uniqAttributes.put(QUALIFIED_NAME, datasetQName); diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java index 5bf59414cb..b1c2474d41 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractPreProcessor.java @@ -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"; @@ -102,7 +102,9 @@ 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); @@ -110,7 +112,7 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con 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) { @@ -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()) ) { diff --git a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractVersionUtils.java b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractVersionUtils.java index e803e51b1f..149ec2b6ea 100644 --- a/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractVersionUtils.java +++ b/repository/src/main/java/org/apache/atlas/repository/store/graph/v2/preprocessor/contract/ContractVersionUtils.java @@ -23,14 +23,13 @@ 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 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; @@ -38,13 +37,11 @@ public ContractVersionUtils(AtlasEntity entity, EntityMutationContext context, E 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 ret = new ArrayList<>(); IndexSearchParams indexSearchParams = new IndexSearchParams(); @@ -52,11 +49,14 @@ private void extractAllVersions() throws AtlasBaseException { 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 attributes = new HashSet<>(); + attributes.add(ATTR_CONTRACT); indexSearchParams.setDsl(dsl); + indexSearchParams.setAttributes(attributes); indexSearchParams.setSuppressLogs(true); AtlasSearchResult result = discovery.directIndexSearch(indexSearchParams);