Skip to content

Commit

Permalink
Check RepositoryEntity for null while getting upload sessions directo…
Browse files Browse the repository at this point in the history
…ry (#72)
  • Loading branch information
DominikWolek authored May 12, 2020
1 parent 374110b commit dae6759
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@ class FileUploadSessionRepository(
}

override fun findAll(): List<FileUploadSession> {
val directory = repositoryService.getEntity(pendingSessionsPath) as RepositoryDirectory

val ids = directory.getChildren()
.filterIsInstance<RepositoryDirectory>()
.flatMap { userFolder -> userFolder.getChildren()
.filterIsInstance<RepositoryDirectory>()
.map { getIdOfPath(Paths.get(it.relativePath)) } }
.toMutableList()

return findAllById(ids = ids)
return findAllById(ids = findAllIds().toMutableList())
}

override fun deleteById(id: Pair<Long, String>) {
Expand All @@ -69,8 +60,7 @@ class FileUploadSessionRepository(
}

override fun count(): Long {
val directory = repositoryService.getEntity(pendingSessionsPath) as RepositoryDirectory
return directory.getChildren().size.toLong()
return findAllIds().size.toLong()
}

override fun findAllById(ids: MutableIterable<Pair<Long, String>>): List<FileUploadSession> {
Expand Down Expand Up @@ -115,6 +105,22 @@ class FileUploadSessionRepository(
}
}

private fun findAllIds(): List<Pair<Long, String>> {
return when (val sessions = repositoryService.getEntity(pendingSessionsPath)) {
null -> emptyList()
else -> {
val sessionsDirectory = sessions as RepositoryDirectory
sessionsDirectory.getChildren()
.filterIsInstance<RepositoryDirectory>()
.flatMap { userFolder ->
userFolder.getChildren()
.filterIsInstance<RepositoryDirectory>()
.map { getIdOfPath(Paths.get(it.relativePath)) }
}
}
}
}

fun getPathOfId(id: Pair<Long, String>): String {
return "$pendingSessionsPath/${id.first}/${id.second}"
}
Expand Down

0 comments on commit dae6759

Please sign in to comment.