-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/DASISH/qddt-client/issues/770
DASISH/qddt-client#769 fixed Change Feed
- Loading branch information
1 parent
a311670
commit 72b5c4c
Showing
6 changed files
with
90 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 24 additions & 18 deletions
42
src/main/kotlin/no/nsd/qddt/repository/ChangeFeedRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?>? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters