Skip to content

Commit

Permalink
Revert "chore: Update abstract from pubmed where missing (#621)"
Browse files Browse the repository at this point in the history
This reverts commit 1dcad1c.
  • Loading branch information
ursjoss committed Dec 7, 2023
1 parent 1dcad1c commit 99a8370
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package ch.difty.scipamato.core

import ch.difty.scipamato.common.logger
import ch.difty.scipamato.common.web.AbstractPage
import ch.difty.scipamato.core.config.ApplicationCoreProperties
import ch.difty.scipamato.core.db.tables.Paper
import ch.difty.scipamato.core.db.tables.ScipamatoUser
import ch.difty.scipamato.core.pubmed.PubmedArticleService
import ch.difty.scipamato.core.web.sync.ISyncTask
import ch.difty.scipamato.core.web.sync.TasksRunnable
import com.giffing.wicket.spring.boot.starter.app.WicketBootSecuredWebApplication
Expand All @@ -14,16 +10,12 @@ import org.apache.wicket.markup.head.filter.JavaScriptFilteredIntoFooterHeaderRe
import org.apache.wicket.markup.html.SecurePackageResourceGuard
import org.apache.wicket.request.Request
import org.apache.wicket.request.Response
import org.jooq.DSLContext
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.runApplication
import org.springframework.cache.annotation.EnableCaching
import org.springframework.cloud.openfeign.EnableFeignClients
import org.springframework.context.annotation.ComponentScan
import java.sql.Timestamp
import java.time.LocalDateTime
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit

Expand All @@ -37,15 +29,6 @@ open class ScipamatoCoreApplication : WicketBootSecuredWebApplication() {

private val executorService = Executors.newSingleThreadExecutor()

@Autowired
private lateinit var dsl: DSLContext

@Autowired
protected lateinit var properties: ApplicationCoreProperties

@Autowired
private lateinit var pubmedArticleService: PubmedArticleService

override fun init() {
// TODO consider making it CSP compliant
cspSettings.blocking().disabled()
Expand All @@ -54,14 +37,6 @@ open class ScipamatoCoreApplication : WicketBootSecuredWebApplication() {

headerResponseDecorators.add { JavaScriptFilteredIntoFooterHeaderResponse(it, AbstractPage.FOOTER_CONTAINER) }
registerJasperJrxmlFilesWithPackageResourceGuard()

triggerStartupMigration(dsl) { pmId: Long ->
val id = pmId.toInt()
val result = properties.pubmedApiKey?.let {
pubmedArticleService.getPubmedArticleWithPmidAndApiKey(id, it)
} ?: pubmedArticleService.getPubmedArticleWithPmid(id)
result.pubmedArticleFacade?.originalAbstract
}
}

// Allow access to jrxml jasper report definition files
Expand All @@ -71,36 +46,6 @@ open class ScipamatoCoreApplication : WicketBootSecuredWebApplication() {
}
}

@Suppress("MagicNumber")
private fun triggerStartupMigration(dsl: DSLContext, getAbstract: (Long) -> String?) {
val adminUserId = (dsl
.select(ScipamatoUser.SCIPAMATO_USER.ID)
.from(ScipamatoUser.SCIPAMATO_USER)
.where(ScipamatoUser.SCIPAMATO_USER.USER_NAME.eq("admin"))
.fetchOne()?.get(0) as? Int?) ?: 1
log.info("Starting Migration (user $adminUserId) <----------------------")
val papersToEnrich: List<PaperIds> =
dsl.select(Paper.PAPER.ID, Paper.PAPER.PM_ID)
.from(Paper.PAPER)
.where(Paper.PAPER.PM_ID.isNotNull.and(Paper.PAPER.ORIGINAL_ABSTRACT.isNull))
.fetchInto(PaperIds::class.java).toList()
log.info("affected records with no abstract but PM_ID: ${papersToEnrich.size}")
papersToEnrich.forEach { paper ->
getAbstract(paper.pmId)?.let { abstract ->
log.info("Migrating paper $paper")
dsl.update(Paper.PAPER)
.set(Paper.PAPER.ORIGINAL_ABSTRACT, abstract)
.set(Paper.PAPER.LAST_MODIFIED, Timestamp.valueOf(LocalDateTime.now()))
.set(Paper.PAPER.LAST_MODIFIED_BY, adminUserId)
.set(Paper.PAPER.VERSION, Paper.PAPER.VERSION + 1)
.where(Paper.PAPER.ID.eq(paper.id).and(Paper.PAPER.ORIGINAL_ABSTRACT.isNull())).execute()
Thread.sleep(1000L)
}
}
}

private data class PaperIds(val id: Long, val pmId: Long)

override fun newSession(request: Request, response: Response): Session = ScipamatoSession(request)

@Suppress("MagicNumber")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ import ch.difty.scipamato.core.persistence.UserService
import ch.difty.scipamato.core.pubmed.PubmedArticleService
import com.ninjasquad.springmockk.MockkBean
import io.mockk.junit5.MockKExtension
import org.jooq.DSLContext
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.test.context.ActiveProfiles
Expand Down Expand Up @@ -87,7 +85,4 @@ abstract class AbstractWicketTest {

@MockkBean
protected lateinit var userServiceMock: UserService

@MockkBean(relaxed = true)
protected lateinit var dsl: DSLContext
}

0 comments on commit 99a8370

Please sign in to comment.