From 7a51b858762a9dc2f3933739a901ba909dab08bd Mon Sep 17 00:00:00 2001 From: mikrise2 <56760252+mikrise2@users.noreply.github.com> Date: Wed, 13 Mar 2024 16:43:06 +0100 Subject: [PATCH] Log filepath (#99) * Added unique index keys * changed insert statement, changed request behaviour * deleted indexes * [ML4SE-515] Log a path in the project to the file in DocumentLoggedData * [ML4SE-515] fix server address * [ML4SE-515] fix log files saving path --- .../tracking/TaskDocumentListener.kt | 5 ++-- .../tasktracker/tracking/TaskFileHandler.kt | 25 +++++++++++-------- .../tracking/logger/DocumentLogPrinter.kt | 15 +++++------ .../tracking/logger/DocumentLogger.kt | 11 ++++---- .../tasktracker/tracking/logger/LoggedData.kt | 12 +++++++-- .../ui/main/panel/MainPluginPanelFactory.kt | 1 + .../tracking/TaskDocumentListenerTest.kt | 4 +-- .../tracking/TaskFileHandlerTest.kt | 2 ++ .../tasktracker/database/DatabaseFactory.kt | 2 +- .../database/models/data/ActivityData.kt | 14 +++++------ .../database/models/data/DataTable.kt | 10 ++++---- .../database/models/data/DocumentData.kt | 16 ++++++------ .../database/models/data/FileEditorData.kt | 10 ++++---- .../database/models/data/SurveyData.kt | 12 ++++----- .../database/models/data/ToolWindowData.kt | 8 +++--- .../database/models/data/WebCamData.kt | 10 ++++---- .../plugins/requests/FileRequests.kt | 5 +++- 17 files changed, 91 insertions(+), 71 deletions(-) diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListener.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListener.kt index 266d5cba..8b711a87 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListener.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListener.kt @@ -3,10 +3,11 @@ package org.jetbrains.research.tasktracker.tracking import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.event.DocumentEvent import com.intellij.openapi.editor.event.DocumentListener +import com.intellij.openapi.project.Project import org.jetbrains.research.tasktracker.config.MainTaskTrackerConfig import org.jetbrains.research.tasktracker.tracking.logger.DocumentLogger -class TaskDocumentListener : DocumentListener { +class TaskDocumentListener(val project: Project) : DocumentListener { private val logger: Logger = Logger.getInstance(javaClass) init { @@ -15,6 +16,6 @@ class TaskDocumentListener : DocumentListener { // Tracking documents changes before to be consistent with activity-tracker plugin override fun beforeDocumentChange(event: DocumentEvent) { - DocumentLogger.log(event.document) + DocumentLogger.log(project, event.document) } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt index 67d30b8f..94609740 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/TaskFileHandler.kt @@ -2,6 +2,7 @@ package org.jetbrains.research.tasktracker.tracking import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.editor.event.DocumentListener import com.intellij.openapi.fileEditor.FileDocumentManager import com.intellij.openapi.module.Module import com.intellij.openapi.module.ModuleManager @@ -25,23 +26,25 @@ import java.io.File typealias ProjectTaskFileMap = MutableMap>> typealias ProjectTaskIdFile = MutableMap>> -@Suppress("UnusedPrivateMember") +@Suppress("UnusedPrivateMember", "TooManyFunctions") object TaskFileHandler { private val logger: Logger = Logger.getInstance(TaskFileHandler.javaClass) - private val listener by lazy { TaskDocumentListener() } + private var listener: DocumentListener? = null private val projectTaskIdToFile: ProjectTaskIdFile = HashMap() val projectToTaskToFiles: ProjectTaskFileMap = HashMap() fun initProject(project: Project) { - TODO() + listener = TaskDocumentListener(project) } + private fun getListener() = listener ?: error("Listener is not define") + fun initTask(project: Project, task: Task) { projectTaskIdToFile.putIfAbsent(project, mutableMapOf()) projectTaskIdToFile[project]?.putIfAbsent(task, mutableMapOf()) getOrCreateFiles(project, task).forEach { file -> file?.let { - addVirtualFileListener(it) + addVirtualFileListener(project, it) projectToTaskToFiles.putIfAbsent(project, mutableMapOf()) projectToTaskToFiles[project]?.putIfAbsent(task, mutableListOf()) projectToTaskToFiles[project]?.get(task)?.add(it) @@ -52,7 +55,7 @@ object TaskFileHandler { // TODO not forget to remove from document loggers hashmap, flush data fun disposeTask(project: Project, task: Task) { projectToTaskToFiles[project]?.let { - it[task]?.let { virtualFiles -> removeVirtualFileListener(virtualFiles) } + it[task]?.let { virtualFiles -> removeVirtualFileListener(project, virtualFiles) } ?: logger.warn("attempt to dispose a uninitialized task: '$task'") it.remove(task) projectTaskIdToFile[project]?.remove(task) @@ -63,24 +66,24 @@ object TaskFileHandler { } ?: logger.warn("attempt to dispose task: '$task' from uninitialized project: '$project'") } - private fun addVirtualFileListener(virtualFile: VirtualFile) { + private fun addVirtualFileListener(project: Project, virtualFile: VirtualFile) { ApplicationManager.getApplication().invokeAndWait { val document = FileDocumentManager.getInstance().getDocument(virtualFile) document?.let { - it.addDocumentListener(listener) + it.addDocumentListener(getListener()) // Log the first state - DocumentLogger.log(it) + DocumentLogger.log(project, it) } ?: logger.warn("attempt to add listener for non-existing document: '$document'") } } - private fun removeVirtualFileListener(virtualFiles: List) { + private fun removeVirtualFileListener(project: Project, virtualFiles: List) { virtualFiles.forEach { file -> ApplicationManager.getApplication().invokeAndWait { val document = FileDocumentManager.getInstance().getDocument(file) document?.let { - DocumentLogger.removeDocumentLogPrinter(document) - document.removeDocumentListener(listener) + DocumentLogger.removeDocumentLogPrinter(project, document) + document.removeDocumentListener(getListener()) } } } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt index e14e7e9b..2b4714bb 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogPrinter.kt @@ -3,6 +3,7 @@ package org.jetbrains.research.tasktracker.tracking.logger import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.Document import com.intellij.openapi.fileEditor.FileDocumentManager +import com.intellij.openapi.project.Project import com.intellij.openapi.util.io.FileUtil import org.apache.commons.csv.CSVFormat import org.apache.commons.csv.CSVPrinter @@ -25,27 +26,27 @@ class DocumentLogPrinter { /** * Gets the active logPrinter or creates a new one if there was none or the active one was full */ - fun getActiveLogPrinter(document: Document): LogPrinter { - val activePrinter = getLastPrinter(document) + fun getActiveLogPrinter(project: Project, document: Document): LogPrinter { + val activePrinter = getLastPrinter(project, document) return if (activePrinter.isFull()) { - addLogPrinter(document) + addLogPrinter(project, document) } else { activePrinter } } - private fun getLastPrinter(document: Document) = if (logPrinters.isEmpty()) { - addLogPrinter(document) + private fun getLastPrinter(project: Project, document: Document) = if (logPrinters.isEmpty()) { + addLogPrinter(project, document) } else { logPrinters.last() } - private fun addLogPrinter(document: Document): LogPrinter { + private fun addLogPrinter(project: Project, document: Document): LogPrinter { logger.info("${MainTaskTrackerConfig.PLUGIN_NAME}: init printer") val logFile = createLogFile(document) val fileWriter = OutputStreamWriter(FileOutputStream(logFile), StandardCharsets.UTF_8) val csvPrinter = CSVPrinter(fileWriter, CSVFormat.DEFAULT) - csvPrinter.printRecord(DocumentLoggedData.headers) + csvPrinter.printRecord(DocumentLoggedData(project).headers) logPrinters.add(LogPrinter(csvPrinter, fileWriter, logFile)) return logPrinters.last() } diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt index 0916b83f..ec5cc545 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/DocumentLogger.kt @@ -2,6 +2,7 @@ package org.jetbrains.research.tasktracker.tracking.logger import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.editor.Document +import com.intellij.openapi.project.Project import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import org.jetbrains.research.tasktracker.requests.FileRequests @@ -11,16 +12,16 @@ object DocumentLogger { private val myDocumentsToPrinters: HashMap = HashMap() private val logger: Logger = Logger.getInstance(DocumentLogger.javaClass) - fun log(document: Document) { + fun log(project: Project, document: Document) { val docPrinter = myDocumentsToPrinters.getOrPut(document) { DocumentLogPrinter() } - val logPrinter = docPrinter.getActiveLogPrinter(document) - logPrinter.csvPrinter.printRecord(DocumentLoggedData.getData(document)) + val logPrinter = docPrinter.getActiveLogPrinter(project, document) + logPrinter.csvPrinter.printRecord(DocumentLoggedData(project).getData(document)) } fun getDocumentLogPrinter(document: Document): DocumentLogPrinter? = myDocumentsToPrinters[document] - fun removeDocumentLogPrinter(document: Document) { - log(document) + fun removeDocumentLogPrinter(project: Project, document: Document) { + log(project, document) val logFiles: List = getDocumentLogPrinter(document)?.getLogFiles() ?: emptyList().also { logger.error("attempt to flush non-existing csv printer for document '$document'") diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/LoggedData.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/LoggedData.kt index cc15f424..3e316110 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/LoggedData.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/tracking/logger/LoggedData.kt @@ -2,6 +2,7 @@ package org.jetbrains.research.tasktracker.tracking.logger import com.intellij.openapi.editor.Document import com.intellij.openapi.fileEditor.FileDocumentManager +import com.intellij.openapi.project.Project import org.jetbrains.research.tasktracker.TaskTrackerPlugin import org.jetbrains.research.tasktracker.tracking.activity.ActivityEvent import org.jetbrains.research.tasktracker.tracking.fileEditor.FileEditorData @@ -9,6 +10,7 @@ import org.jetbrains.research.tasktracker.tracking.toolWindow.ToolWindowData import org.jetbrains.research.tasktracker.tracking.webcam.WebCamData import org.jetbrains.research.tasktracker.util.survey.SurveyData import org.joda.time.DateTime +import kotlin.io.path.Path data class LoggedDataGetter(val header: String, val getData: (T) -> S) @@ -23,11 +25,17 @@ abstract class LoggedData { } } -object DocumentLoggedData : LoggedData() { +class DocumentLoggedData(project: Project) : LoggedData() { override val loggedDataGetters: List> = arrayListOf( LoggedDataGetter("date") { DateTime.now().toString() }, LoggedDataGetter("timestamp") { it.modificationStamp.toString() }, - LoggedDataGetter("filename") { FileDocumentManager.getInstance().getFile(it)?.name }, + LoggedDataGetter("filename") { + FileDocumentManager.getInstance().getFile(it)?.toNioPath()?.let { filepath -> + project.basePath?.let { projectPath -> + Path(projectPath).relativize(filepath) + } ?: filepath + }.toString() + }, LoggedDataGetter("file_hash_code") { FileDocumentManager.getInstance().getFile(it)?.hashCode().toString() }, LoggedDataGetter("document_hash_code") { it.hashCode().toString() }, LoggedDataGetter("fragment") { it.text }, diff --git a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt index 8858dd46..a2ad68f6 100644 --- a/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt +++ b/ij-plugin/src/main/kotlin/org/jetbrains/research/tasktracker/ui/main/panel/MainPluginPanelFactory.kt @@ -50,6 +50,7 @@ class MainPluginPanelFactory : ToolWindowFactory { lateinit var project: Project override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { + TaskFileHandler.initProject(project) TaskTrackerPlugin.initPlugin() this.project = project mainWindow = project.getService(MainWindowService::class.java).mainWindow diff --git a/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListenerTest.kt b/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListenerTest.kt index 540946ec..a4a7e8fc 100644 --- a/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListenerTest.kt +++ b/ij-plugin/src/test/kotlin/org/jetbrains/research/tasktracker/tracking/TaskDocumentListenerTest.kt @@ -22,7 +22,7 @@ class TaskDocumentListenerTest : CodeInsightFixtureTestCase index > 1 } @@ -46,7 +46,7 @@ class TaskDocumentListenerTest : CodeInsightFixtureTestCase>( } private fun testInitTasks(tasks: List) { + TaskFileHandler.initProject(project) assertNoThrowable { tasks.forEach { task -> TaskFileHandler.initTask(project, task) @@ -84,6 +85,7 @@ class TaskFileHandlerTest : CodeInsightFixtureTestCase>( } private fun testDisposeTasks(tasks: List) { + TaskFileHandler.initProject(project) tasks.forEach { task -> TaskFileHandler.initTask(project, task) } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt index a3212b99..3be824d0 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/DatabaseFactory.kt @@ -26,7 +26,7 @@ object DatabaseFactory { SurveyData, FileEditorData ).let { - SchemaUtils.create(tables = it) + SchemaUtils.createMissingTablesAndColumns(tables = it) } commit() } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt index b2b6da79..15e8e216 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ActivityData.kt @@ -1,6 +1,6 @@ package org.jetbrains.research.tasktracker.database.models.data -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.statements.UpdateBuilder /** * The table presenting all the activities that have occurred in the IDE. @@ -26,12 +26,12 @@ object ActivityData : DataTable() { /** * Activity ID as provided by the IDE. */ - val actionId = integer("action_id").nullable() + val actionId = integer("action_id").nullable().default(-1) - override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { - insertStatement[type] = iterator.next() - insertStatement[info] = iterator.next() - insertStatement[selectedText] = iterator.next() - insertStatement[actionId] = iterator.next().toIntOrNull() + override fun insertData(updateBuilder: UpdateBuilder<*>, iterator: Iterator, researchId: Int) { + updateBuilder[type] = iterator.next() + updateBuilder[info] = iterator.next() + updateBuilder[selectedText] = iterator.next() + updateBuilder[actionId] = iterator.next().toIntOrNull() } } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DataTable.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DataTable.kt index 05093917..d084eec9 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DataTable.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DataTable.kt @@ -2,18 +2,18 @@ package org.jetbrains.research.tasktracker.database.models.data import org.jetbrains.exposed.dao.id.EntityID import org.jetbrains.exposed.dao.id.IntIdTable -import org.jetbrains.exposed.sql.insert +import org.jetbrains.exposed.sql.insertIgnore import org.jetbrains.exposed.sql.javatime.timestampWithTimeZone -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.statements.UpdateBuilder import org.jetbrains.research.tasktracker.database.models.Researches import java.time.OffsetDateTime abstract class DataTable : IntIdTable() { - val researchId = reference("research_id", Researches).index() + val researchId = reference("research_id", Researches) val date = timestampWithTimeZone("date") protected abstract fun insertData( - insertStatement: InsertStatement, + updateBuilder: UpdateBuilder<*>, iterator: Iterator, researchId: Int ) @@ -22,7 +22,7 @@ abstract class DataTable : IntIdTable() { iterator: Iterator, researchId: Int, ) { - insert { + insertIgnore { it[this.researchId] = EntityID(researchId, Researches) it[date] = OffsetDateTime.parse(iterator.next()) insertData(it, iterator, researchId) diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt index 8c216931..198c8717 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/DocumentData.kt @@ -1,6 +1,6 @@ package org.jetbrains.research.tasktracker.database.models.data -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.statements.UpdateBuilder /** * The table represents information about changes to the file used in the research. @@ -17,12 +17,12 @@ object DocumentData : DataTable() { */ val testMode = text("test_mode") - override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { - insertStatement[timestamp] = iterator.next().toLong() - insertStatement[filename] = iterator.next() - insertStatement[fileHashCode] = iterator.next().toInt() - insertStatement[documentHashCode] = iterator.next().toInt() - insertStatement[fragment] = iterator.next() - insertStatement[testMode] = iterator.next() + override fun insertData(updateBuilder: UpdateBuilder<*>, iterator: Iterator, researchId: Int) { + updateBuilder[timestamp] = iterator.next().toLong() + updateBuilder[filename] = iterator.next() + updateBuilder[fileHashCode] = iterator.next().toInt() + updateBuilder[documentHashCode] = iterator.next().toInt() + updateBuilder[fragment] = iterator.next() + updateBuilder[testMode] = iterator.next() } } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt index a1665185..50e0dca4 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/FileEditorData.kt @@ -1,6 +1,6 @@ package org.jetbrains.research.tasktracker.database.models.data -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.statements.UpdateBuilder /** * @@ -22,9 +22,9 @@ object FileEditorData : DataTable() { */ val newFile = text("new_file").nullable() - override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { - insertStatement[action] = iterator.next() - insertStatement[oldFile] = iterator.next() - insertStatement[newFile] = iterator.next() + override fun insertData(updateBuilder: UpdateBuilder<*>, iterator: Iterator, researchId: Int) { + updateBuilder[action] = iterator.next() + updateBuilder[oldFile] = iterator.next() + updateBuilder[newFile] = iterator.next() } } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt index 702bb731..cf6e80c1 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/SurveyData.kt @@ -1,6 +1,6 @@ package org.jetbrains.research.tasktracker.database.models.data -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.statements.UpdateBuilder /** * The table represents information about a completed survey. @@ -19,10 +19,10 @@ object SurveyData : DataTable() { val option = text("option").nullable() val answer = text("answer") - override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { - insertStatement[questionId] = iterator.next().toInt() - insertStatement[question] = iterator.next() - insertStatement[option] = iterator.next() - insertStatement[answer] = iterator.next() + override fun insertData(updateBuilder: UpdateBuilder<*>, iterator: Iterator, researchId: Int) { + updateBuilder[questionId] = iterator.next().toInt() + updateBuilder[question] = iterator.next() + updateBuilder[option] = iterator.next() + updateBuilder[answer] = iterator.next() } } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ToolWindowData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ToolWindowData.kt index 794537b3..8727e772 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ToolWindowData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/ToolWindowData.kt @@ -1,6 +1,6 @@ package org.jetbrains.research.tasktracker.database.models.data -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.statements.UpdateBuilder /** * The table represents information about events with tool windows in IDE. @@ -17,8 +17,8 @@ object ToolWindowData : DataTable() { */ val activeWindow = text("active_window") - override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { - insertStatement[action] = iterator.next() - insertStatement[activeWindow] = iterator.next() + override fun insertData(updateBuilder: UpdateBuilder<*>, iterator: Iterator, researchId: Int) { + updateBuilder[action] = iterator.next() + updateBuilder[activeWindow] = iterator.next() } } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt index f48ef50a..6ca246ed 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/database/models/data/WebCamData.kt @@ -1,6 +1,6 @@ package org.jetbrains.research.tasktracker.database.models.data -import org.jetbrains.exposed.sql.statements.InsertStatement +import org.jetbrains.exposed.sql.statements.UpdateBuilder /** * The table represents information about emotions determined through photos. @@ -23,9 +23,9 @@ object WebCamData : DataTable() { */ val scores = text("scores") - override fun insertData(insertStatement: InsertStatement, iterator: Iterator, researchId: Int) { - insertStatement[emotionShown] = iterator.next() - insertStatement[isRegular] = iterator.next().toBoolean() - insertStatement[scores] = iterator.next() + override fun insertData(updateBuilder: UpdateBuilder<*>, iterator: Iterator, researchId: Int) { + updateBuilder[emotionShown] = iterator.next() + updateBuilder[isRegular] = iterator.next().toBoolean() + updateBuilder[scores] = iterator.next() } } diff --git a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/plugins/requests/FileRequests.kt b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/plugins/requests/FileRequests.kt index 87bcec32..7da1ffc4 100644 --- a/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/plugins/requests/FileRequests.kt +++ b/ij-server/src/main/kotlin/org/jetbrains/research/tasktracker/plugins/requests/FileRequests.kt @@ -6,6 +6,7 @@ import io.ktor.server.plugins.* import io.ktor.server.response.* import io.ktor.server.routing.* import io.ktor.server.util.* +import kotlinx.coroutines.launch import org.jetbrains.research.tasktracker.util.createLogFile import org.jetbrains.research.tasktracker.util.logFile.parseLogFile @@ -19,8 +20,10 @@ fun Routing.uploadLogFile() { val logFileType = parameters["logFileType"] ?: DEFAULT_FOLDER val researchId = parameters.getOrFail("id") val logFile = createLogFile(logFileType, researchId) - logFile.parseLogFile(logFileType, researchId) call.respond(HttpStatusCode.OK) + launch { + logFile.parseLogFile(logFileType, researchId) + } } catch (e: MissingRequestParameterException) { call.respond(HttpStatusCode.BadRequest, e.localizedMessage) } catch (e: ParameterConversionException) {