From 69863072513e898e78c4d53fb354ab1c32a12bdd Mon Sep 17 00:00:00 2001 From: Rustam Date: Mon, 18 Mar 2024 22:53:12 +0100 Subject: [PATCH] Add `name` property to AdditionalProblemProperties on backend --- .../polybacs/api/AdditionalProblemProperties.kt | 10 +++------- .../github/jvmusin/polybacs/bacs/BacsArchiveService.kt | 4 ++-- .../jvmusin/polybacs/server/SolutionsController.kt | 5 +++-- .../jvmusin/polybacs/sybon/SybonArchiveBuilder.kt | 5 ++--- .../polybacs/sybon/SybonSpecialCollectionTests.kt | 5 +++-- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/io/github/jvmusin/polybacs/api/AdditionalProblemProperties.kt b/src/main/kotlin/io/github/jvmusin/polybacs/api/AdditionalProblemProperties.kt index e0fa673..4b2c599 100644 --- a/src/main/kotlin/io/github/jvmusin/polybacs/api/AdditionalProblemProperties.kt +++ b/src/main/kotlin/io/github/jvmusin/polybacs/api/AdditionalProblemProperties.kt @@ -14,17 +14,13 @@ import io.github.jvmusin.polybacs.api.StatementFormat.PDF * @param statementFormat format of the statement, actually `PDF` or `HTML`. */ data class AdditionalProblemProperties( - val prefix: String? = null, + val name: String, + val prefix: String? = null, // TODO: Drop nullability; drop whole concept? val suffix: String? = null, val timeLimitMillis: Int? = null, val memoryLimitMegabytes: Int? = null, val statementFormat: StatementFormat = PDF ) { - companion object { - /** Do not add any prefix/suffix and use problem's default time and memory limits. */ - val defaultProperties = AdditionalProblemProperties() - } - /** Build problem name prefixing it with [prefix] and suffixing with [suffix] if they are not `null`. */ - fun buildFullName(problemName: String) = "${prefix.orEmpty()}$problemName${suffix.orEmpty()}" + fun buildFullName() = "${prefix.orEmpty()}$name${suffix.orEmpty()}" } diff --git a/src/main/kotlin/io/github/jvmusin/polybacs/bacs/BacsArchiveService.kt b/src/main/kotlin/io/github/jvmusin/polybacs/bacs/BacsArchiveService.kt index d60a147..57e3fd4 100644 --- a/src/main/kotlin/io/github/jvmusin/polybacs/bacs/BacsArchiveService.kt +++ b/src/main/kotlin/io/github/jvmusin/polybacs/bacs/BacsArchiveService.kt @@ -127,11 +127,11 @@ class BacsArchiveService( /** Uploads [problem] to Bacs archive with extra [properties]. */ suspend fun uploadProblem( problem: IRProblem, - properties: AdditionalProblemProperties = AdditionalProblemProperties.defaultProperties, + properties: AdditionalProblemProperties = AdditionalProblemProperties(problem.name), ): String { val zip = problem.toZipArchive(properties) uploadProblem(zip) - val fullName = properties.buildFullName(problem.name) + val fullName = properties.buildFullName() val state = waitTillProblemIsImported(fullName) if (state != BacsProblemState.IMPORTED) throw BacsProblemUploadException("Задача $fullName не импортирована, статус $state") diff --git a/src/main/kotlin/io/github/jvmusin/polybacs/server/SolutionsController.kt b/src/main/kotlin/io/github/jvmusin/polybacs/server/SolutionsController.kt index 12f6d59..38a188b 100644 --- a/src/main/kotlin/io/github/jvmusin/polybacs/server/SolutionsController.kt +++ b/src/main/kotlin/io/github/jvmusin/polybacs/server/SolutionsController.kt @@ -48,8 +48,9 @@ class SolutionsController( @RequestMapping("/createTestProblem") fun createTestProblem(@PathVariable problemId: Int, session: HttpSession) = offloadScope.launch(exceptionHandler("create test problem", session)) { - val properties = AdditionalProblemProperties(suffix = "-test") - val fullName = properties.buildFullName(polygonService.downloadProblem(problemId).name) + val problemName = polygonService.downloadProblem(problemId).name + val properties = AdditionalProblemProperties(name = problemName, suffix = "-test") + val fullName = properties.buildFullName() val toastSender = webSocketConnectionKeeper.createSender(session.id) transferProblemToBacs(toastSender, problemId, properties, false, polygonService, bacsArchiveService) diff --git a/src/main/kotlin/io/github/jvmusin/polybacs/sybon/SybonArchiveBuilder.kt b/src/main/kotlin/io/github/jvmusin/polybacs/sybon/SybonArchiveBuilder.kt index 095b51a..3c74990 100644 --- a/src/main/kotlin/io/github/jvmusin/polybacs/sybon/SybonArchiveBuilder.kt +++ b/src/main/kotlin/io/github/jvmusin/polybacs/sybon/SybonArchiveBuilder.kt @@ -1,7 +1,6 @@ package io.github.jvmusin.polybacs.sybon import io.github.jvmusin.polybacs.api.AdditionalProblemProperties -import io.github.jvmusin.polybacs.api.AdditionalProblemProperties.Companion.defaultProperties import io.github.jvmusin.polybacs.ir.IRProblem import io.github.jvmusin.polybacs.util.toZipArchive import java.nio.file.Path @@ -16,8 +15,8 @@ import kotlin.io.path.writeText * * @return file where the zip is located. */ -fun IRProblem.toZipArchive(properties: AdditionalProblemProperties = defaultProperties): Path { - val fullName = properties.buildFullName(name) +fun IRProblem.toZipArchive(properties: AdditionalProblemProperties = AdditionalProblemProperties(name)): Path { + val fullName = properties.buildFullName() val destinationPath = Paths.get( "sybon-packages", "$fullName-${UUID.randomUUID()}", diff --git a/src/test/kotlin/io/github/jvmusin/polybacs/sybon/SybonSpecialCollectionTests.kt b/src/test/kotlin/io/github/jvmusin/polybacs/sybon/SybonSpecialCollectionTests.kt index 19e37cb..c39730b 100644 --- a/src/test/kotlin/io/github/jvmusin/polybacs/sybon/SybonSpecialCollectionTests.kt +++ b/src/test/kotlin/io/github/jvmusin/polybacs/sybon/SybonSpecialCollectionTests.kt @@ -23,7 +23,8 @@ class SybonSpecialCollectionTests( ) : StringSpec({ val specialCollectionId = 10023 val polygonProblemId = 147360 - val properties = AdditionalProblemProperties( + fun properties(problemName: String) = AdditionalProblemProperties( + name = problemName, suffix = LocalDateTime.now().format( DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss") ) + "-polybacs-test-rustam" @@ -31,7 +32,7 @@ class SybonSpecialCollectionTests( "Full cycle" { val irProblem = polygonService.downloadProblem(polygonProblemId, includeTests = true) - val fullName = bacsArchiveService.uploadProblem(irProblem, properties) + val fullName = bacsArchiveService.uploadProblem(irProblem, properties(irProblem.name)) println("Problem full name: $fullName") delay(2.minutes) // wait for the problem to appear in the archive val sybonProblemId = repeat(3.minutes, 10.seconds) {