Skip to content

Commit

Permalink
refactor: Migrate GET /admin/lists?projectIri route to tapir (#3006)
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Jan 29, 2024
1 parent 296815c commit a931357
Show file tree
Hide file tree
Showing 23 changed files with 296 additions and 290 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object LayersTest {
with IriConverter
with IriService
with KnoraProjectRepoLive
with ListsResponderADM
with ListsResponder
with ListsResponderV2
with MessageRelay
with OntologyCache
Expand Down Expand Up @@ -174,7 +174,9 @@ object LayersTest {
IriService.layer,
KnoraProjectRepoLive.layer,
KnoraResponseRenderer.layer,
ListsResponderADMLive.layer,
ListsEndpoints.layer,
ListsEndpointsHandlers.layer,
ListsResponder.layer,
ListsResponderV2Live.layer,
MaintenanceEndpoints.layer,
MaintenanceEndpointsHandlers.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.knora.webapi.messages.admin.responder.listsmessages.ListNodeCreatePay
import org.knora.webapi.messages.admin.responder.listsmessages.*
import org.knora.webapi.messages.store.triplestoremessages.RdfDataObject
import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2
import org.knora.webapi.routing.UnsafeZioRun
import org.knora.webapi.sharedtestdata.SharedListsTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM
import org.knora.webapi.sharedtestdata.SharedTestDataADM2.*
Expand All @@ -32,7 +33,7 @@ import org.knora.webapi.util.MutableTestIri
/**
* Tests [[ListsResponderADM]].
*/
class ListsResponderADMSpec extends CoreSpec with ImplicitSender {
class ListsResponderSpec extends CoreSpec with ImplicitSender {

override lazy val rdfDataObjects = List(
RdfDataObject(
Expand All @@ -56,39 +57,18 @@ class ListsResponderADMSpec extends CoreSpec with ImplicitSender {
"The Lists Responder" when {
"used to query information about lists" should {
"return all lists" in {
appActor ! ListsGetRequestADM(
requestingUser = SharedTestDataADM.imagesUser01
)

val received: ListsGetResponseADM = expectMsgType[ListsGetResponseADM](timeout)

received.lists.size should be(9)
val actual = UnsafeZioRun.runOrThrow(ListsResponder.getLists(None))
actual.lists.size should be(9)
}

"return all lists belonging to the images project" in {
appActor ! ListsGetRequestADM(
projectIri = Some(imagesProjectIri),
requestingUser = SharedTestDataADM.imagesUser01
)

val received: ListsGetResponseADM = expectMsgType[ListsGetResponseADM](timeout)

// log.debug("received: " + received)

received.lists.size should be(4)
val actual = UnsafeZioRun.runOrThrow(ListsResponder.getLists(Some(ProjectIri.unsafeFrom(imagesProjectIri))))
actual.lists.size should be(4)
}

"return all lists belonging to the anything project" in {
appActor ! ListsGetRequestADM(
projectIri = Some(anythingProjectIri),
requestingUser = SharedTestDataADM.imagesUser01
)

val received: ListsGetResponseADM = expectMsgType[ListsGetResponseADM](timeout)

// log.debug("received: " + received)

received.lists.size should be(4)
val actual = UnsafeZioRun.runOrThrow(ListsResponder.getLists(Some(ProjectIri.unsafeFrom(anythingProjectIri))))
actual.lists.size should be(4)
}

"return basic list information (anything list)" in {
Expand Down
6 changes: 4 additions & 2 deletions webapi/src/main/scala/org/knora/webapi/core/LayersLive.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object LayersLive {
AuthorizationRestService & CacheService & CacheServiceRequestMessageHandler & CardinalityHandler &
CardinalityService & ConstructResponseUtilV2 & ConstructTransformer & GravsearchTypeInspectionRunner &
GroupsResponderADM & HttpServer & IIIFRequestMessageHandler & InferenceOptimizationService &
InstrumentationServerConfig & IriConverter & IriService & JwtService & KnoraProjectRepo & ListsResponderADM &
InstrumentationServerConfig & IriConverter & IriService & JwtService & KnoraProjectRepo & ListsResponder &
ListsResponderV2 & MessageRelay & OntologyCache & OntologyHelpers & OntologyInferencer & OntologyRepo &
OntologyResponderV2 & PermissionsResponderADM & PermissionsRestService & PermissionUtilADM &
PredicateObjectMapper & ProjectADMRestService & ProjectADMService & ProjectExportService &
Expand Down Expand Up @@ -122,7 +122,9 @@ object LayersLive {
JwtServiceLive.layer,
KnoraProjectRepoLive.layer,
KnoraResponseRenderer.layer,
ListsResponderADMLive.layer,
ListsEndpoints.layer,
ListsEndpointsHandlers.layer,
ListsResponder.layer,
ListsResponderV2Live.layer,
MaintenanceEndpoints.layer,
MaintenanceEndpointsHandlers.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,10 @@ case class ChangeNodePositionApiRequestADM(position: Int, parentIri: IRI) extend
// Messages

/**
* An abstract trait for messages that can be sent to `HierarchicalListsResponderV2`.
* A trait for messages that can be sent to `HierarchicalListsResponderV2`.
*/
sealed trait ListsResponderRequestADM extends KnoraRequestADM with RelayedMessage

/**
* Requests a list of all lists or the lists inside a project. A successful response will be a [[ListsGetResponseADM]]
*
* @param projectIri the IRI of the project.
* @param requestingUser the user making the request.
*/
case class ListsGetRequestADM(
projectIri: Option[IRI] = None,
requestingUser: User
) extends ListsResponderRequestADM

/**
* Requests a node (root or child). A successful response will be a [[ListItemGetResponseADM]]
*
Expand Down Expand Up @@ -474,18 +463,28 @@ case class NodeADM(nodeinfo: ListChildNodeInfoADM, children: Seq[ListChildNodeAD

/**
* Represents basic information about a list node, the information which is found in the list's root or child node.
*
* @param id the IRI of the list.
* @param name the name of the list node.
* @param labels the labels of the node in all available languages.
* @param comments the comments attached to the node in all available languages.
*/
abstract class ListNodeInfoADM(
id: IRI,
name: Option[String],
labels: StringLiteralSequenceV2,
comments: StringLiteralSequenceV2
) {
sealed trait ListNodeInfoADM {

/**
* @return The IRI of the list node.
*/
def id: IRI

/**
* @return The name of the list node.
*/
def name: Option[String]

/**
* @return The labels of the node in all available languages.
*/
def labels: StringLiteralSequenceV2

/**
* @return The comments attached to the node in all available languages.
*/
def comments: StringLiteralSequenceV2

/**
* Sorts the whole hierarchy.
Expand All @@ -494,10 +493,6 @@ abstract class ListNodeInfoADM(
*/
def sorted: ListNodeInfoADM

def getName: Option[String] = name

def getComments: StringLiteralSequenceV2 = comments

/**
* Gets the label in the user's preferred language.
*
Expand All @@ -515,7 +510,6 @@ abstract class ListNodeInfoADM(
* @return the comment in the preferred language.
*/
def getCommentInPreferredLanguage(userLang: String, fallbackLang: String): Option[String]

}

case class ListRootNodeInfoADM(
Expand All @@ -524,7 +518,7 @@ case class ListRootNodeInfoADM(
name: Option[String] = None,
labels: StringLiteralSequenceV2,
comments: StringLiteralSequenceV2
) extends ListNodeInfoADM(id, name, labels, comments) {
) extends ListNodeInfoADM {

/**
* Sorts the whole hierarchy.
Expand Down Expand Up @@ -587,7 +581,7 @@ case class ListChildNodeInfoADM(
comments: StringLiteralSequenceV2,
position: Int,
hasRootNode: IRI
) extends ListNodeInfoADM(id, name, labels, comments) {
) extends ListNodeInfoADM {

/**
* Sorts the whole hierarchy.
Expand Down
Loading

0 comments on commit a931357

Please sign in to comment.