
com.atlan.model.graph.ModelGraph Maven / Gradle / Ivy
// Generated by delombok at Wed Oct 16 22:16:04 UTC 2024
/* SPDX-License-Identifier: Apache-2.0
Copyright 2024 Atlan Pte. Ltd. */
package com.atlan.model.graph;
import com.atlan.AtlanClient;
import com.atlan.exception.AtlanException;
import com.atlan.model.assets.Asset;
import com.atlan.model.assets.IModel;
import com.atlan.model.assets.ModelAttribute;
import com.atlan.model.assets.ModelDataModel;
import com.atlan.model.assets.ModelEntity;
import com.atlan.model.assets.ModelEntityAssociation;
import com.atlan.model.assets.ModelVersion;
import com.atlan.model.fields.AtlanField;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Structure through which various model assets can all be traversed.
*/
public class ModelGraph {
private ModelDataModel model;
private ModelVersion version;
private List entities;
private long asOfTime;
private static final List INCLUDES = List.of(ModelEntity.MODEL_ENTITY_MAPPED_TO_ENTITIES, ModelEntity.MODEL_ENTITY_MAPPED_FROM_ENTITIES, ModelAttribute.MODEL_ATTRIBUTE_DATA_TYPE, ModelAttribute.MODEL_ATTRIBUTE_IS_NULLABLE, ModelAttribute.MODEL_ATTRIBUTE_IS_PRIMARY, ModelAttribute.MODEL_ATTRIBUTE_IS_FOREIGN, ModelAttribute.MODEL_ATTRIBUTE_IS_DERIVED, ModelEntityAssociation.MODEL_ENTITY_ASSOCIATION_CARDINALITY, ModelEntityAssociation.MODEL_ENTITY_ASSOCIATION_LABEL, ModelEntityAssociation.MODEL_ENTITY_ASSOCIATION_TO_QUALIFIED_NAME, ModelEntityAssociation.MODEL_ENTITY_ASSOCIATION_FROM_QUALIFIED_NAME);
/**
* Construct a model graph from the provided parameters.
*
* @param client connectivity to the Atlan tenant
* @param time business date for which to retrieve the model graph
* @param prefix (optional) scope of the model graph to retrieve
* @return the model graph for the provided parameters
* @throws AtlanException on any issues communicating with the underlying APIs
*/
public static ModelGraph from(AtlanClient client, long time, String prefix) throws AtlanException {
List assets = IModel.findByTime(client, time, prefix, INCLUDES);
ModelGraphBuilder builder = builder();
Map eg = new HashMap<>();
assets.forEach(it -> {
if (it instanceof ModelDataModel dm) {
builder.model(dm);
} else if (it instanceof ModelVersion mv) {
builder.version(mv);
} else if (it instanceof ModelEntity me) {
if (!eg.containsKey(me.getModelVersionAgnosticQualifiedName())) {
eg.put(me.getModelVersionAgnosticQualifiedName(), ModelEntityGraph.builder());
}
eg.get(me.getModelVersionAgnosticQualifiedName()).details(me);
} else if (it instanceof ModelAttribute ma) {
if (!eg.containsKey(ma.getModelEntityQualifiedName())) {
eg.put(ma.getModelEntityQualifiedName(), ModelEntityGraph.builder());
}
eg.get(ma.getModelEntityQualifiedName()).attribute(ma);
} else if (it instanceof ModelEntityAssociation mea) {
String from = mea.getModelEntityAssociationFromQualifiedName();
String to = mea.getModelEntityAssociationToQualifiedName();
if (!eg.containsKey(from)) {
eg.put(from, ModelEntityGraph.builder());
}
if (!eg.containsKey(to)) {
eg.put(to, ModelEntityGraph.builder());
}
eg.get(from).associatedTo(ModelEntityGraph.AssociatedEntity.builder().entity(ModelEntity.refByQualifiedName(to)).cardinality(mea.getModelEntityAssociationCardinality()).label(mea.getModelEntityAssociationLabel()).build());
eg.get(to).associatedFrom(ModelEntityGraph.AssociatedEntity.builder().entity(ModelEntity.refByQualifiedName(from)).cardinality(mea.getModelEntityAssociationCardinality()).label(mea.getModelEntityAssociationLabel()).build());
}
});
return builder.entities(eg.values().stream().map(ModelEntityGraph.ModelEntityGraphBuilder::build).toList()).build();
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
ModelGraph(final ModelDataModel model, final ModelVersion version, final List entities, final long asOfTime) {
this.model = model;
this.version = version;
this.entities = entities;
this.asOfTime = asOfTime;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
private static class ModelGraphBuilder {
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelDataModel model;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelVersion version;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private java.util.ArrayList entities;
@java.lang.SuppressWarnings("all")
@lombok.Generated
private long asOfTime;
@java.lang.SuppressWarnings("all")
@lombok.Generated
ModelGraphBuilder() {
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelGraph.ModelGraphBuilder model(final ModelDataModel model) {
this.model = model;
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelGraph.ModelGraphBuilder version(final ModelVersion version) {
this.version = version;
return this;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelGraph.ModelGraphBuilder entity(final ModelEntityGraph entity) {
if (this.entities == null) this.entities = new java.util.ArrayList();
this.entities.add(entity);
return this;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelGraph.ModelGraphBuilder entities(final java.util.Collection extends ModelEntityGraph> entities) {
if (entities == null) {
throw new java.lang.NullPointerException("entities cannot be null");
}
if (this.entities == null) this.entities = new java.util.ArrayList();
this.entities.addAll(entities);
return this;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelGraph.ModelGraphBuilder clearEntities() {
if (this.entities != null) this.entities.clear();
return this;
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelGraph.ModelGraphBuilder asOfTime(final long asOfTime) {
this.asOfTime = asOfTime;
return this;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
private ModelGraph build() {
java.util.List entities;
switch (this.entities == null ? 0 : this.entities.size()) {
case 0:
entities = java.util.Collections.emptyList();
break;
case 1:
entities = java.util.Collections.singletonList(this.entities.get(0));
break;
default:
entities = java.util.Collections.unmodifiableList(new java.util.ArrayList(this.entities));
}
return new ModelGraph(this.model, this.version, entities, this.asOfTime);
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public java.lang.String toString() {
return "ModelGraph.ModelGraphBuilder(model=" + this.model + ", version=" + this.version + ", entities=" + this.entities + ", asOfTime=" + this.asOfTime + ")";
}
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
private static ModelGraph.ModelGraphBuilder builder() {
return new ModelGraph.ModelGraphBuilder();
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public ModelDataModel getModel() {
return this.model;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public ModelVersion getVersion() {
return this.version;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public List getEntities() {
return this.entities;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
public long getAsOfTime() {
return this.asOfTime;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof ModelGraph)) return false;
final ModelGraph other = (ModelGraph) o;
if (!other.canEqual((java.lang.Object) this)) return false;
if (this.getAsOfTime() != other.getAsOfTime()) return false;
final java.lang.Object this$model = this.getModel();
final java.lang.Object other$model = other.getModel();
if (this$model == null ? other$model != null : !this$model.equals(other$model)) return false;
final java.lang.Object this$version = this.getVersion();
final java.lang.Object other$version = other.getVersion();
if (this$version == null ? other$version != null : !this$version.equals(other$version)) return false;
final java.lang.Object this$entities = this.getEntities();
final java.lang.Object other$entities = other.getEntities();
if (this$entities == null ? other$entities != null : !this$entities.equals(other$entities)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
@lombok.Generated
protected boolean canEqual(final java.lang.Object other) {
return other instanceof ModelGraph;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
@lombok.Generated
public int hashCode() {
final int PRIME = 59;
int result = 1;
final long $asOfTime = this.getAsOfTime();
result = result * PRIME + (int) ($asOfTime >>> 32 ^ $asOfTime);
final java.lang.Object $model = this.getModel();
result = result * PRIME + ($model == null ? 43 : $model.hashCode());
final java.lang.Object $version = this.getVersion();
result = result * PRIME + ($version == null ? 43 : $version.hashCode());
final java.lang.Object $entities = this.getEntities();
result = result * PRIME + ($entities == null ? 43 : $entities.hashCode());
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy