Skip to content

Commit

Permalink
Merge pull request #1169 from atlanhq/FT-716
Browse files Browse the repository at this point in the history
Remove unused methods and simplify
  • Loading branch information
cmgrote authored Dec 23, 2024
2 parents b9f6520 + fad3b5e commit 97d7cfd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 54 deletions.
49 changes: 0 additions & 49 deletions package-toolkit/runtime/src/main/kotlin/com/atlan/pkg/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -864,33 +864,14 @@ object Utils {
(!directUpload && objectStoreKey.isNotBlank())
}

/**
* Get the file type of the provided file.
*
* @param importType details of the type of import expected (direct vs object store-based vs url)
* @param filePath details of the directly-provided file
* @return the type of the file
*/
fun getFileType(
importType: String,
filePath: String,
): String {
if (importType == "DIRECT" || importType == "URL") {
return filePath.substringAfterLast(".")
}
return ""
}

/**
* Unzip the provided zip file into the specified directory.
*
* @param importType details of the type of import expected (direct vs object store-based)
* @param zipFilePath path to the zip file to unzip
* @param destDirPath path to the directory where the files should be unzipped
* @return list of absolute paths of the unzipped files
*/
fun unzipFiles(
importType: String,
zipFilePath: String,
destDirPath: String,
): List<String> {
Expand Down Expand Up @@ -919,36 +900,6 @@ object Utils {
return destDir.listFiles()?.map { it.absolutePath } ?: emptyList()
}

/**
* Get the list of files in the provided directory.
*
* @param importType details of the type of import expected (direct vs object store-based)
* @param directory path to the directory to list files from
* @return list of absolute paths of files in the directory
*/
fun getFilesInDirectory(
importType: String,
directory: String,
): List<String> {
if (importType == "DIRECT") {
val path = Paths.get(directory)
val files = mutableListOf<String>()
if (path.isDirectory()) {
path.walk().forEach {
if (it.isRegularFile()) {
files.add(it.pathString)
}
}
} else {
files.add(directory)
}
return files
} else {
// return empty list for object store-based imports
return listOf()
}
}

/**
* Upload the provided output file to the object store defined by the credentials available.
* Note: if no credentials are provided, the default (in-tenant) object store will be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ object OpenAPISpecLoader {
}
}
for (sourceFile in sourceFiles) {
processFile(ctx, connectionQN, sourceFile, batchSize)
processFile(ctx, connectionQN, sourceFile, batchSize, outputDirectory)
}
}
}
Expand All @@ -87,18 +87,17 @@ object OpenAPISpecLoader {
connectionQN: String,
sourceFile: String,
batchSize: Int,
outputDirectory: String,
) {
val fileType = Utils.getFileType(ctx.config.importType, sourceFile)

val fileType = Paths.get(sourceFile).toFile().extension.lowercase()
when (fileType) {
"json" -> {
logger.info { "Loading OpenAPI specification from $sourceFile into: $connectionQN" }
loadOpenAPISpec(ctx.client, connectionQN, OpenAPISpecReader(sourceFile), batchSize)
}
"zip" -> {
logger.info { "Extracting and processing ZIP file: $sourceFile" }
val zipExtractPath = "tmp"
val extractedFiles = Utils.unzipFiles(ctx.config.importType, sourceFile, zipExtractPath)
val extractedFiles = Utils.unzipFiles(sourceFile, outputDirectory)
processExtractedFiles(ctx, connectionQN, extractedFiles, batchSize)
}
else -> {
Expand Down

0 comments on commit 97d7cfd

Please sign in to comment.