Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ class ChallengeController(
return true
}


private fun processUserSubmission(entity: ChallengeSubmissionEntity): Boolean {
if (entity.userName.isNotBlank() && entity.userName != "-") {
val id = entity.userName.split("|")[0].trim().toIntOrNull() ?: 0
val id = entity.userName.split("|")[1].trim().toIntOrNull() ?: 0
val user = transactionManager.transaction(readOnly = true) { users.findById(id) }

if (user.isPresent) {
Expand All @@ -141,4 +142,4 @@ class ChallengeController(
}

private fun mapUsername(it: UserEntity) =
"${it.id}| ${it.fullNameWithAlias} [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
"${it.fullNameWithAlias} | ${it.id} | [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class ProductGroupVirtualEntity (
@property:GenerateOverview(columnName = "Termék", order = 1)
var name: String = "",

@property:GenerateOverview(columnName = "Eladott mennyiség", order = 2, centered = true)
@property:GenerateOverview(columnName = "Eladott mennyiség", order = 2, centered = true, renderer = OverviewType.NUMBER)
var soldCount: Int = 0,

) : IdentifiableEntity
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,19 @@ class ResponsesController(
}

val objReader = objectMapper.readerFor(object : TypeReference<Map<String, Any>>() {})
val entries = formService.getResponsesById(id)
.map { objReader.readValue<Map<String, Any>>(it.submission) }
val responses = formService.getResponsesById(id)
val submissions = responses.map { objReader.readValue<Map<String, Any>>(it.submission) }
.map { it.values }
.toList()
val submitters = responses.map { listOf(it.submitterGroupId?:"", it.submitterGroupName, it.submitterUserId?:"", it.submitterUserName) }

val entries = submitters.zip(submissions) { a, b -> a + b }

val headers = objReader.readValue<Map<String, Any>>(formService.getResponsesById(id).firstOrNull()?.submission ?: "{}")
val header = objReader.readValue<Map<String, Any>>(formService.getResponsesById(id).firstOrNull()?.submission ?: "{}")
.keys
.joinToString(",")
val headers = "submitterGroupId,submitterGroupName,submitterUserId,submitterUserName,$header"

val result = CsvMapper().writeValueAsString(entries)
response.setHeader("Content-Disposition", "attachment; filename=\"form-${id}-responses.csv\"")
return headers + "\n" + result
Expand All @@ -149,7 +154,9 @@ class ResponsesController(
return "403"
}

val entries = formService.getResponsesById(id).joinToString(",") { it.submission }
val entries = formService.getResponsesById(id)
.map { "{submitterGroupId:${it.submitterGroupId},submitterGroupName:${it.submitterGroupName},submitterUserId:${it.submitterUserId},submitterUserName:${it.submitterUserName},submission:${it.submission}}" }
.joinToString(",") { it }

return "[${entries}]"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class FormVotesDto(
@property:GenerateOverview(columnName = "Űrlap neve", order = 1, useForSearch = true)
var name: String = "",

@property:GenerateOverview(columnName = "Kitöltések", order = 2, useForSearch = true)
@property:GenerateOverview(columnName = "Kitöltések", order = 2, useForSearch = true, renderer = OverviewType.NUMBER)
var submissions: Long = 0,

) : IdentifiableEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import hu.bme.sch.cmsch.component.groupselection.GroupSelectionComponent
import hu.bme.sch.cmsch.component.location.LocationService
import hu.bme.sch.cmsch.component.login.CmschUser
import hu.bme.sch.cmsch.component.login.LoginComponent
import hu.bme.sch.cmsch.component.race.FreestyleRaceEntryDto
import hu.bme.sch.cmsch.component.race.RaceService
import hu.bme.sch.cmsch.component.race.RaceView
import hu.bme.sch.cmsch.component.race.RaceStatsView
import hu.bme.sch.cmsch.component.riddle.RiddleBusinessLogicService
import hu.bme.sch.cmsch.component.task.TasksService
import hu.bme.sch.cmsch.component.token.ALL_TOKEN_TYPE
Expand Down Expand Up @@ -64,8 +63,7 @@ class ProfileService(
val tokenCategoryToDisplay = tokenComponent.map { it.collectRequiredType }.orElse(ALL_TOKEN_TYPE)
val incompleteTasks = tasksService.map { it.getTasksThatNeedsToBeCompleted(user) }.orElse(null)

val raceView: RaceView? = raceService.map { it.getViewForUsers(user) }.orElse(null)
val freestyleRaceView: FreestyleRaceEntryDto? = raceService.map { it.getFreestyleEntryOfUser(user.id) }.orElse(null)
val raceStats: RaceStatsView? = raceService.map { it.getRaceStats(user) }.orElse(null)

return ProfileView(
loggedIn = true,
Expand Down Expand Up @@ -114,10 +112,7 @@ class ProfileService(
}.orElse(null),

// Race component
racePlacement = raceView?.place,
raceStat = raceView?.bestTime,
freestyleRaceDescription = freestyleRaceView?.description,
freestyleRaceStat = freestyleRaceView?.time,
raceStats = raceStats,

// Locations component
locations = profileComponent.showGroupLeadersLocations.mapIfTrue { fetchLocations(group).orElse(null) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hu.bme.sch.cmsch.component.profile
import com.fasterxml.jackson.annotation.JsonView
import hu.bme.sch.cmsch.component.debt.DebtDto
import hu.bme.sch.cmsch.component.leaderboard.LeaderBoardEntry
import hu.bme.sch.cmsch.component.race.RaceStatsView
import hu.bme.sch.cmsch.component.token.TokenDto
import hu.bme.sch.cmsch.dto.FullDetails
import hu.bme.sch.cmsch.model.GuildType
Expand Down Expand Up @@ -79,21 +80,9 @@ data class ProfileView(
@field:JsonView(FullDetails::class)
val completedTaskCount: Int? = null,

// Race placement
// Race stats
@field:JsonView(FullDetails::class)
val racePlacement: Int? = null,

// Race stat given in seconds
@field:JsonView(FullDetails::class)
val raceStat: Float? = null,

// Freestyle (funky) race description
@field:JsonView(FullDetails::class)
val freestyleRaceDescription: String? = null,

// Freestyle (funky) race stat given in seconds
@field:JsonView(FullDetails::class)
val freestyleRaceStat: Float? = null,
val raceStats: RaceStatsView? = null,

@field:JsonView(FullDetails::class)
val profileIsComplete: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ const val TIMER_OCCURRENCE = 10

private const val NOBODY = "senki"

data class TowerHistoryEntry(
val userName: String = NOBODY,
val userId: Int = 0,
val ownerGroup: String = NOBODY,
val ownerGroupId: Int = 0,
val timestamp: Long = 0
)

@Service
@ConditionalOnBean(QrFightComponent::class)
class QrFightService(
Expand Down Expand Up @@ -309,22 +317,12 @@ class QrFightService(
if (dailyLimit != -1L){
val history = towerEntity.history
.split("\n")
.map { it.split(";") }
.map {
TokenPropertyRawView(
ownerUserName = it[0],
ownerUserId = it[1].toIntOrNull() ?: 0,
ownerGroupName = it[2],
ownerGroupId = it[3].toIntOrNull() ?: 0,
timestamp = it[4].toLongOrNull() ?: 0,
token = "",
score = 0
)
}
.filter { it.isNotBlank() } // Only non-empty lines
.map { objectMapper.readValue(it, TowerHistoryEntry::class.java) }
.filter { it.timestamp > clock.getTimeInSeconds() - 24 * 3600 }
.filter { it.ownerUserId == user.id }
.filter { it.userId == user.id }

if (history.size > dailyLimit){
if (history.size >= dailyLimit){
log.info("Tower '{}' daily limit exceeded for user:{} (group:{})", towerEntity.selector, user.userName, groupName)
return TokenSubmittedView(QR_TOWER_DAILY_LIMIT_EXCEEDED, token.title, null, null)
}
Expand All @@ -337,7 +335,7 @@ class QrFightService(

towerEntity.ownerGroupId = groupId
towerEntity.ownerGroupName = groupName
towerEntity.history += "${user.userName};${user.id};${groupName};${groupId};${clock.getTimeInSeconds()};\n"
towerEntity.history += objectMapper.writeValueAsString(TowerHistoryEntry(userName = user.userName, userId = user.id, ownerGroup = groupName, ownerGroupId = groupId, timestamp = clock.getTimeInSeconds())) + "\n"
qrTowerRepository.save(towerEntity)
log.info("Tower '{}' captured by group:{} (user:{})", token.title, groupName, user.userName)
return TokenSubmittedView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ data class QrLevelEntity(
@property:ImportFormat
var extraLevel: Boolean = false,

@Column(nullable = false, columnDefinition="BOOLEAN DEFAULT false")
@Column(nullable = false)
@field:JsonView(value = [ Edit::class, Preview::class, FullDetails::class ])
@property:GenerateInput(type = InputType.SWITCH, order = 14, label = "Treasure hunt szint",
note = "Olyan tokeneket tartalmazó szint, ahol az addig megszerzett tokenek adják a hintet a további tokenekhez")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ data class FreestyleRaceEntryDto(
@property:ImportFormat
var email: String = "",

@field:JsonView(FullDetails::class)
@property:GenerateOverview(columnName = "Címke", order = 6)
@property:ImportFormat
var label: String = "",

) : ManagedEntity {

override fun getEntityConfig(env: Environment) = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class FreestyleRaceRecordController(

private fun processUserSubmission(entity: FreestyleRaceRecordEntity): Boolean {
if (entity.userName.isNotBlank() && entity.userName != "-") {
val id = entity.userName.split("|")[0].trim().toIntOrNull() ?: 0
val id = entity.userName.split("|")[1].trim().toIntOrNull() ?: 0
val user = transactionManager.transaction(readOnly = true) { users.findById(id) }

if (user.isPresent) {
Expand Down Expand Up @@ -146,7 +146,7 @@ class FreestyleRaceRecordController(
}

private fun mapUsername(it: UserEntity) =
"${it.id}| ${it.fullNameWithAlias} [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
"${it.fullNameWithAlias} | ${it.id} | [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"

private fun mapUsername(it: UserSelectorView) =
"${it.id}| ${it.fullNameWithAlias} [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
"${it.fullNameWithAlias} | ${it.id} | [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data class FreestyleRaceRecordEntity(
@field:JsonView(value = [ Edit::class, Preview::class, FullDetails::class ])
@Column(nullable = false)
@property:GenerateInput(type = InputType.ENTITY_SELECT, order = 2, label = "Felhasználó", entitySource = "UserEntity",
note = "Csak akkor kell kijelölni ha felhasználók kapnak pontot. Formátum: `id| Teljes Név [a/g] email` ahol az: a = authsch, g = google",
note = "Csak akkor kell kijelölni ha felhasználók kapnak pontot. Formátum: `Teljes Név | id | [a/g] email` ahol az: a = authsch, g = google",
interpreter = InputInterpreter.SEARCH)
@property:GenerateOverview(columnName = "Felhasználó", order = 2, centered = true)
@property:ImportFormat
Expand Down Expand Up @@ -75,13 +75,6 @@ data class FreestyleRaceRecordEntity(
@property:ImportFormat
var timestamp: Long = 0,

@Column(nullable = false)
@field:JsonView(value = [ Edit::class, Preview::class, FullDetails::class ])
@property:GenerateInput(order = 7, label = "Címke", note = "Név melletti címke, pl: Gólya, Lány etc.")
@property:GenerateOverview(columnName = "Címke", order = 6)
@property:ImportFormat
var label: String = "",

) : ManagedEntity, Duplicatable {

override fun getEntityConfig(env: Environment) = EntityConfig(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,17 @@ data class RaceEntryDto(
@property:ImportFormat
var email: String = "",

) : ManagedEntity {
@field:JsonView(FullDetails::class)
@property:GenerateOverview(columnName = "Címke", order = 5)
@property:ImportFormat
var label: String = "",

@field:JsonView(FullDetails::class)
@property:GenerateOverview(columnName = "Címke színe", order = 6)
@property:ImportFormat
var labelColor: String? = "",

) : ManagedEntity {

override fun getEntityConfig(env: Environment) = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class RaceRecordController(

private fun processUserSubmission(entity: RaceRecordEntity): Boolean {
if (entity.userName.isNotBlank() && entity.userName != "-") {
val id = entity.userName.split("|")[0].trim().toIntOrNull() ?: 0
val id = entity.userName.split("|")[1].trim().toIntOrNull() ?: 0
val user = transactionManager.transaction(readOnly = true) { users.findById(id) }

if (user.isPresent) {
Expand Down Expand Up @@ -156,7 +156,7 @@ class RaceRecordController(


private fun mapUsername(it: UserEntity) =
"${it.id}| ${it.fullNameWithAlias} [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
"${it.fullNameWithAlias} | ${it.id} | [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"

private fun mapUsername(it: UserSelectorView) =
"${it.id}| ${it.fullNameWithAlias} [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
"${it.fullNameWithAlias} | ${it.id} | [${it.provider.firstOrNull() ?: 'n'}] ${it.email}"
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class RaceRecordEntity(

@Column(nullable = false)
@field:JsonView(value = [ Edit::class ])
@property:GenerateInput(order = 2, label = "Kategória", type = InputType.ENTITY_SELECT,
@property:GenerateInput(order = 1, label = "Kategória", type = InputType.ENTITY_SELECT,
entitySource = "RaceCategoryEntity", note = "Az üres az alapértelmezett kategória")
@property:GenerateOverview(columnName = "Kategória", order = 1)
@property:ImportFormat
Expand All @@ -42,7 +42,7 @@ data class RaceRecordEntity(
@field:JsonView(value = [ Edit::class, Preview::class, FullDetails::class ])
@Column(nullable = false)
@property:GenerateInput(type = InputType.ENTITY_SELECT, order = 2, label = "Felhasználó", entitySource = "UserEntity",
note = "Csak akkor kell kijelölni ha felhasználók kapnak pontot. Formátum: `id| Teljes Név [a/g] email` ahol az: a = authsch, g = google",
note = "Csak akkor kell kijelölni ha felhasználók kapnak pontot. Formátum: `Teljes Név | id | [a/g] email` ahol az: a = authsch, g = google",
interpreter = InputInterpreter.SEARCH)
@property:GenerateOverview(columnName = "Felhasználó", order = 2, centered = true)
@property:ImportFormat
Expand Down Expand Up @@ -76,6 +76,24 @@ data class RaceRecordEntity(
@property:ImportFormat
var timestamp: Long = 0,

@Column(nullable = false)
@field:JsonView(value = [ Edit::class, Preview::class, FullDetails::class ])
@property:GenerateInput(order = 6, label = "Címke", note = "Név melletti címke, pl: Gólya, Lány etc.")
@property:GenerateOverview(columnName = "Címke", order = 6)
@property:ImportFormat
var label: String = "",

@Column(nullable = true, columnDefinition = "TEXT")
@field:JsonView(value = [Edit::class, Preview::class, FullDetails::class])
@property:GenerateInput(
order = 7,
type = InputType.COLOR,
label = "Szín",
note = "A címke színe hex kódban megadva. Ha üresen hagyod, akkor az oldal színét fogja használni.",
)
@property:ImportFormat
var labelColor: String? = "",

) : ManagedEntity, Duplicatable {

override fun getEntityConfig(env: Environment) = EntityConfig(
Expand Down
Loading
Loading