Skip to content

Commit 3be5186

Browse files
committed
Migrate Section.java to Scala
- Replace Java class with Scala case class using @BeanProperty and @BooleanBeanProperty - Use direct field access in Scala code, getters available for Java interop - Replace ImmutableMap with Scala Map - Replace secondary constructor with fromResultSet factory method in companion object - Remove Serializable and serialVersionUID - Rename constants to UpperCamelCase - Update copyright to 2026
1 parent 7645690 commit 3be5186

37 files changed

Lines changed: 251 additions & 320 deletions

src/main/java/ru/org/linux/section/Section.java

Lines changed: 0 additions & 174 deletions
This file was deleted.

src/main/scala/ru/org/linux/boxlets/ArticlesBoxlet.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 1998-2024 Linux.org.ru
2+
* Copyright 1998-2026 Linux.org.ru
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -35,7 +35,7 @@ class ArticlesBoxlet(topTenDao: BoxletTopicDao, sectionService: SectionService)
3535
Map(
3636
"messages" -> list.asJava,
3737
"name" -> "Статьи",
38-
"link" -> sectionService.getSection(Section.SECTION_ARTICLES).getSectionLink,
38+
"link" -> sectionService.getSection(Section.Articles).getSectionLink,
3939
"title" -> "Новые статьи").asJava)
4040
}
4141
}

src/main/scala/ru/org/linux/gallery/DeleteImageController.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class DeleteImageController(imageDao: ImageDao, imageService: ImageService, topi
3232
throw new AccessViolationException("Вы не можете редактировать эту тему")
3333
}
3434

35-
if (topic.section.isImagepost && image.main) {
35+
if (topic.section.imagepost && image.main) {
3636
throw new AccessViolationException("Нельзя удалить основное изображение")
3737
}
3838
}

src/main/scala/ru/org/linux/gallery/ImageDao.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 1998-2024 Linux.org.ru
2+
* Copyright 1998-2026 Linux.org.ru
33
* Licensed under the Apache License, Version 2.0 (the "License");
44
* you may not use this file except in compliance with the License.
55
* You may obtain a copy of the License at
@@ -68,13 +68,13 @@ class ImageDao(private val sectionService: SectionService, dataSource: DataSourc
6868
* @return список GalleryDto объектов
6969
*/
7070
def getGalleryItems(countItems: Int): Seq[GalleryItem] = {
71-
val gallery = sectionService.getSection(Section.SECTION_GALLERY)
71+
val gallery = sectionService.getSection(Section.Gallery)
7272
val sql =
7373
s"""SELECT t.msgid, t.stat1,t.title, t.userid, t.urlname, images.extension, images.id AS imageid, t.commitdate
7474
|FROM
7575
| (SELECT topics.id AS msgid, topics.stat1, topics.title, userid, urlname, topics.commitdate
7676
| FROM topics JOIN groups ON topics.groupid = groups.id WHERE topics.moderate
77-
| AND section=${Section.SECTION_GALLERY} AND NOT topics.deleted AND commitdate IS NOT NULL
77+
| AND section=${Section.Gallery} AND NOT topics.deleted AND commitdate IS NOT NULL
7878
| ORDER BY commitdate DESC LIMIT ?) as t JOIN images ON t.msgid = images.topic
7979
|WHERE NOT images.deleted AND images.main ORDER BY commitdate DESC""".stripMargin
8080

@@ -85,14 +85,14 @@ class ImageDao(private val sectionService: SectionService, dataSource: DataSourc
8585
* Возвращает последние объекты галереи.
8686
*/
8787
def getGalleryItems(countItems: Int, tagId: Int): Seq[GalleryItem] = {
88-
val gallery = sectionService.getSection(Section.SECTION_GALLERY)
88+
val gallery = sectionService.getSection(Section.Gallery)
8989

9090
val sql =
9191
s"""SELECT t.msgid, t.stat1,t.title, t.userid, t.urlname, images.extension, images.id AS imageid, t.commitdate
9292
|FROM
9393
| (SELECT topics.id AS msgid, topics.stat1, topics.title, userid, urlname, topics.commitdate
9494
| FROM topics JOIN groups ON topics.groupid = groups.id WHERE topics.moderate
95-
| AND section=${Section.SECTION_GALLERY} AND NOT topics.deleted AND commitdate IS NOT NULL AND
95+
| AND section=${Section.Gallery} AND NOT topics.deleted AND commitdate IS NOT NULL AND
9696
| topics.id IN (SELECT msgid FROM tags WHERE tagid=?) ORDER BY commitdate DESC LIMIT ?) as t
9797
| JOIN images ON t.msgid = images.topic
9898
|WHERE NOT images.deleted AND images.main""".stripMargin

src/main/scala/ru/org/linux/group/GroupController.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class GroupController(groupDao: GroupDao, archiveDao: ArchiveDao, sectionService
7171
@RequestParam(defaultValue = "0", value = "offset") offset: Int,
7272
@PathVariable year: Int, @PathVariable month: Int,
7373
@RequestParam(value = "showignored", defaultValue = "false") showIgnored: Boolean): CompletionStage[ModelAndView] = MaybeAuthorized { implicit currentUserOpt =>
74-
val section = sectionService.getSection(Section.SECTION_FORUM)
74+
val section = sectionService.getSection(Section.Forum)
7575
val group = groupDao.getGroup(section, groupName)
7676

7777
if (year < 1990 || year > 3000) {
@@ -104,7 +104,7 @@ class GroupController(groupDao: GroupDao, archiveDao: ArchiveDao, sectionService
104104
@RequestParam(defaultValue = "false") showDeleted: Boolean,
105105
@RequestParam(value = "showignored", defaultValue = "false") showIgnored: Boolean,
106106
request: HttpServletRequest): CompletionStage[ModelAndView] = MaybeAuthorized { implicit currentUserOpt =>
107-
val section = sectionService.getSection(Section.SECTION_FORUM)
107+
val section = sectionService.getSection(Section.Forum)
108108
val group = groupDao.getGroup(section, groupName)
109109

110110
if (showDeleted && !currentUserOpt.authorized) {

src/main/scala/ru/org/linux/group/GroupListDao.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class GroupListDao(ds: DataSource) {
145145

146146
def getSectionListTopics(section: Section, offset: Int, tagId: Int)
147147
(implicit session: AnySession): collection.Seq[TopicsListItem] = {
148-
val partFilter = s" AND section = ${section.getId}"
148+
val partFilter = s" AND section = ${section.id}"
149149
val tagFilter = s" AND topics.id IN (SELECT msgid FROM tags WHERE tagid=$tagId) "
150150

151151
load(

src/main/scala/ru/org/linux/group/GroupPermissionService.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.joda.time.{DateTime, Duration}
1818
import org.springframework.stereotype.Service
1919
import ru.org.linux.auth.{AnySession, AuthorizedSession}
2020
import ru.org.linux.msgbase.DeleteInfoDao
21-
import ru.org.linux.section.Section.{SECTION_ARTICLES, SECTION_GALLERY, SECTION_NEWS}
21+
import ru.org.linux.section.Section.{Articles, Gallery, News}
2222
import ru.org.linux.section.{Section, SectionService}
2323
import ru.org.linux.topic.{PreparedTopic, Topic, TopicPermissionService}
2424
import ru.org.linux.user.{User, UserPermissionService}
@@ -77,7 +77,7 @@ class GroupPermissionService(sectionService: SectionService, deleteInfoDao: Dele
7777
private def effectivePostscore(group: Group) = {
7878
val section = sectionService.getSection(group.sectionId)
7979

80-
Math.max(group.topicRestriction, section.getTopicsRestriction)
80+
Math.max(group.topicRestriction, section.topicsRestriction)
8181
}
8282

8383
def enableAllowAnonymousCheckbox(group: Group)(implicit currentUser: AnySession): Boolean = {
@@ -87,7 +87,7 @@ class GroupPermissionService(sectionService: SectionService, deleteInfoDao: Dele
8787
}
8888

8989
def isTopicPostingAllowed(section: Section)(implicit currentUser: AnySession): Boolean =
90-
isTopicPostingAllowed(section.getTopicsRestriction, currentUser.userOpt.orNull)
90+
isTopicPostingAllowed(section.topicsRestriction, currentUser.userOpt.orNull)
9191

9292
def isTopicPostingAllowed(group: Group)(implicit currentUser: AnySession): Boolean =
9393
isTopicPostingAllowed(effectivePostscore(group), currentUser.userOpt.orNull)
@@ -110,20 +110,20 @@ class GroupPermissionService(sectionService: SectionService, deleteInfoDao: Dele
110110
}
111111

112112
def isImagePostingAllowed(section: Section)(implicit currentUser: AnySession): Boolean = {
113-
if (section.isImagepost) {
113+
if (section.imagepost) {
114114
true
115115
} else if (currentUser.authorized &&
116116
(currentUser.moderator || currentUser.corrector || currentUser.userOpt.exists(_.getScore >= 50))) {
117-
section.isImageAllowed
117+
section.imageAllowed
118118
} else {
119119
false
120120
}
121121
}
122122

123123
def additionalImageLimit(section: Section)(implicit currentUser: AnySession): Int = {
124124
if (isImagePostingAllowed(section)) {
125-
section.getId match {
126-
case SECTION_ARTICLES | SECTION_GALLERY | SECTION_NEWS =>
125+
section.id match {
126+
case Articles | Gallery | News =>
127127
3
128128
case _ =>
129129
0
@@ -225,7 +225,7 @@ class GroupPermissionService(sectionService: SectionService, deleteInfoDao: Dele
225225

226226
editDeadline.isAfterNow
227227
}
228-
} else if (by.id == author.id && message.commited && section.getId == SECTION_ARTICLES) {
228+
} else if (by.id == author.id && message.commited && section.id == Articles) {
229229
val editDeadline = new DateTime(message.commitDate).plus(EditPeriod)
230230

231231
editDeadline.isAfterNow
@@ -269,7 +269,7 @@ class GroupPermissionService(sectionService: SectionService, deleteInfoDao: Dele
269269

270270
editDeadline.isAfterNow
271271
}
272-
} else if (by.id == author.id && message.commited && section.getId == SECTION_ARTICLES) {
272+
} else if (by.id == author.id && message.commited && section.id == Articles) {
273273
val editDeadline = new DateTime(message.commitDate).plus(EditPeriod)
274274

275275
editDeadline.isAfterNow

src/main/scala/ru/org/linux/search/SearchService.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ class SearchService(elastic: OpenSearchClient, userService: UserService, siteCon
296296

297297
private def buildSectionFacet(sectionsAgg: Aggregate, selected:Option[String]): Seq[FacetItem] = {
298298
def mkItem(urlName: String, count: Long) = {
299-
val name = sectionService.nameToSection.get(urlName).map(_.getName).getOrElse(urlName).toLowerCase
299+
val name = sectionService.nameToSection.get(urlName).map(_.name).getOrElse(urlName).toLowerCase
300300
FacetItem(urlName, s"$name ($count)")
301301
}
302302

0 commit comments

Comments
 (0)