Skip to content

Commit

Permalink
Merge branch 'data-contract' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
bichitra95 committed Apr 23, 2024
2 parents 9c2b7fa + 3e75d0f commit e985c96
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ 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 = "dataContractGovernedAsset";
public static final String REL_ATTR_LATEST_CONTRACT = "dataContractLatest";
public static final String REL_ATTR_GOVERNED_ASSET_CERTIFIED = "dataContractGovernedAssetCertified";
public static final String REL_ATTR_GOVERNED_ASSET = "dataContractAsset";
public static final String REL_ATTR_GOVERNED_ASSET_CERTIFIED = "dataContractAssetCertified";
public static final String REL_ATTR_PREVIOUS_VERSION = "dataContractPreviousVersion";
public static final String ASSET_ATTR_HAS_CONTRACT = "hasContract";
public static final String ASSET_ATTR_DESCRIPTION = "description";
Expand Down Expand Up @@ -113,11 +112,11 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con

ContractVersionUtils versionUtil = new ContractVersionUtils(entity, context, entityRetriever, typeRegistry, entityStore, graph, discovery);
AtlasEntity currentVersionEntity = versionUtil.getCurrentVersion();
String latestVersion = "V1";
int newVersionNumber = 1;
if (currentVersionEntity != null) {
// Contract already exist
String qName = (String) currentVersionEntity.getAttribute(QUALIFIED_NAME);
Integer currentVersionNumber = Integer.valueOf(qName.substring(qName.lastIndexOf("/V") + 2));
int currentVersionNumber = Integer.parseInt(qName.substring(qName.lastIndexOf("/V") + 2));
List<String> attributes = getDiffAttributes(context, entity, currentVersionEntity);
if (attributes.isEmpty()) {
// No changes in the contract, Not creating new version
Expand All @@ -129,7 +128,7 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con
return;
} else {
// contract changed (metadata might/not changed). Create new version.
latestVersion = String.format("V%s", currentVersionNumber + 1);
newVersionNumber = currentVersionNumber + 1;

// Attach previous version via rel
entity.setRelationshipAttribute(REL_ATTR_PREVIOUS_VERSION, getAtlasObjectId(currentVersionEntity));
Expand All @@ -139,9 +138,12 @@ private void processCreateContract(AtlasEntity entity, EntityMutationContext con

}
}
entity.setAttribute(QUALIFIED_NAME, String.format("%s/%s/%s", contractQName, VERSION_PREFIX, latestVersion));
entity.setAttribute(ATTR_VERSION, latestVersion);
entity.setAttribute(QUALIFIED_NAME, String.format("%s/%s/V%s", contractQName, VERSION_PREFIX, 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()) ) {
entity.setRelationshipAttribute(REL_ATTR_GOVERNED_ASSET_CERTIFIED, getAtlasObjectId(associatedAsset.getEntity()));
}

datasetAttributeSync(context, associatedAsset.getEntity(), contract, entity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public AtlasEntity getCurrentVersion() throws AtlasBaseException {
if (this.versionList == null) {
extractAllVersions();
}
if (this.versionList == null) {
return null;
}
Collections.sort(this.versionList, (e1, e2) -> {
String e1QName = (String) e1.getAttribute(QUALIFIED_NAME);
String e2QName = (String) e2.getAttribute(QUALIFIED_NAME);

return e2QName.compareTo(e1QName);
});
if (this.versionList.isEmpty()) {
return null;
}
return new AtlasEntity(this.versionList.get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@


@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({"kind", "status", "template_version", "dataset", "type", "columns"})
@JsonPropertyOrder({"kind", "status", "template_version", "datasource", "dataset", "type", "description", "owners",
"tags", "certificate", "columns"})
public class DataContract {
@Valid @NotNull
public String kind;
Expand All @@ -31,12 +32,18 @@ public class DataContract {
@JsonProperty(value = "template_version", defaultValue = "0.0.1")
public String templateVersion;
@Valid @NotNull
public String datasource;
@Valid @NotNull
public String dataset;
@Valid @NotNull
public DATASET_TYPE type;
public String description;
public List<String> owners;
public List<BusinessTag> tags;
public String certificate;
@Valid
public List<Column> columns;
private Map<String, Object> unknownFields = new HashMap<>();
public List<Column> columns;
private Map<String, Object> unknownFields = new HashMap<>();

@JsonSetter("type")
public void setType(String type) throws AtlasBaseException {
Expand Down Expand Up @@ -131,6 +138,23 @@ private boolean isSemVer(String version) {
return matcher.matches();
}

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({"name"})
public static final class BusinessTag {
@NotNull
public String name;
private Map<String, Object> unknownFields = new HashMap<>();

@JsonAnySetter
public void setUnknownFields(String key, Object value) {
unknownFields.put(key, value);
}
@JsonAnyGetter
public Map<String, Object> getUnknownFields() {
return unknownFields;
}

}
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder({"name", "description", "data_type"})
public static final class Column {
Expand Down

0 comments on commit e985c96

Please sign in to comment.