Skip to content

Commit

Permalink
https://github.com/DASISH/qddt-client/issues/770
Browse files Browse the repository at this point in the history
DASISH/qddt-client#769

fixed Change Feed
  • Loading branch information
StigNorland committed Jan 25, 2022
1 parent a311670 commit 72b5c4c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/main/kotlin/no/nsd/qddt/config/RepositoryRestConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class RepositoryRestConfig : RepositoryRestConfigurer {
config.exposeIdsFor(User::class.java)
config.exposeIdsFor(PublicationStatus::class.java)
config.exposeIdsFor(Publication::class.java)
// config.exposeIdsFor(ChangeFeed::class.java)


// config.withEntityLookup().forRepository(AgencyRepository::class.java, Agency::id, AgencyRepository::findById)
Expand Down
54 changes: 54 additions & 0 deletions src/main/kotlin/no/nsd/qddt/controller/ViewController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package no.nsd.qddt.controller

import no.nsd.qddt.repository.ChangeFeedRepository
import no.nsd.qddt.repository.projection.UserListe
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.rest.webmvc.BasePathAwareController
import org.springframework.hateoas.*
import org.springframework.hateoas.mediatype.hal.HalModelBuilder
import org.springframework.web.bind.annotation.*

@BasePathAwareController
class ViewController(@Autowired val changeFeedRepository: ChangeFeedRepository) {

class ChangelogCriteria{
var name: String? = null
get() = field?.replace("*","%")?:"%"
var kind: String? = null
get() = field?.replace("*","%")?:"%"
var changeKind: String? = null
get() = field?.replace("*","%")?:"%"

override fun toString(): String {
return "ChangelogCriteria(name=$name, changeKind=$changeKind, kind=$kind)"
}

}

@ResponseBody
@GetMapping("/changelog/search/findByQuery", produces = ["application/hal+json"])
fun getByQuery(changelogCriteria: ChangelogCriteria, pageable: Pageable?): RepresentationModel<*> {

AbstractRestController.logger.debug(changelogCriteria.toString())
val entities = changeFeedRepository.findByNameLikeIgnoreCaseAndRefChangeKindLikeIgnoreCaseAndRefKindLikeIgnoreCase(
name = changelogCriteria.name,
changeKind = changelogCriteria.changeKind,
kind= changelogCriteria.kind,
pageable
).map {
val user = it.modifiedBy!!
HalModelBuilder.halModel()
.entity(it)
.embed(user, LinkRelation.of("modifiedBy"))
.build()
}

return PagedModel.of(entities.content,pageMetadataBuilder(entities), Link.of("changelogs"))
}

protected fun pageMetadataBuilder(revisions: Page<RepresentationModel<out RepresentationModel<*>>>): PagedModel.PageMetadata {
return PagedModel.PageMetadata(revisions.size.toLong(),revisions.pageable.pageNumber.toLong(),revisions.totalElements,revisions.totalPages.toLong())
}
}
8 changes: 7 additions & 1 deletion src/main/kotlin/no/nsd/qddt/model/ChangeFeed.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package no.nsd.qddt.model

import no.nsd.qddt.model.enums.ActionKind
import org.hibernate.annotations.Immutable
import java.sql.Timestamp
import java.util.*
Expand All @@ -13,6 +14,8 @@ import javax.persistence.*
@Immutable
data class ChangeFeed(@EmbeddedId private val changeFeedKey: ChangeFeedKey? = null) {

@Column(name = "ref_id",insertable = false, updatable = false)
var refId: UUID? = null

@Column(name = "ref_rev", insertable = false, updatable = false)
var refRev: Int? = null
Expand All @@ -24,12 +27,15 @@ data class ChangeFeed(@EmbeddedId private val changeFeedKey: ChangeFeedKey? = nu
@Column(name = "ref_change_kind")
var refChangeKind: String? = null

@Column(name = "ref_action", insertable = false, updatable = false)
var refAction: ActionKind? = null

@Column(name = "ref_modified")
var modified: Timestamp? = null

@ManyToOne
@JoinColumn(name = "ref_modified_by", updatable = false)
private var modifiedBy: User? = null
var modifiedBy: User? = null

@Column(name = "element_id")
private var elementId: UUID? = null
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/no/nsd/qddt/model/ChangeFeedKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class ChangeFeedKey(
protected var refRev: Int? = null,

@Enumerated(EnumType.ORDINAL)
@Column(columnDefinition = "int2")
protected var refAction: ActionKind? = null
@Column(name = "ref_action", columnDefinition = "int2")
var refAction: ActionKind? = null


) :Serializable {
Expand Down
42 changes: 24 additions & 18 deletions src/main/kotlin/no/nsd/qddt/repository/ChangeFeedRepository.kt
Original file line number Diff line number Diff line change
@@ -1,35 +1,41 @@
package no.nsd.qddt.repository
import no.nsd.qddt.model.ChangeFeed
import no.nsd.qddt.model.ChangeFeedKey
import no.nsd.qddt.repository.projection.CommentListe
import org.springframework.data.domain.Page
import org.springframework.data.domain.Pageable
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param
import org.springframework.data.rest.core.annotation.RepositoryRestResource
import org.springframework.data.rest.core.annotation.RestResource
import org.springframework.stereotype.Repository

/**
* @author Stig Norland
*/
//@RepositoryRestResource(path = "changelog", itemResourceRel = "ChangeFeed") //, excerptProjection = CommentListe::class)
@Repository
interface ChangeFeedRepository : JpaRepository<ChangeFeed?, ChangeFeedKey?> {
fun findByNameLikeIgnoreCaseOrRefChangeKindLikeIgnoreCaseOrRefKindLikeIgnoreCase(
name: String?,
changeKind: String?,
kind: String?,
interface ChangeFeedRepository : JpaRepository<ChangeFeed, ChangeFeedKey> {

// @RestResource(rel = "findByQuery", path = "findByQuery")
fun findByNameLikeIgnoreCaseAndRefChangeKindLikeIgnoreCaseAndRefKindLikeIgnoreCase(
name: String?="%",
changeKind: String?="%",
kind: String?="%",
pageable: Pageable?
): Page<ChangeFeed?>?
): Page<ChangeFeed>

@Query(
value = "SELECT cl FROM ChangeFeed cl " +
"WHERE lower(cl.name) like :name or lower(cl.refChangeKind) LIKE :changeKind or lower(cl.refKind) LIKE :kind "
+ "ORDER BY ?#{#pageable}", countQuery = "SELECT count(cl) FROM ChangeFeed cl " +
"WHERE lower(cl.name) like :name or lower(cl.refChangeKind) LIKE :changeKind or lower(cl.refKind) LIKE :kind "
+ "ORDER BY ?#{#pageable}", nativeQuery = false
)
fun findByQuery(
@Param("name") name: String?,
@Param("changeKind") changeKind: String?,
@Param("kind") kind: String?, pageable: Pageable?
): Page<ChangeFeed?>?
// @Query(nativeQuery = false,
// value = "SELECT cl FROM ChangeFeed cl " +
// "WHERE lower(cl.name) like :name or lower(cl.refChangeKind) LIKE :changeKind or lower(cl.refKind) LIKE :kind "
// ,
// countQuery = "SELECT count(cl) FROM ChangeFeed cl " +
// "WHERE lower(cl.name) like :name or lower(cl.refChangeKind) LIKE :changeKind or lower(cl.refKind) LIKE :kind "
// )
// fun findByQuery(
// @Param("name") name: String?,
// @Param("changeKind") changeKind: String?,
// @Param("kind") kind: String?, pageable: Pageable?
// ): Page<ChangeFeed?>?
}
3 changes: 2 additions & 1 deletion src/main/kotlin/no/nsd/qddt/repository/SearchRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package no.nsd.qddt.repository

import no.nsd.qddt.model.QddtUrl
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.rest.core.annotation.RepositoryRestResource
import org.springframework.stereotype.Repository
import java.util.*

/**
* @author Stig Norland
*/
@Repository
@RepositoryRestResource(path = "search", itemResourceRel = "QddtUrl") //, excerptProjection = CommentListe::class)
interface SearchRepository : JpaRepository<QddtUrl, UUID> {
fun findByName(name: String): List<QddtUrl>
fun findByUserId(userId: UUID): List<QddtUrl> // @Query(value = "SELECT p.* FROM publication p " +
Expand Down

0 comments on commit 72b5c4c

Please sign in to comment.