Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further experimental work on data model assets #909

Merged
merged 9 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

dependencies {
implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:2.0.20")
implementation("org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:2.0.21")
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.25.0")
implementation("io.freefair.gradle:lombok-plugin:8.10.2")
implementation("net.ltgt.gradle:gradle-errorprone-plugin:4.0.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {
testImplementation(project(":package-toolkit:testing"))
// In your own project, you would use this in place of the 1 dependency above:
//testImplementation("com.atlan:package-toolkit-testing:+")
testImplementation("org.jetbrains.kotlin:kotlin-test:2.0.20")
testImplementation("org.jetbrains.kotlin:kotlin-test:2.0.21")
}

pkl {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/com.atlan.kotlin.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {
runtimeOnly("org.apache.logging.log4j:log4j-core:2.24.1")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1")
testImplementation("org.testng:testng:7.10.2")
testImplementation("org.jetbrains.kotlin:kotlin-test:2.0.20")
testImplementation("org.jetbrains.kotlin:kotlin-test:2.0.21")
}

tasks {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
GROUP=com.atlan
VERSION_NAME=2.2.4-SNAPSHOT
VERSION_NAME=2.2.5-SNAPSHOT

POM_URL=https://github.com/atlanhq/atlan-java
[email protected]:atlanhq/atlan-java.git
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ log4j = "2.24.1"
wiremock = "3.9.1"
jnanoid = "2.0.0"
numaflow = "0.8.0"
awssdk = "2.28.19"
awssdk = "2.28.21"
gcs = "26.48.0"
system-stubs = "2.1.7"
fastcsv = "3.3.1"
Expand Down
235 changes: 191 additions & 44 deletions integration-tests/src/test/java/com/atlan/java/sdk/ModelTest.java

Large diffs are not rendered by default.

37 changes: 25 additions & 12 deletions sdk/src/main/java/com/atlan/model/assets/IModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.atlan.model.enums.AtlanStatus;
import com.atlan.model.enums.CertificateStatus;
import com.atlan.model.enums.SourceCostUnitType;
import com.atlan.model.fields.AtlanField;
import com.atlan.model.fields.KeywordField;
import com.atlan.model.fields.KeywordTextField;
import com.atlan.model.fields.NumericField;
Expand All @@ -25,6 +26,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.time.Instant;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.SortedSet;
Expand Down Expand Up @@ -117,11 +119,14 @@ public static String getNameFromSlug(String slug) {
* @param client connectivity to the Atlan tenant
* @param businessDate time at which the model assets were active
* @param prefix (optional) qualifiedName prefix to limit the model assets to fetch
* @param extraAttributes (optional) additional attributes to retrieve for each model asset
* @return all model assets active at the requested time
* @throws AtlanException on any issues with underlying API interactions
*/
public static List<Asset> findByTime(AtlanClient client, Date businessDate, String prefix) throws AtlanException {
return findByTime(client, businessDate.toInstant(), prefix);
public static List<Asset> findByTime(
AtlanClient client, Date businessDate, String prefix, List<AtlanField> extraAttributes)
throws AtlanException {
return findByTime(client, businessDate.toInstant(), prefix, extraAttributes);
}

/**
Expand All @@ -130,12 +135,14 @@ public static List<Asset> findByTime(AtlanClient client, Date businessDate, Stri
* @param client connectivity to the Atlan tenant
* @param businessDate time at which the model assets were active
* @param prefix (optional) qualifiedName prefix to limit the model assets to fetch
* @param extraAttributes (optional) additional attributes to retrieve for each model asset
* @return all model assets active at the requested time
* @throws AtlanException on any issues with underlying API interactions
*/
public static List<Asset> findByTime(AtlanClient client, Instant businessDate, String prefix)
public static List<Asset> findByTime(
AtlanClient client, Instant businessDate, String prefix, List<AtlanField> extraAttributes)
throws AtlanException {
return findByTime(client, businessDate.toEpochMilli(), prefix);
return findByTime(client, businessDate.toEpochMilli(), prefix, extraAttributes);
}

/**
Expand All @@ -144,24 +151,30 @@ public static List<Asset> findByTime(AtlanClient client, Instant businessDate, S
* @param client connectivity to the Atlan tenant
* @param businessDate time at which the model assets were active
* @param prefix (optional) qualifiedName prefix to limit the model assets to fetch
* @param extraAttributes (optional) additional attributes to retrieve for each model asset
* @return all model assets active at the requested time
* @throws AtlanException on any issues with underlying API interactions
*/
public static List<Asset> findByTime(AtlanClient client, long businessDate, String prefix) throws AtlanException {
public static List<Asset> findByTime(
AtlanClient client, long businessDate, String prefix, List<AtlanField> extraAttributes)
throws AtlanException {
Query subQuery = FluentSearch._internal()
.whereSome(ModelDataModel.MODEL_EXPIRED_AT_BUSINESS_DATE.gt(businessDate))
.whereSome(ModelDataModel.MODEL_EXPIRED_AT_BUSINESS_DATE.eq(0))
.whereSome(MODEL_EXPIRED_AT_BUSINESS_DATE.gt(businessDate))
.whereSome(MODEL_EXPIRED_AT_BUSINESS_DATE.eq(0))
.minSomes(1)
.build()
.toQuery();
return client
.assets
.select()
.includeOnResults(ModelAttribute.MODEL_BUSINESS_DATE)
.includeOnResults(ModelDataModel.MODEL_EXPIRED_AT_BUSINESS_DATE)
.includeOnResults(ModelAttribute.DESCRIPTION)
.includeOnResults(ModelAttribute.MODEL_NAMESPACE)
.includeOnResults(ModelAttribute.MODEL_ENTITY_QUALIFIED_NAME)
.includesOnResults(extraAttributes != null ? extraAttributes : Collections.emptyList())
.includeOnResults(MODEL_BUSINESS_DATE)
.includeOnResults(MODEL_EXPIRED_AT_BUSINESS_DATE)
.includeOnResults(Asset.DESCRIPTION)
.includeOnResults(MODEL_NAMESPACE)
.includeOnResults(MODEL_ENTITY_QUALIFIED_NAME)
.includeOnResults(MODEL_VERSION_AGNOSTIC_QUALIFIED_NAME)
.includeRelationshipAttributes(true)
.where(Asset.QUALIFIED_NAME.startsWith(prefix))
.where(ModelDataModel.MODEL_BUSINESS_DATE.lte(businessDate))
.where(subQuery)
Expand Down
30 changes: 22 additions & 8 deletions sdk/src/main/java/com/atlan/model/assets/ModelAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,26 +415,33 @@ public static boolean restore(AtlanClient client, String qualifiedName) throws A
Map.of(
"connectionQualifiedName", entity.getConnectionQualifiedName(),
"name", entity.getName(),
"qualifiedName", entity.getModelVersionAgnosticQualifiedName()));
"qualifiedName", entity.getModelVersionAgnosticQualifiedName(),
"type", entity.getModelType()));
return creator(
name,
entity.getConnectionQualifiedName(),
entity.getName(),
entity.getModelVersionAgnosticQualifiedName());
name,
entity.getConnectionQualifiedName(),
entity.getName(),
entity.getModelVersionAgnosticQualifiedName(),
entity.getModelType())
.clearModelAttributeEntities()
.modelAttributeEntity(entity.trimToReference().toBuilder()
.semantic(SaveSemantic.APPEND)
.build());
}

/**
* Builds the minimal object necessary to create a ModelAttribute.
*
* @param name of the ModelAttribute
* @param entityQualifiedName unique (version-agnostic) name of the entity in which this ModelAttribute exists
* @param modelType type of model in which this attribute exists
* @return the minimal request necessary to create the ModelAttribute, as a builder
*/
public static ModelAttributeBuilder<?, ?> creator(String name, String entityQualifiedName) {
public static ModelAttributeBuilder<?, ?> creator(String name, String entityQualifiedName, String modelType) {
String entitySlug = StringUtils.getNameFromQualifiedName(entityQualifiedName);
String entityName = IModel.getNameFromSlug(entitySlug);
String connectionQualifiedName = StringUtils.getConnectionQualifiedName(entityQualifiedName);
return creator(name, connectionQualifiedName, entityName, entityQualifiedName);
return creator(name, connectionQualifiedName, entityName, entityQualifiedName, modelType);
}

/**
Expand All @@ -444,10 +451,15 @@ public static boolean restore(AtlanClient client, String qualifiedName) throws A
* @param connectionQualifiedName unique name of the connection in which to create this ModelAttribute
* @param entityName simple name (version-agnostic) of the entity in which to create this ModelAttribute
* @param entityQualifiedName unique name (version-agnostic) of the entity in which to create this ModelAttribute
* @param modelType type of model in which this attribute exists
* @return the minimal request necessary to create the ModelAttribute, as a builder
*/
public static ModelAttributeBuilder<?, ?> creator(
String name, String connectionQualifiedName, String entityName, String entityQualifiedName) {
String name,
String connectionQualifiedName,
String entityName,
String entityQualifiedName,
String modelType) {
String modelQualifiedName = StringUtils.getParentQualifiedNameFromQualifiedName(entityQualifiedName);
String modelName = IModel.getNameFromSlug(StringUtils.getNameFromQualifiedName(modelQualifiedName));
AtlanConnectorType connectorType = Connection.getConnectorTypeFromQualifiedName(connectionQualifiedName);
Expand All @@ -458,7 +470,9 @@ public static boolean restore(AtlanClient client, String qualifiedName) throws A
.modelQualifiedName(modelQualifiedName)
.modelEntityName(entityName)
.modelEntityQualifiedName(entityQualifiedName)
.modelAttributeEntity(ModelEntity.refByQualifiedName(entityQualifiedName, SaveSemantic.APPEND))
.modelVersionAgnosticQualifiedName(generateQualifiedName(name, entityQualifiedName))
.modelType(modelType)
.connectorType(connectorType)
.connectionQualifiedName(connectionQualifiedName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.atlan.exception.InvalidRequestException;
import com.atlan.exception.NotFoundException;
import com.atlan.model.enums.AtlanAnnouncementType;
import com.atlan.model.enums.AtlanConnectorType;
import com.atlan.model.enums.CertificateStatus;
import com.atlan.model.enums.ModelCardinalityType;
import com.atlan.model.relations.Reference;
Expand Down Expand Up @@ -376,20 +377,121 @@ public static boolean restore(AtlanClient client, String qualifiedName) throws A
return Asset.restore(client, TYPE_NAME, qualifiedName);
}

/**
* Builds the minimal object necessary to create a ModelAttributeAssociation.
*
* @param name of the ModelAttributeAssociation
* @param from entity (version-agnostic) from which the association exists
* @param to entity (version-agnostic) to which the association exists
* @return the minimal request necessary to create the ModelAttributeAssociation, as a builder
* @throws InvalidRequestException if the from or to are provided without a modelVersionAgnosticQualifiedName
*/
public static ModelAttributeAssociationBuilder<?, ?> creator(String name, ModelAttribute from, ModelAttribute to)
throws InvalidRequestException {
validateRelationship(
ModelAttribute.TYPE_NAME,
Map.of(
"from_connectionQualifiedName", from.getConnectionQualifiedName(),
"from_qualifiedName", from.getModelVersionAgnosticQualifiedName(),
"to_qualifiedName", to.getModelVersionAgnosticQualifiedName()));
return creator(
name,
from.getConnectionQualifiedName(),
from.getModelVersionAgnosticQualifiedName(),
to.getModelVersionAgnosticQualifiedName())
.modelAttributeAssociationFrom(from.trimToReference())
.modelAttributeAssociationTo(to.trimToReference());
}

/**
* Builds the minimal object necessary to create a ModelAttributeAssociation.
*
* @param name of the ModelAttributeAssociation
* @param fromQualifiedName unique (version-agnostic) name of the entity from which the association exists
* @param toQualifiedName unique (version-agnostic) name of the entity to which the association exists
* @return the minimal request necessary to create the ModelAttributeAssociation, as a builder
*/
public static ModelAttributeAssociationBuilder<?, ?> creator(
String name, String fromQualifiedName, String toQualifiedName) {
String connectionQualifiedName = StringUtils.getConnectionQualifiedName(fromQualifiedName);
return creator(name, connectionQualifiedName, fromQualifiedName, toQualifiedName);
}

/**
* Builds the minimal object necessary to create a ModelAttributeAssociation.
*
* @param name of the ModelAttributeAssociation
* @param connectionQualifiedName unique name of the connection in which to create this ModelAttributeAssociation
* @param fromQualifiedName unique (version-agnostic) name of the entity from which the association exists
* @param toQualifiedName unique (version-agnostic) name of the entity to which the association exists
* @return the minimal request necessary to create the ModelAttributeAssociation, as a builder
*/
public static ModelAttributeAssociationBuilder<?, ?> creator(
String name, String connectionQualifiedName, String fromQualifiedName, String toQualifiedName) {
AtlanConnectorType connectorType = Connection.getConnectorTypeFromQualifiedName(connectionQualifiedName);
String qualifiedName = generateQualifiedName(name, fromQualifiedName, toQualifiedName);
String modelEntityQualifiedName = StringUtils.getParentQualifiedNameFromQualifiedName(fromQualifiedName);
String modelEntityName = IModel.getNameFromSlug(StringUtils.getNameFromQualifiedName(modelEntityQualifiedName));
String modelQualifiedName = StringUtils.getParentQualifiedNameFromQualifiedName(modelEntityQualifiedName);
String modelName = IModel.getNameFromSlug(StringUtils.getNameFromQualifiedName(modelQualifiedName));
return ModelAttributeAssociation._internal()
.guid("-" + ThreadLocalRandom.current().nextLong(0, Long.MAX_VALUE - 1))
.name(name)
.qualifiedName(qualifiedName)
.modelVersionAgnosticQualifiedName(qualifiedName)
.connectorType(connectorType)
.connectionQualifiedName(connectionQualifiedName)
.modelName(modelName)
.modelQualifiedName(modelQualifiedName)
.modelEntityName(modelEntityName)
.modelEntityQualifiedName(modelEntityQualifiedName)
.modelAttributeAssociationFrom(ModelAttribute.refByQualifiedName(fromQualifiedName))
.modelAttributeAssociationFromQualifiedName(fromQualifiedName)
.modelAttributeAssociationTo(ModelAttribute.refByQualifiedName(toQualifiedName))
.modelAttributeAssociationToQualifiedName(toQualifiedName)
.modelAttributeAssociationLabel(name);
}

/**
* Builds the minimal object necessary to update a ModelAttributeAssociation.
*
* @param versionAgnosticQualifiedName of the ModelAttributeAssociation
* @param name of the ModelAttributeAssociation
* @return the minimal request necessary to update the ModelAttributeAssociation, as a builder
*/
public static ModelAttributeAssociationBuilder<?, ?> updater(String versionAgnosticQualifiedName, String name) {
return ModelAttributeAssociation._internal()
.guid("-" + ThreadLocalRandom.current().nextLong(0, Long.MAX_VALUE - 1))
.modelVersionAgnosticQualifiedName(versionAgnosticQualifiedName)
.name(name);
}

/**
* Builds the minimal object necessary to update a ModelAttributeAssociation.
*
* @param qualifiedName of the ModelAttributeAssociation
* @param name of the ModelAttributeAssociation
* @return the minimal request necessary to update the ModelAttributeAssociation, as a builder
*/
public static ModelAttributeAssociationBuilder<?, ?> updater(String qualifiedName, String name) {
public static ModelAttributeAssociationBuilder<?, ?> updaterForVersion(String qualifiedName, String name) {
return ModelAttributeAssociation._internal()
.guid("-" + ThreadLocalRandom.current().nextLong(0, Long.MAX_VALUE - 1))
.qualifiedName(qualifiedName)
.name(name);
}

/**
* Generate a unique ModelAttributeAssociation name.
*
* @param name of the ModelAttributeAssociation
* @param fromQualifiedName unique (version-agnostic) name of the entity from which the association exists
* @param toQualifiedName unique (version-agnostic) name of the entity to which the association exists
* @return a unique name for the ModelAttributeAssociation
*/
public static String generateQualifiedName(String name, String fromQualifiedName, String toQualifiedName) {
return fromQualifiedName + "<<" + name + ">>" + toQualifiedName;
}

/**
* Builds the minimal object necessary to apply an update to a ModelAttributeAssociation, from a potentially
* more-complete ModelAttributeAssociation object.
Expand All @@ -402,9 +504,9 @@ public static boolean restore(AtlanClient client, String qualifiedName) throws A
validateRequired(
TYPE_NAME,
Map.of(
"qualifiedName", this.getQualifiedName(),
"modelVersionAgnosticQualifiedName", this.getModelVersionAgnosticQualifiedName(),
"name", this.getName()));
return updater(this.getQualifiedName(), this.getName());
return updater(this.getModelVersionAgnosticQualifiedName(), this.getName());
}

/**
Expand Down
Loading
Loading