com.atlan.pkg.cab.DimensionImporter.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cube-assets-builder Show documentation
Show all versions of cube-assets-builder Show documentation
Atlan custom package for building cube assets
/* SPDX-License-Identifier: Apache-2.0
Copyright 2023 Atlan Pte. Ltd. */
package com.atlan.pkg.cab
import com.atlan.model.assets.Asset
import com.atlan.model.assets.CubeDimension
import com.atlan.model.enums.AssetCreationHandling
import com.atlan.model.fields.AtlanField
import com.atlan.pkg.serde.RowDeserializer
import mu.KotlinLogging
/**
* Import cube dimensions into Atlan from a provided CSV file.
*
* Only the cube dimensions and attributes in the provided CSV file will attempt to be loaded.
* By default, any blank values in a cell in the CSV file will be ignored. If you would like any
* particular column's blank values to actually overwrite (i.e. remove) existing values for that
* asset in Atlan, then add that column's field to getAttributesToOverwrite.
*
* @param preprocessed details of the preprocessed CSV file
* @param attrsToOverwrite list of fields that should be overwritten in Atlan, if their value is empty in the CSV
* @param creationHandling what to do with assets that do not exist (create full, partial, or ignore)
* @param batchSize maximum number of records to save per API request
* @param connectionImporter that was used to import connections
* @param trackBatches if true, minimal details about every asset created or updated is tracked (if false, only counts of each are tracked)
* @param fieldSeparator character to use to separate fields (for example ',' or ';')
*/
class DimensionImporter(
private val preprocessed: Importer.PreprocessedCsv,
private val attrsToOverwrite: List,
private val creationHandling: AssetCreationHandling,
private val batchSize: Int,
private val connectionImporter: ConnectionImporter,
trackBatches: Boolean,
fieldSeparator: Char,
) : AssetImporter(
preprocessed.preprocessedFile,
attrsToOverwrite,
creationHandling,
batchSize,
CubeDimension.TYPE_NAME,
KotlinLogging.logger {},
trackBatches,
fieldSeparator,
) {
/** {@inheritDoc} */
override fun getBuilder(deserializer: RowDeserializer): Asset.AssetBuilder<*, *> {
val name = deserializer.getValue(CubeDimension.CUBE_DIMENSION_NAME.atlanFieldName)?.let { it as String } ?: ""
val connectionQN = connectionImporter.getBuilder(deserializer).build().qualifiedName
val qnDetails = getQualifiedNameDetails(deserializer.row, deserializer.heading, typeNameFilter)
val cubeQN = "$connectionQN/${qnDetails.parentPartialQN}"
return CubeDimension.creator(name, cubeQN)
.cubeHierarchyCount(preprocessed.qualifiedNameToChildCount[qnDetails.uniqueQN]?.toLong())
}
}