Skip to content

Commit

Permalink
Temporary API to retrieve where used information
Browse files Browse the repository at this point in the history
This is temporary as it actually exposes information to which platform owner should not have any access
  • Loading branch information
tpetter committed Jan 30, 2021
1 parent da5a9c4 commit 5140e33
Showing 1 changed file with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class PlatformRoute(platformQueries: PlatformQueries)(override implicit val user
enableTenant ~
getUserInformation ~
updateUserInformation ~
getWhereUsedInformation ~
getUpdateStatus
}

Expand Down Expand Up @@ -222,6 +223,56 @@ class PlatformRoute(platformQueries: PlatformQueries)(override implicit val user
}
}

@Path("/where-used-info")
@POST
@Operation(
summary = "Get where used information across the platform for a list of users to be updated",
description = "Get where used information across the platform for a list of users to be updated",
tags = Array("platform"),
responses = Array(
new ApiResponse(description = "String message with the usage statistics", responseCode = "200"),
new ApiResponse(description = "Not able to perform the action", responseCode = "500")
)
)
@RequestBody(description = "List of new user information", required = true, content = Array(new Content(schema = new Schema(implementation = classOf[TenantAPI.PlatformUsersUpdateFormat]))))
@Consumes(Array("application/json"))
def getWhereUsedInformation = post {
validOwner { _ =>
pathPrefix("where-used-info") {
pathEndOrSingleSlash {
import spray.json.DefaultJsonProtocol._
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._

implicit val userFormat = jsonFormat2(TenantAPI.PlatformUserUpdateFormat)
implicit val listFormat = jsonFormat1(TenantAPI.PlatformUsersUpdateFormat)
entity(as[TenantAPI.PlatformUsersUpdateFormat]) { list =>
val newUserIds = list.users.map(u => u.newUserId)
val existingUserIds = list.users.map(u => u.existingUserId)
val startWhereUsedQueries = System.currentTimeMillis()
val queries = for {
tenantsByUser <- platformQueries.whereUsedInTenants(existingUserIds)
casesByUser <- platformQueries.whereUsedInCases(existingUserIds)
tenantsByNewUser <- platformQueries.whereUsedInTenants(newUserIds)
casesByNewUser <- platformQueries.whereUsedInCases(newUserIds)
} yield (tenantsByUser, casesByUser, tenantsByNewUser, casesByNewUser)
onComplete(queries) {
case Success(value) => {
val finishedWhereUsedQueries = System.currentTimeMillis()
val queryTimingMsg = s"Query took ${finishedWhereUsedQueries - startWhereUsedQueries} millis"
val existingMsg = s"Existing user ids are found in ${value._1.size} tenants and ${value._2.size} cases; query took ${finishedWhereUsedQueries - startWhereUsedQueries} millis"
val newMsg = s"New user ids are found in ${value._3.size} tenants and ${value._4.size} cases"

val msg = s"$queryTimingMsg\n$existingMsg\n$newMsg"
complete(StatusCodes.OK, msg)
}
case Failure(t) => handleFailure(t)
}
}
}
}
}
}

@Path("/update-status")
@GET
@Operation(
Expand Down

0 comments on commit 5140e33

Please sign in to comment.