Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Migrate PUT /admin/group/<groupIri> to Tapir (DEV-1588) #3071

Merged
merged 9 commits into from Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,6 +19,7 @@ import org.knora.webapi.messages.store.triplestoremessages.StringLiteralV2
import org.knora.webapi.routing.UnsafeZioRun
import org.knora.webapi.sharedtestdata.SharedTestDataADM.*
import org.knora.webapi.slice.admin.api.GroupsRequests.GroupCreateRequest
import org.knora.webapi.slice.admin.api.GroupsRequests.GroupUpdateRequest
import org.knora.webapi.slice.admin.domain.model.GroupIri
import org.knora.webapi.slice.admin.domain.model.KnoraProject.ProjectIri
import org.knora.webapi.util.MutableTestIri
Expand Down Expand Up @@ -56,7 +57,7 @@ class GroupsResponderADMSpec extends CoreSpec {

"CREATE the group and return the group's info if the supplied group name is unique" in {
val response = UnsafeZioRun.runOrThrow(
GroupsResponderADM.createGroupADM(
GroupsResponderADM.createGroup(
GroupCreateRequest(
id = None,
name = GroupName.unsafeFrom("NewGroup"),
Expand Down Expand Up @@ -93,7 +94,7 @@ class GroupsResponderADMSpec extends CoreSpec {
"return a 'DuplicateValueException' if the supplied group name is not unique" in {
val groupName = GroupName.unsafeFrom("NewGroup")
val exit = UnsafeZioRun.run(
GroupsResponderADM.createGroupADM(
GroupsResponderADM.createGroup(
GroupCreateRequest(
id = Some(GroupIri.unsafeFrom(imagesReviewerGroup.id)),
name = groupName,
Expand All @@ -113,24 +114,23 @@ class GroupsResponderADMSpec extends CoreSpec {
}

"UPDATE a group" in {
appActor ! GroupChangeRequestADM(
groupIri = newGroupIri.get,
changeGroupRequest = GroupUpdatePayloadADM(
Some(GroupName.unsafeFrom("UpdatedGroupName")),
Some(
GroupDescriptions
.unsafeFrom(
val response = UnsafeZioRun.runOrThrow(
GroupsResponderADM.updateGroup(
groupIri = GroupIri.unsafeFrom(newGroupIri.get),
GroupUpdateRequest(
name = Some(GroupName.unsafeFrom("UpdatedGroupName")),
descriptions = Some(
GroupDescriptions.unsafeFrom(
Seq(V2.StringLiteralV2(value = """UpdatedDescription with "quotes" and <html tag>""", Some("en")))
)
)
),
requestingUser = imagesUser01,
apiRequestID = UUID.randomUUID
),
status = Some(GroupStatus.active),
selfjoin = Some(GroupSelfJoin.impossible)
),
UUID.randomUUID
)
)

val received: GroupGetResponseADM = expectMsgType[GroupGetResponseADM](timeout)
val updatedGroupInfo = received.group

val updatedGroupInfo = response.group
updatedGroupInfo.name should equal("UpdatedGroupName")
updatedGroupInfo.descriptions should equal(
Seq(StringLiteralV2("""UpdatedDescription with "quotes" and <html tag>""", Some("en")))
Expand All @@ -141,41 +141,49 @@ class GroupsResponderADMSpec extends CoreSpec {
}

"return 'NotFound' if a not-existing group IRI is submitted during update" in {
appActor ! GroupChangeRequestADM(
groupIri = "http://rdfh.ch/groups/notexisting",
GroupUpdatePayloadADM(
Some(GroupName.unsafeFrom("UpdatedGroupName")),
Some(
GroupDescriptions
.unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en"))))
)
),
requestingUser = imagesUser01,
apiRequestID = UUID.randomUUID
val groupIri = "http://rdfh.ch/groups/0000/notexisting"
val exit = UnsafeZioRun.run(
GroupsResponderADM.updateGroup(
groupIri = GroupIri.unsafeFrom(groupIri),
GroupUpdateRequest(
name = Some(GroupName.unsafeFrom("UpdatedGroupName")),
descriptions = Some(
GroupDescriptions
.unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en"))))
),
status = Some(GroupStatus.active),
selfjoin = Some(GroupSelfJoin.impossible)
),
UUID.randomUUID
)
)
assertFailsWithA[NotFoundException](
exit,
s"Group <$groupIri> not found. Aborting update request."
)

expectMsgPF(timeout) { case msg: Failure =>
msg.cause.isInstanceOf[NotFoundException] should ===(true)
}
}

"return 'BadRequest' if the new group name already exists inside the project" in {
appActor ! GroupChangeRequestADM(
groupIri = newGroupIri.get,
changeGroupRequest = GroupUpdatePayloadADM(
Some(GroupName.unsafeFrom("Image reviewer")),
Some(
GroupDescriptions
.unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en"))))
)
),
requestingUser = imagesUser01,
apiRequestID = UUID.randomUUID
val groupName = GroupName.unsafeFrom("Image reviewer")
val exit = UnsafeZioRun.run(
GroupsResponderADM.updateGroup(
GroupIri.unsafeFrom(newGroupIri.get),
GroupUpdateRequest(
name = Some(groupName),
descriptions = Some(
GroupDescriptions
.unsafeFrom(Seq(V2.StringLiteralV2(value = "UpdatedDescription", language = Some("en"))))
),
status = Some(GroupStatus.active),
selfjoin = Some(GroupSelfJoin.impossible)
),
UUID.randomUUID
)
)
assertFailsWithA[BadRequestException](
exit,
s"Group with the name '${groupName.value}' already exists."
)

expectMsgPF(timeout) { case msg: Failure =>
msg.cause.isInstanceOf[BadRequestException] should ===(true)
}
}

"return 'BadRequest' if nothing would be changed during the update" in {
Expand Down
Expand Up @@ -27,27 +27,6 @@ import org.knora.webapi.slice.admin.domain.model.User
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// API requests

/**
* Represents an API request payload that asks the Knora API server to create a new group.
*
* @param id the optional IRI of the group to be created (unique).
* @param name the name of the group to be created (unique).
* @param descriptions the descriptions of the group to be created.
* @param project the project inside which the group will be created.
* @param status the status of the group to be created (active = true, inactive = false).
* @param selfjoin the status of self-join of the group to be created.
*/
case class CreateGroupApiRequestADM(
id: Option[IRI] = None,
name: String,
descriptions: Seq[V2.StringLiteralV2],
project: IRI,
status: Boolean,
selfjoin: Boolean
) extends GroupsADMJsonProtocol {
def toJsValue: JsValue = createGroupApiRequestADMFormat.write(this)
}

/**
* Represents an API request payload that asks the Knora API server to update
* an existing group. There are two change cases that are covered with this
Expand Down Expand Up @@ -130,21 +109,6 @@ case class MultipleGroupsGetRequestADM(
*/
case class GroupMembersGetRequestADM(groupIri: IRI, requestingUser: User) extends GroupsResponderRequestADM

/**
* Request updating of an existing group.
*
* @param groupIri the IRI of the group to be updated.
* @param changeGroupRequest the data which needs to be update.
* @param requestingUser the user initiating the request.
* @param apiRequestID the ID of the API request.
*/
case class GroupChangeRequestADM(
groupIri: IRI,
changeGroupRequest: GroupUpdatePayloadADM,
requestingUser: User,
apiRequestID: UUID
) extends GroupsResponderRequestADM

/**
* Request changing the status (active/inactive) of an existing group.
*
Expand Down Expand Up @@ -220,8 +184,6 @@ trait GroupsADMJsonProtocol extends SprayJsonSupport with DefaultJsonProtocol wi
implicit val groupsGetResponseADMFormat: RootJsonFormat[GroupsGetResponseADM] =
jsonFormat(GroupsGetResponseADM, "groups")
implicit val groupResponseADMFormat: RootJsonFormat[GroupGetResponseADM] = jsonFormat(GroupGetResponseADM, "group")
implicit val createGroupApiRequestADMFormat: RootJsonFormat[CreateGroupApiRequestADM] =
jsonFormat(CreateGroupApiRequestADM, "id", "name", "descriptions", "project", "status", "selfjoin")
implicit val changeGroupApiRequestADMFormat: RootJsonFormat[ChangeGroupApiRequestADM] =
jsonFormat(ChangeGroupApiRequestADM, "name", "descriptions", "status", "selfjoin")
}

This file was deleted.