Skip to content

Commit

Permalink
remove EntityService's custom getWorkspaceId implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb committed Nov 26, 2024
1 parent d41c5c8 commit a565861
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ class EntityService(rawlsDAO: RawlsDAO,
): Future[PerRequestMessage] = {
import spray.json._
val dataBytes = rawlsCalls.toJson.prettyPrint.getBytes(StandardCharsets.UTF_8)
getWorkspaceId(workspaceNamespace, workspaceName, userInfo) map { workspaceId =>
rawlsDAO.getWorkspaceId(workspaceNamespace, workspaceName)(userInfo) map { workspaceId =>
val bucketToWrite = GcsBucketName(FireCloudConfig.Cwds.bucket)
val fileToWrite = GcsObjectName(s"to-cwds/${workspaceId}/${java.util.UUID.randomUUID()}.json")
val gcsPath = writeDataToGcs(bucketToWrite, fileToWrite, dataBytes)
val importRequest = getRawlsJsonImportRequest(gcsPath, isUpsert)
importToCWDS(workspaceNamespace, workspaceName, workspaceId, userInfo, importRequest)
importToCWDS(workspaceNamespace, workspaceName, workspaceId.toString, userInfo, importRequest)
}
}

Expand All @@ -220,9 +220,6 @@ class EntityService(rawlsDAO: RawlsDAO,
private def getRawlsJsonImportRequest(gcsPath: String, isUpsert: Boolean): AsyncImportRequest =
AsyncImportRequest(gcsPath, FILETYPE_RAWLS, Some(ImportOptions(None, Some(isUpsert))))

private def getWorkspaceId(workspaceNamespace: String, workspaceName: String, userInfo: UserInfo): Future[String] =
rawlsDAO.getWorkspace(workspaceNamespace, workspaceName)(userInfo).map(_.workspace.workspaceId)

private def importToCWDS(workspaceNamespace: String,
workspaceName: String,
workspaceId: String,
Expand Down Expand Up @@ -339,8 +336,8 @@ class EntityService(rawlsDAO: RawlsDAO,
if (importRequest.filetype.isEmpty)
throw new FireCloudExceptionWithErrorReport(ErrorReport(BadRequest, "filetype must be specified"))

getWorkspaceId(workspaceNamespace, workspaceName, userInfo) map { workspaceId =>
importToCWDS(workspaceNamespace, workspaceName, workspaceId, userInfo, importRequest)
rawlsDAO.getWorkspaceId(workspaceNamespace, workspaceName)(userInfo) map { workspaceId =>
importToCWDS(workspaceNamespace, workspaceName, workspaceId.toString, userInfo, importRequest)
} recover { case apiEx: ApiException =>
throw wrapCwdsException(apiEx)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {

when(cwdsDAO.isEnabled).thenReturn(true)
when(cwdsDAO.getSupportedFormats).thenReturn(List("pfb", "tdrexport", "rawlsjson"))
when(rawlsDAO.getWorkspace(any[String], any[String])(any[UserInfo]))
.thenReturn(Future.successful(workspaceResponse))
when(rawlsDAO.getWorkspaceId(any[String], any[String])(any[UserInfo]))
.thenReturn(Future.successful(UUID.fromString(workspaceResponse.workspace.workspaceId)))

entityService
.importEntitiesFromTSV("workspaceNamespace", "workspaceName", tsvData, dummyUserInfo("token"), true)
Expand All @@ -176,7 +176,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
val capturedRequest = argumentCaptor.getValue
capturedRequest.options should be(Some(ImportOptions(None, Some(tsvType != "update"))))
verify(rawlsDAO, times(1))
.getWorkspace(any[String], any[String])(any[UserInfo])
.getWorkspaceId(any[String], any[String])(any[UserInfo])

}
}
Expand Down Expand Up @@ -289,8 +289,8 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {

when(cwdsDAO.importV1(any[String], any[AsyncImportRequest])(any[UserInfo])).thenReturn(genericJob)

when(rawlsDAO.getWorkspace(any[String], any[String])(any[UserInfo]))
.thenReturn(Future.successful(workspaceResponse))
when(rawlsDAO.getWorkspaceId(any[String], any[String])(any[UserInfo]))
.thenReturn(Future.successful(UUID.fromString(workspaceResponse.workspace.workspaceId)))

// create input
val input = AsyncImportRequest(url = "https://example.com", filetype = importFiletype)
Expand All @@ -302,7 +302,7 @@ class EntityServiceSpec extends BaseServiceSpec with BeforeAndAfterEach {
verify(cwdsDAO, times(1))
.importV1(any[String], any[AsyncImportRequest])(any[UserInfo])
verify(rawlsDAO, times(1))
.getWorkspace(any[String], any[String])(any[UserInfo])
.getWorkspaceId(any[String], any[String])(any[UserInfo])
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class MockRawlsDAO extends RawlsDAO {
private val rawlsWorkspaceWithAttributes = WorkspaceDetails(
"attributes",
"att",
"id",
"00000000-0000-0000-0000-000000000000",
"", // bucketname
Some("wf-collection"),
DateTime.now(),
Expand Down

0 comments on commit a565861

Please sign in to comment.