-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Importing Resource Container from Zip File (#423)
* Refactor to support loading of zip RC's. No Tree support yet. * Creation of OtterTree from zip file works, several issues remain 1. Collection slugs are incorrect 2. chapters, verses, and body/notes are being put into the tree backwards * Polished and moved ZipEntryTreeBuilder to new package * Update CollectionRepository.kt * Two menu options to import from zip or folder * PR Comment * Update travis.yml to clone dev branch of kotlin-resource-container instead of master * Use ResourceContainer's new autoclose feature. * Corrected mispelled package name * PR Comment- categories and versification * PR Comments- mispelling and categories and versification
- Loading branch information
Showing
8 changed files
with
152 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../org/wycliffeassociates/otter/jvm/domain/resourcecontainer/project/ZipEntryTreeBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.wycliffeassociates.otter.jvm.domain.resourcecontainer.project | ||
|
||
import org.wycliffeassociates.otter.common.collections.tree.OtterTree | ||
import org.wycliffeassociates.otter.common.collections.tree.OtterTreeNode | ||
import org.wycliffeassociates.otter.common.domain.resourcecontainer.project.IZipEntryTreeBuilder | ||
import org.wycliffeassociates.otter.common.domain.resourcecontainer.project.OtterFile | ||
import org.wycliffeassociates.otter.common.domain.resourcecontainer.project.OtterZipFile.Companion.otterFileZ | ||
import java.io.IOException | ||
import java.nio.file.attribute.BasicFileAttributes | ||
import java.nio.file.Files | ||
import java.nio.file.SimpleFileVisitor | ||
import java.nio.file.FileSystem | ||
import java.nio.file.Paths | ||
import java.nio.file.Path | ||
import java.nio.file.FileSystems | ||
import java.nio.file.FileVisitResult | ||
import java.util.zip.ZipFile | ||
import java.util.ArrayDeque | ||
|
||
object ZipEntryTreeBuilder : IZipEntryTreeBuilder { | ||
|
||
private fun createZipFileSystem(zipFilename: String): FileSystem { | ||
val path = Paths.get(zipFilename) | ||
return FileSystems.newFileSystem(path, null) | ||
} | ||
|
||
override fun buildOtterFileTree(zipFile: ZipFile, projectPath: String): OtterTree<OtterFile> { | ||
var treeRoot: OtterTree<OtterFile>? = null | ||
val treeCursor = ArrayDeque<OtterTree<OtterFile>>() | ||
createZipFileSystem(zipFile.name).use { zipFileSystem -> | ||
|
||
val projectRoot = zipFileSystem.getPath(projectPath) | ||
val sep = zipFileSystem.separator | ||
|
||
Files.walkFileTree(projectRoot, object : SimpleFileVisitor<Path>() { | ||
@Throws(IOException::class) | ||
override fun visitFile(file: Path, | ||
attrs: BasicFileAttributes): FileVisitResult { | ||
val filepath = file.toString().substringAfter(sep) | ||
val entry = zipFile.getEntry(filepath) | ||
val otterZipFile = otterFileZ(filepath, zipFile, sep, treeCursor.peek()?.value, entry) | ||
treeCursor.peek()?.addChild(OtterTreeNode(otterZipFile)) | ||
return FileVisitResult.CONTINUE | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun postVisitDirectory(dir: Path?, exc: IOException?): FileVisitResult { | ||
treeRoot = treeCursor.pop() | ||
return FileVisitResult.CONTINUE | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun preVisitDirectory(dir: Path, | ||
attrs: BasicFileAttributes): FileVisitResult { | ||
val newDirNode = OtterTree( | ||
otterFileZ(dir.toString(), zipFile, zipFileSystem.separator, treeCursor.peek()?.value) | ||
) | ||
treeCursor.peek()?.addChild(newDirNode) | ||
treeCursor.push(newDirNode) | ||
return FileVisitResult.CONTINUE | ||
} | ||
}) | ||
return treeRoot ?: OtterTree(otterFileZ(zipFile.name, zipFile, zipFileSystem.separator)) | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters