Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.atlan.samples.loaders.models.ObjectDetails Maven / Gradle / Ivy
// Generated by delombok at Thu Sep 07 11:44:18 UTC 2023
/* SPDX-License-Identifier: Apache-2.0 */
/* Copyright 2023 Atlan Pte. Ltd. */
package com.atlan.samples.loaders.models;
import com.atlan.Atlan;
import com.atlan.exception.AtlanException;
import com.atlan.exception.NotFoundException;
import com.atlan.model.assets.*;
import com.atlan.model.enums.AtlanConnectorType;
import com.atlan.util.AssetBatch;
import java.util.*;
/**
* Utility class for capturing the full details provided about a table.
*/
public class ObjectDetails extends AssetDetails {
@java.lang.SuppressWarnings("all")
private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ObjectDetails.class);
public static final String COL_OBJECT_NAME = "OBJECT NAME";
public static final String COL_OBJECT_ARN = "OBJECT ARN";
public static final String COL_OBJECT_PATH = "OBJECT PATH";
public static final String COL_OBJECT_SIZE = "OBJECT SIZE";
public static final String COL_CONTENT_TYPE = "CONTENT TYPE";
private static final List REQUIRED = List.of(ConnectionDetails.COL_CONNECTOR, ConnectionDetails.COL_CONNECTION, BucketDetails.COL_BUCKET_NAME, COL_OBJECT_NAME);
private String connectionQualifiedName;
private String containerQualifiedName;
private String bucketName;
private String name;
private String arn;
private String path;
private Long size;
private String contentType;
/**
* {@inheritDoc}
*/
@Override
public String getIdentity() {
return containerQualifiedName + "/" + name;
}
/**
* Build up details about the object on the provided row.
*
* @param connectionCache a cache of connections that have first been resolved across the spreadsheet
* @param row a row of data from the spreadsheet, as a map from column name to value
* @param delim delimiter used in cells that can contain multiple values
* @return the object details for that row
*/
public static ObjectDetails getFromRow(Map connectionCache, Map row, String delim) {
ObjectDetailsBuilder builder = getFromRow(ObjectDetails.builder(), row, delim);
if (getMissingFields(row, REQUIRED).isEmpty()) {
String connectionQN = ConnectionDetails.getQualifiedName(connectionCache, row);
String bucketQN = BucketDetails.getQualifiedName(connectionCache, row);
if (bucketQN != null && !bucketQN.isEmpty()) {
builder = builder.connectionQualifiedName(connectionQN).containerQualifiedName(bucketQN).bucketName(row.get(BucketDetails.COL_BUCKET_NAME)).name(row.get(COL_OBJECT_NAME)).arn(row.get(COL_OBJECT_ARN)).path(row.get(COL_OBJECT_PATH)).contentType(row.get(COL_CONTENT_TYPE));
String size = row.get(COL_OBJECT_SIZE);
try {
builder = builder.size(Double.valueOf(size).longValue());
} catch (NumberFormatException e) {
log.error("Unable to translate provided object size to a number: {}", size, e);
}
return builder.stub(false).build();
}
}
return null;
}
/**
* Create objects in bulk, if they do not exist, or update them if they do (idempotent).
*
* @param objects the set of objects to ensure exist
* @param batchSize maximum number of objects to create per batch
* @param updateOnly if true, only attempt to update existing assets, otherwise allow assets to be created as well
* @return qualifiedNames of all parent buckets in which assets were created or updated
*/
public static Set upsert(Map objects, int batchSize, boolean updateOnly) {
Set parents = new HashSet<>();
AssetBatch batch = new AssetBatch(Atlan.getDefaultClient(), "object", batchSize);
Map> toClassifyS3 = new HashMap<>();
Map> toClassifyGCS = new HashMap<>();
Map> toClassifyADLS = new HashMap<>();
long totalResults = objects.size();
long localCount = 0;
try {
for (ObjectDetails details : objects.values()) {
String parentQN = details.getContainerQualifiedName();
String bucketName = details.getBucketName();
String objectName = details.getName();
String objectARN = details.getArn();
AtlanConnectorType objectType = Connection.getConnectorTypeFromQualifiedName(parentQN);
switch (objectType) {
case S3:
String connectionQN = details.getConnectionQualifiedName();
if (objectARN != null && !objectARN.isEmpty()) {
if (updateOnly) {
String qualifiedName = IS3.generateQualifiedName(connectionQN, objectARN);
try {
S3Object.get(Atlan.getDefaultClient(), qualifiedName, false);
S3Object toUpdate = S3Object.updater(qualifiedName, objectName).description(details.getDescription()).certificateStatus(details.getCertificate()).certificateStatusMessage(details.getCertificateStatusMessage()).announcementType(details.getAnnouncementType()).announcementTitle(details.getAnnouncementTitle()).announcementMessage(details.getAnnouncementMessage()).ownerUsers(details.getOwnerUsers()).ownerGroups(details.getOwnerGroups()).s3ObjectKey(details.getPath()).s3ObjectSize(details.getSize()).s3ObjectContentType(details.getContentType()).build();
if (!details.getAtlanTags().isEmpty()) {
toClassifyS3.put(toUpdate.getQualifiedName(), details.getAtlanTags());
}
parents.add(parentQN);
localCount++;
if (batch.add(toUpdate) != null) {
log.info(" ... processed {}/{} ({}%)", localCount, totalResults, Math.round(((double) localCount / totalResults) * 100));
}
} catch (NotFoundException e) {
log.warn("Unable to find existing object — skipping: {}", qualifiedName, e);
} catch (AtlanException e) {
log.error("Unable to lookup whether object exists or not.", e);
}
} else {
S3Object s3 = S3Object.creator(objectName, parentQN, bucketName, objectARN).description(details.getDescription()).certificateStatus(details.getCertificate()).certificateStatusMessage(details.getCertificateStatusMessage()).announcementType(details.getAnnouncementType()).announcementTitle(details.getAnnouncementTitle()).announcementMessage(details.getAnnouncementMessage()).ownerUsers(details.getOwnerUsers()).ownerGroups(details.getOwnerGroups()).s3ObjectKey(details.getPath()).s3ObjectSize(details.getSize()).s3ObjectContentType(details.getContentType()).build();
if (!details.getAtlanTags().isEmpty()) {
toClassifyS3.put(s3.getQualifiedName(), details.getAtlanTags());
}
parents.add(parentQN);
localCount++;
if (batch.add(s3) != null) {
log.info(" ... processed {}/{} ({}%)", localCount, totalResults, Math.round(((double) localCount / totalResults) * 100));
}
}
} else {
log.error("Unable to create an S3 object without an ARN: {}", details);
}
break;
case GCS:
if (updateOnly) {
String qualifiedName = GCSObject.generateQualifiedName(objectName, parentQN);
try {
GCSObject.get(Atlan.getDefaultClient(), qualifiedName, false);
GCSObject toUpdate = GCSObject.updater(qualifiedName, objectName).description(details.getDescription()).certificateStatus(details.getCertificate()).certificateStatusMessage(details.getCertificateStatusMessage()).announcementType(details.getAnnouncementType()).announcementTitle(details.getAnnouncementTitle()).announcementMessage(details.getAnnouncementMessage()).ownerUsers(details.getOwnerUsers()).ownerGroups(details.getOwnerGroups()).gcsObjectKey(details.getPath()).gcsObjectSize(details.getSize()).gcsObjectContentType(details.getContentType()).build();
if (!details.getAtlanTags().isEmpty()) {
toClassifyGCS.put(toUpdate.getQualifiedName(), details.getAtlanTags());
}
parents.add(parentQN);
localCount++;
if (batch.add(toUpdate) != null) {
log.info(" ... processed {}/{} ({}%)", localCount, totalResults, Math.round(((double) localCount / totalResults) * 100));
}
} catch (NotFoundException e) {
log.warn("Unable to find existing object — skipping: {}", qualifiedName, e);
} catch (AtlanException e) {
log.error("Unable to lookup whether object exists or not.", e);
}
} else {
GCSObject gcs = GCSObject.creator(objectName, parentQN).description(details.getDescription()).certificateStatus(details.getCertificate()).certificateStatusMessage(details.getCertificateStatusMessage()).announcementType(details.getAnnouncementType()).announcementTitle(details.getAnnouncementTitle()).announcementMessage(details.getAnnouncementMessage()).ownerUsers(details.getOwnerUsers()).ownerGroups(details.getOwnerGroups()).gcsObjectKey(details.getPath()).gcsObjectSize(details.getSize()).gcsObjectContentType(details.getContentType()).build();
if (!details.getAtlanTags().isEmpty()) {
toClassifyGCS.put(gcs.getQualifiedName(), details.getAtlanTags());
}
parents.add(parentQN);
localCount++;
if (batch.add(gcs) != null) {
log.info(" ... processed {}/{} ({}%)", localCount, totalResults, Math.round(((double) localCount / totalResults) * 100));
}
}
break;
case ADLS:
if (updateOnly) {
String qualifiedName = ADLSObject.generateQualifiedName(objectName, parentQN);
try {
ADLSObject.get(Atlan.getDefaultClient(), qualifiedName, false);
ADLSObject toUpdate = ADLSObject.updater(qualifiedName, objectName).description(details.getDescription()).certificateStatus(details.getCertificate()).certificateStatusMessage(details.getCertificateStatusMessage()).announcementType(details.getAnnouncementType()).announcementTitle(details.getAnnouncementTitle()).announcementMessage(details.getAnnouncementMessage()).ownerUsers(details.getOwnerUsers()).ownerGroups(details.getOwnerGroups()).adlsObjectUrl(details.getPath()).adlsObjectSize(details.getSize()).adlsObjectContentType(details.getContentType()).build();
if (!details.getAtlanTags().isEmpty()) {
toClassifyADLS.put(toUpdate.getQualifiedName(), details.getAtlanTags());
}
parents.add(parentQN);
localCount++;
if (batch.add(toUpdate) != null) {
log.info(" ... processed {}/{} ({}%)", localCount, totalResults, Math.round(((double) localCount / totalResults) * 100));
}
} catch (NotFoundException e) {
log.warn("Unable to find existing object — skipping: {}", qualifiedName, e);
} catch (AtlanException e) {
log.error("Unable to lookup whether object exists or not.", e);
}
} else {
ADLSObject adls = ADLSObject.creator(objectName, parentQN).description(details.getDescription()).certificateStatus(details.getCertificate()).certificateStatusMessage(details.getCertificateStatusMessage()).announcementType(details.getAnnouncementType()).announcementTitle(details.getAnnouncementTitle()).announcementMessage(details.getAnnouncementMessage()).ownerUsers(details.getOwnerUsers()).ownerGroups(details.getOwnerGroups()).adlsObjectUrl(details.getPath()).adlsObjectSize(details.getSize()).adlsObjectContentType(details.getContentType()).build();
if (!details.getAtlanTags().isEmpty()) {
toClassifyADLS.put(adls.getQualifiedName(), details.getAtlanTags());
}
parents.add(parentQN);
localCount++;
if (batch.add(adls) != null) {
log.info(" ... processed {}/{} ({}%)", localCount, totalResults, Math.round(((double) localCount / totalResults) * 100));
}
}
break;
default:
log.error("Invalid object type ({}) — skipping: {}", objectType, details);
break;
}
}
// And don't forget to flush out any that remain
if (batch.flush() != null) {
log.info(" ... processed {}/{} ({}%)", localCount, totalResults, Math.round(((double) localCount / totalResults) * 100));
}
} catch (AtlanException e) {
log.error("Unable to bulk-upsert object details.", e);
}
// Classifications must be added in a second pass, after the asset exists
appendAtlanTags(toClassifyS3, S3Object.TYPE_NAME);
appendAtlanTags(toClassifyGCS, GCSObject.TYPE_NAME);
appendAtlanTags(toClassifyADLS, ADLSObject.TYPE_NAME);
return parents;
}
@java.lang.SuppressWarnings("all")
public static abstract class ObjectDetailsBuilder> extends AssetDetails.AssetDetailsBuilder {
@java.lang.SuppressWarnings("all")
private String connectionQualifiedName;
@java.lang.SuppressWarnings("all")
private String containerQualifiedName;
@java.lang.SuppressWarnings("all")
private String bucketName;
@java.lang.SuppressWarnings("all")
private String name;
@java.lang.SuppressWarnings("all")
private String arn;
@java.lang.SuppressWarnings("all")
private String path;
@java.lang.SuppressWarnings("all")
private Long size;
@java.lang.SuppressWarnings("all")
private String contentType;
@java.lang.Override
@java.lang.SuppressWarnings("all")
protected abstract B self();
@java.lang.Override
@java.lang.SuppressWarnings("all")
public abstract C build();
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B connectionQualifiedName(final String connectionQualifiedName) {
this.connectionQualifiedName = connectionQualifiedName;
return self();
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B containerQualifiedName(final String containerQualifiedName) {
this.containerQualifiedName = containerQualifiedName;
return self();
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B bucketName(final String bucketName) {
this.bucketName = bucketName;
return self();
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B name(final String name) {
this.name = name;
return self();
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B arn(final String arn) {
this.arn = arn;
return self();
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B path(final String path) {
this.path = path;
return self();
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B size(final Long size) {
this.size = size;
return self();
}
/**
* @return {@code this}.
*/
@java.lang.SuppressWarnings("all")
public B contentType(final String contentType) {
this.contentType = contentType;
return self();
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "ObjectDetails.ObjectDetailsBuilder(super=" + super.toString() + ", connectionQualifiedName=" + this.connectionQualifiedName + ", containerQualifiedName=" + this.containerQualifiedName + ", bucketName=" + this.bucketName + ", name=" + this.name + ", arn=" + this.arn + ", path=" + this.path + ", size=" + this.size + ", contentType=" + this.contentType + ")";
}
}
@java.lang.SuppressWarnings("all")
private static final class ObjectDetailsBuilderImpl extends ObjectDetails.ObjectDetailsBuilder {
@java.lang.SuppressWarnings("all")
private ObjectDetailsBuilderImpl() {
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
protected ObjectDetails.ObjectDetailsBuilderImpl self() {
return this;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public ObjectDetails build() {
return new ObjectDetails(this);
}
}
@java.lang.SuppressWarnings("all")
protected ObjectDetails(final ObjectDetails.ObjectDetailsBuilder b) {
super(b);
this.connectionQualifiedName = b.connectionQualifiedName;
this.containerQualifiedName = b.containerQualifiedName;
this.bucketName = b.bucketName;
this.name = b.name;
this.arn = b.arn;
this.path = b.path;
this.size = b.size;
this.contentType = b.contentType;
}
@java.lang.SuppressWarnings("all")
public static ObjectDetails.ObjectDetailsBuilder builder() {
return new ObjectDetails.ObjectDetailsBuilderImpl();
}
@java.lang.SuppressWarnings("all")
public String getConnectionQualifiedName() {
return this.connectionQualifiedName;
}
@java.lang.SuppressWarnings("all")
public String getContainerQualifiedName() {
return this.containerQualifiedName;
}
@java.lang.SuppressWarnings("all")
public String getBucketName() {
return this.bucketName;
}
@java.lang.SuppressWarnings("all")
public String getName() {
return this.name;
}
@java.lang.SuppressWarnings("all")
public String getArn() {
return this.arn;
}
@java.lang.SuppressWarnings("all")
public String getPath() {
return this.path;
}
@java.lang.SuppressWarnings("all")
public Long getSize() {
return this.size;
}
@java.lang.SuppressWarnings("all")
public String getContentType() {
return this.contentType;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public boolean equals(final java.lang.Object o) {
if (o == this) return true;
if (!(o instanceof ObjectDetails)) return false;
final ObjectDetails other = (ObjectDetails) o;
if (!other.canEqual((java.lang.Object) this)) return false;
final java.lang.Object this$size = this.getSize();
final java.lang.Object other$size = other.getSize();
if (this$size == null ? other$size != null : !this$size.equals(other$size)) return false;
final java.lang.Object this$connectionQualifiedName = this.getConnectionQualifiedName();
final java.lang.Object other$connectionQualifiedName = other.getConnectionQualifiedName();
if (this$connectionQualifiedName == null ? other$connectionQualifiedName != null : !this$connectionQualifiedName.equals(other$connectionQualifiedName)) return false;
final java.lang.Object this$containerQualifiedName = this.getContainerQualifiedName();
final java.lang.Object other$containerQualifiedName = other.getContainerQualifiedName();
if (this$containerQualifiedName == null ? other$containerQualifiedName != null : !this$containerQualifiedName.equals(other$containerQualifiedName)) return false;
final java.lang.Object this$bucketName = this.getBucketName();
final java.lang.Object other$bucketName = other.getBucketName();
if (this$bucketName == null ? other$bucketName != null : !this$bucketName.equals(other$bucketName)) return false;
final java.lang.Object this$name = this.getName();
final java.lang.Object other$name = other.getName();
if (this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
final java.lang.Object this$arn = this.getArn();
final java.lang.Object other$arn = other.getArn();
if (this$arn == null ? other$arn != null : !this$arn.equals(other$arn)) return false;
final java.lang.Object this$path = this.getPath();
final java.lang.Object other$path = other.getPath();
if (this$path == null ? other$path != null : !this$path.equals(other$path)) return false;
final java.lang.Object this$contentType = this.getContentType();
final java.lang.Object other$contentType = other.getContentType();
if (this$contentType == null ? other$contentType != null : !this$contentType.equals(other$contentType)) return false;
return true;
}
@java.lang.SuppressWarnings("all")
protected boolean canEqual(final java.lang.Object other) {
return other instanceof ObjectDetails;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public int hashCode() {
final int PRIME = 59;
int result = 1;
final java.lang.Object $size = this.getSize();
result = result * PRIME + ($size == null ? 43 : $size.hashCode());
final java.lang.Object $connectionQualifiedName = this.getConnectionQualifiedName();
result = result * PRIME + ($connectionQualifiedName == null ? 43 : $connectionQualifiedName.hashCode());
final java.lang.Object $containerQualifiedName = this.getContainerQualifiedName();
result = result * PRIME + ($containerQualifiedName == null ? 43 : $containerQualifiedName.hashCode());
final java.lang.Object $bucketName = this.getBucketName();
result = result * PRIME + ($bucketName == null ? 43 : $bucketName.hashCode());
final java.lang.Object $name = this.getName();
result = result * PRIME + ($name == null ? 43 : $name.hashCode());
final java.lang.Object $arn = this.getArn();
result = result * PRIME + ($arn == null ? 43 : $arn.hashCode());
final java.lang.Object $path = this.getPath();
result = result * PRIME + ($path == null ? 43 : $path.hashCode());
final java.lang.Object $contentType = this.getContentType();
result = result * PRIME + ($contentType == null ? 43 : $contentType.hashCode());
return result;
}
@java.lang.Override
@java.lang.SuppressWarnings("all")
public java.lang.String toString() {
return "ObjectDetails(super=" + super.toString() + ", connectionQualifiedName=" + this.getConnectionQualifiedName() + ", containerQualifiedName=" + this.getContainerQualifiedName() + ", bucketName=" + this.getBucketName() + ", name=" + this.getName() + ", arn=" + this.getArn() + ", path=" + this.getPath() + ", size=" + this.getSize() + ", contentType=" + this.getContentType() + ")";
}
}