Skip to content

Commit

Permalink
Archives with raw COSV files should be at the top of the list (#2817)
Browse files Browse the repository at this point in the history
### What's done:
- added sorting of raw COSV files depending on whether the file is an archive.

Closes #2815
  • Loading branch information
DrAlexD authored Oct 27, 2023
1 parent 0de3877 commit d960424
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions save-cloud-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ kotlin {
implementation(libs.spring.boot)
implementation(libs.spring.data.jpa)
implementation(libs.jackson.module.kotlin)
implementation(libs.hibernate.core)
implementation(libs.hibernate.jpa21.api)
api(libs.slf4j.api)
api(libs.jetbrains.annotations)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ data class RawCosvFileDto(
*
* @return true if this raw cosv file is uploaded zip archive, checking by [fileName]
*/
fun RawCosvFileDto.isUploadedZipArchive(): Boolean = status == RawCosvFileStatus.UPLOADED && fileName.endsWith(ZIP_ARCHIVE_EXTENSION, ignoreCase = true)
fun RawCosvFileDto.isZipArchive(): Boolean = fileName.endsWith(ZIP_ARCHIVE_EXTENSION, ignoreCase = true)

/**
* Extracted as extension to avoid Jackson issue with encoding this field
*
* @return true if this raw cosv file is uploaded json file, checking by [fileName]
*/
fun RawCosvFileDto.isUploadedJsonFile(): Boolean = status == RawCosvFileStatus.UPLOADED && !fileName.endsWith(ZIP_ARCHIVE_EXTENSION, ignoreCase = true)
fun RawCosvFileDto.isUploadedJsonFile(): Boolean = !isZipArchive() && status == RawCosvFileStatus.UPLOADED

/**
* Extracted as extension to avoid Jackson issue with encoding this field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import com.saveourtool.save.entities.Organization
import com.saveourtool.save.entities.User
import com.saveourtool.save.spring.entity.BaseEntityWithDtoWithId
import com.saveourtool.save.spring.entity.IBaseEntityWithDate
import com.saveourtool.save.utils.ZIP_ARCHIVE_EXTENSION

import org.hibernate.annotations.Formula

import java.time.LocalDateTime
import javax.persistence.*
Expand All @@ -21,6 +24,7 @@ import kotlinx.datetime.toKotlinLocalDateTime
* @property contentLength
* @property createDate
* @property updateDate
* @property isZip
*/
@Entity
@Suppress("LongParameterList")
Expand All @@ -34,6 +38,8 @@ class RawCosvFile(
var organization: Organization,
@Enumerated(EnumType.STRING)
var status: RawCosvFileStatus,
@Formula("LOWER(file_name) LIKE '%_$ZIP_ARCHIVE_EXTENSION'")
var isZip: Boolean? = null,
var statusMessage: String? = null,
var contentLength: Long? = null,
override var createDate: LocalDateTime? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.saveourtool.save.v1
import org.reactivestreams.Publisher
import org.springframework.dao.DataIntegrityViolationException
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Sort
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
Expand Down Expand Up @@ -318,7 +319,7 @@ class RawCosvFileController(
authentication: Authentication,
): ResponseEntity<RawCosvFileDtoFlux> = hasPermission(authentication, organizationName, Permission.READ, "read")
.flatMap {
rawCosvFileStorage.listByOrganizationAndUser(organizationName, authentication.name, PageRequest.of(page, size))
rawCosvFileStorage.listByOrganizationAndUser(organizationName, authentication.name, PageRequest.of(page, size, Sort.by("isZip").descending().and(Sort.by("id"))))
}
.flatMapIterable { it }
.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isHasErrors
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isPendingRemoved
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isProcessing
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isUploadedJsonFile
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isUploadedZipArchive
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isZipArchive
import com.saveourtool.save.entities.cosv.RawCosvFileStatisticsDto
import com.saveourtool.save.entities.cosv.RawCosvFileStatus
import com.saveourtool.save.s3.S3Operations
Expand Down Expand Up @@ -79,7 +79,7 @@ class RawCosvFileStorage(
val filesList = s3KeyManager.listByOrganizationAndUser(organizationName, userName).toList()
RawCosvFileStatisticsDto(
filesList.count(),
filesList.count { it.isUploadedZipArchive() },
filesList.count { it.isZipArchive() },
filesList.count { it.isUploadedJsonFile() },
filesList.count { it.isProcessing() },
filesList.count { it.isPendingRemoved() },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isHasErrors
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isPendingRemoved
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isProcessing
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isUploadedJsonFile
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isUploadedZipArchive
import com.saveourtool.save.entities.cosv.RawCosvFileDto.Companion.isZipArchive
import com.saveourtool.save.entities.cosv.RawCosvFileStatisticsDto
import com.saveourtool.save.entities.cosv.RawCosvFileStreamingResponse
import com.saveourtool.save.frontend.components.basic.selectFormRequired
Expand Down Expand Up @@ -89,7 +89,7 @@ val cosvFileManagerComponent: FC<Props> = FC {
setAvailableFiles { it.minus(file) }
setStatistics { it.copy(allAvailableFilesCount = statistics.allAvailableFilesCount.dec()) }
when {
file.isUploadedZipArchive() -> setStatistics { it.copy(uploadedArchivesCount = statistics.uploadedArchivesCount.dec()) }
file.isZipArchive() -> setStatistics { it.copy(uploadedArchivesCount = statistics.uploadedArchivesCount.dec()) }
file.isUploadedJsonFile() -> setStatistics { it.copy(uploadedJsonFilesCount = statistics.uploadedJsonFilesCount.dec()) }
file.isProcessing() -> setStatistics { it.copy(processingFilesCount = statistics.processingFilesCount.dec()) }
file.isPendingRemoved() -> setStatistics { it.copy(pendingRemovedFilesCount = statistics.pendingRemovedFilesCount.dec()) }
Expand Down Expand Up @@ -385,11 +385,11 @@ val cosvFileManagerComponent: FC<Props> = FC {
availableFiles.map { file ->
li {
val highlightZipArchive = when {
file.isUploadedZipArchive() -> "font-weight-bold"
file.isZipArchive() -> "font-weight-bold"
else -> ""
}
val fileColor = when {
file.isUploadedZipArchive() -> "primary"
file.isZipArchive() -> "primary"
file.isUploadedJsonFile() -> "success"
file.isProcessing() -> "secondary"
file.isPendingRemoved() -> "light"
Expand All @@ -401,15 +401,15 @@ val cosvFileManagerComponent: FC<Props> = FC {
asDynamic()["data-toggle"] = "tooltip"
asDynamic()["data-placement"] = "left"
title = when {
file.isUploadedZipArchive() -> "It's a ZIP archive, please unzip to get JSON files"
file.isZipArchive() -> "It's a ZIP archive, please unzip to get JSON files"
file.isUploadedJsonFile() -> "It's a JSON file, you can submit it"
file.isProcessing() -> "In progress, please wait"
file.isPendingRemoved() -> "Already processed, will be deleted shortly"
file.isDuplicate() -> "Duplicate, the vulnerability with such ID already uploaded: ${file.statusMessage.orEmpty()}"
file.isHasErrors() -> "This JSON file has error: ${file.statusMessage.orEmpty()}"
else -> ""
}
if (file.isUploadedZipArchive()) {
if (file.isZipArchive()) {
button {
type = ButtonType.button
className = ClassName("btn")
Expand Down

0 comments on commit d960424

Please sign in to comment.