diff --git a/controllers/src/main/scala/cromwell/pipeline/controller/ProjectConfigurationController.scala b/controllers/src/main/scala/cromwell/pipeline/controller/ProjectConfigurationController.scala index c8e59ab9e..f32dc3edd 100644 --- a/controllers/src/main/scala/cromwell/pipeline/controller/ProjectConfigurationController.scala +++ b/controllers/src/main/scala/cromwell/pipeline/controller/ProjectConfigurationController.scala @@ -6,9 +6,10 @@ import akka.http.scaladsl.server.{ ExceptionHandler, Route } import cromwell.pipeline.controller.ProjectConfigurationController._ import cromwell.pipeline.controller.utils.FromStringUnmarshallers._ import cromwell.pipeline.controller.utils.FromUnitMarshaller._ -import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId } +import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId => ProjectIdPM } import cromwell.pipeline.datastorage.dto._ import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent +import cromwell.pipeline.model.wrapper.ProjectId import cromwell.pipeline.service.ProjectConfigurationService import cromwell.pipeline.service.ProjectConfigurationService.Exceptions._ import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport._ @@ -61,7 +62,7 @@ class ProjectConfigurationController(projectConfigurationService: ProjectConfigu val route: AccessTokenContent => Route = implicit accessToken => handleExceptions(projectConfigurationServiceExceptionHandler) { - pathPrefix("projects" / ProjectId / "configurations") { projectId => + pathPrefix("projects" / ProjectIdPM / "configurations") { projectId => buildConfiguration(projectId) ~ addConfiguration(projectId) ~ getConfiguration(projectId) ~ diff --git a/controllers/src/main/scala/cromwell/pipeline/controller/ProjectFileController.scala b/controllers/src/main/scala/cromwell/pipeline/controller/ProjectFileController.scala index 8467c2af4..e85a46772 100644 --- a/controllers/src/main/scala/cromwell/pipeline/controller/ProjectFileController.scala +++ b/controllers/src/main/scala/cromwell/pipeline/controller/ProjectFileController.scala @@ -6,9 +6,10 @@ import akka.http.scaladsl.server.Route import akka.stream.Materializer import cromwell.pipeline.controller.utils.FieldUnmarshallers._ import cromwell.pipeline.controller.utils.FromStringUnmarshallers._ -import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId } +import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId => ProjectIdPM } import cromwell.pipeline.datastorage.dto._ import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent +import cromwell.pipeline.model.wrapper.ProjectId import cromwell.pipeline.service.ProjectFileService import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport._ @@ -99,7 +100,7 @@ class ProjectFileController(wdlService: ProjectFileService)( val route: AccessTokenContent => Route = implicit accessToken => validateFile ~ - pathPrefix("projects" / ProjectId / "files") { projectId => + pathPrefix("projects" / ProjectIdPM / "files") { projectId => getFile(projectId) ~ getFiles(projectId) ~ uploadFile(projectId) ~ diff --git a/controllers/src/main/scala/cromwell/pipeline/controller/RunController.scala b/controllers/src/main/scala/cromwell/pipeline/controller/RunController.scala index e9c72eb73..be0947bee 100644 --- a/controllers/src/main/scala/cromwell/pipeline/controller/RunController.scala +++ b/controllers/src/main/scala/cromwell/pipeline/controller/RunController.scala @@ -4,9 +4,10 @@ import akka.http.scaladsl.model.{ StatusCode, StatusCodes } import akka.http.scaladsl.server.Directives.{ entity, _ } import akka.http.scaladsl.server.{ ExceptionHandler, Route } import cromwell.pipeline.controller.RunController.runServiceExceptionHandler -import cromwell.pipeline.controller.utils.PathMatchers.{ ProjectId, RunId } +import cromwell.pipeline.controller.utils.PathMatchers.{ RunId, ProjectId => ProjectIdPM } import cromwell.pipeline.datastorage.dto._ import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent +import cromwell.pipeline.model.wrapper.ProjectId import cromwell.pipeline.service.RunService import cromwell.pipeline.service.RunService.Exceptions.RunServiceException import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport._ @@ -46,7 +47,7 @@ class RunController(runService: RunService) { val route: AccessTokenContent => Route = implicit accessToken => handleExceptions(runServiceExceptionHandler) { - pathPrefix("projects" / ProjectId / "runs") { projectId => + pathPrefix("projects" / ProjectIdPM / "runs") { projectId => getRun(projectId) ~ getRunsByProject(projectId) ~ deleteRun(projectId) ~ diff --git a/controllers/src/main/scala/cromwell/pipeline/controller/utils/FromStringUnmarshallers.scala b/controllers/src/main/scala/cromwell/pipeline/controller/utils/FromStringUnmarshallers.scala index e2748276a..2b4d4703e 100644 --- a/controllers/src/main/scala/cromwell/pipeline/controller/utils/FromStringUnmarshallers.scala +++ b/controllers/src/main/scala/cromwell/pipeline/controller/utils/FromStringUnmarshallers.scala @@ -2,8 +2,9 @@ package cromwell.pipeline.controller.utils import akka.http.scaladsl.unmarshalling.Unmarshaller import cats.data.Validated -import cromwell.pipeline.datastorage.dto.{ PipelineVersion, ProjectId } -import cromwell.pipeline.model.wrapper.RunId +import cromwell.pipeline.datastorage.dto.PipelineVersion +import cromwell.pipeline.model.validator.Enable +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId } import java.nio.file.{ Path, Paths } @@ -17,7 +18,7 @@ object FromStringUnmarshallers { } implicit val stringToProjectId: Unmarshaller[String, ProjectId] = Unmarshaller.strict[String, ProjectId] { projectId => - ProjectId(projectId) + ProjectId(projectId, Enable.Unsafe) } implicit val stringToPath: Unmarshaller[String, Path] = Unmarshaller.strict[String, Path] { path => Paths.get(path) diff --git a/controllers/src/main/scala/cromwell/pipeline/controller/utils/PathMatchers.scala b/controllers/src/main/scala/cromwell/pipeline/controller/utils/PathMatchers.scala index 476c3abad..c53c9e0d8 100644 --- a/controllers/src/main/scala/cromwell/pipeline/controller/utils/PathMatchers.scala +++ b/controllers/src/main/scala/cromwell/pipeline/controller/utils/PathMatchers.scala @@ -2,13 +2,11 @@ package cromwell.pipeline.controller.utils import akka.http.scaladsl.server.PathMatcher1 import akka.http.scaladsl.server.PathMatchers.Segment -import cromwell.pipeline.datastorage.dto import cromwell.pipeline.model.wrapper - import java.nio.file.{ Path, Paths } object PathMatchers { - val ProjectId: PathMatcher1[dto.ProjectId] = Segment.map(dto.ProjectId(_)) + val ProjectId: PathMatcher1[wrapper.ProjectId] = Segment.flatMap(wrapper.ProjectId.from(_).toOption) val Path: PathMatcher1[Path] = Segment.map(Paths.get(_)) val RunId: PathMatcher1[wrapper.RunId] = Segment.flatMap(wrapper.RunId.from(_).toOption) val ProjectSearchFilterId: PathMatcher1[wrapper.ProjectSearchFilterId] = diff --git a/controllers/src/test/scala/cromwell/pipeline/controller/ProjectConfigurationControllerTest.scala b/controllers/src/test/scala/cromwell/pipeline/controller/ProjectConfigurationControllerTest.scala index cc3f6f6af..e981916c6 100644 --- a/controllers/src/test/scala/cromwell/pipeline/controller/ProjectConfigurationControllerTest.scala +++ b/controllers/src/test/scala/cromwell/pipeline/controller/ProjectConfigurationControllerTest.scala @@ -5,6 +5,7 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest import cromwell.pipeline.datastorage.dao.utils.{ TestProjectUtils, TestUserUtils } import cromwell.pipeline.datastorage.dto._ import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent +import cromwell.pipeline.model.wrapper.ProjectConfigurationId import cromwell.pipeline.service.ProjectConfigurationService.Exceptions.{ InternalError, NotFound, ValidationError } import cromwell.pipeline.service.{ ProjectConfigurationService, VersioningException } import cromwell.pipeline.utils.URLEncoderUtils @@ -46,10 +47,9 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return success for update configuration" in { when(configurationService.addConfiguration(configuration, accessToken.userId)).thenReturn(Future.unit) - Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController - .route( - accessToken - ) ~> check { + Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route( + accessToken + ) ~> check { status shouldBe StatusCodes.NoContent } } @@ -57,10 +57,9 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return InternalServerError when failure update configuration" in { val error = InternalError("Something went wrong") when(configurationService.addConfiguration(configuration, accessToken.userId)).thenReturn(Future.failed(error)) - Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController - .route( - accessToken - ) ~> check { + Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route( + accessToken + ) ~> check { status shouldBe StatusCodes.InternalServerError entityAs[String] shouldBe "Something went wrong" } @@ -69,10 +68,9 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return NotFound when failure find project to update configuration" in { when(configurationService.addConfiguration(configuration, accessToken.userId)) .thenReturn(Future.failed(NotFound())) - Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController - .route( - accessToken - ) ~> check { + Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route( + accessToken + ) ~> check { status shouldBe StatusCodes.NotFound } } @@ -82,7 +80,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return configuration by existing project id" in { when(configurationService.getLastByProjectId(projectId, accessToken.userId)) .thenReturn(Future.successful(configuration)) - Get(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check { + Get(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.OK entityAs[ProjectConfiguration] shouldBe configuration } @@ -90,10 +88,10 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return Configuration not found message" in { when(configurationService.getLastByProjectId(projectId, accessToken.userId)) - .thenReturn(Future.failed(NotFound(s"There is no configuration with project_id: ${projectId.value}"))) - Get(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check { + .thenReturn(Future.failed(NotFound(s"There is no configuration with project_id: $projectId"))) + Get(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.NotFound - entityAs[String] shouldBe s"There is no configuration with project_id: ${projectId.value}" + entityAs[String] shouldBe s"There is no configuration with project_id: $projectId" } } } @@ -103,7 +101,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return success for deactivate configuration" in { when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId)).thenReturn(Future.unit) - Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check { + Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.NoContent } } @@ -111,7 +109,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return InternalServerError when failure deactivate configuration" in { when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId)) .thenReturn(Future.failed(error)) - Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check { + Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError entityAs[String] shouldBe "Something went wrong" } @@ -120,7 +118,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return NotFound when failure find project to deactivate configuration" in { when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId)) .thenReturn(Future.failed(NotFound())) - Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check { + Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.NotFound } } @@ -131,7 +129,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return configuration for file" in { when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId)) .thenReturn(Future.successful(configuration)) - Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~> + Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.OK entityAs[ProjectConfiguration] shouldBe configuration @@ -141,7 +139,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return failed for Bad request" in { when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId)) .thenReturn(Future.failed(VersioningException.HttpException("Bad request"))) - Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~> + Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError entityAs[String] shouldBe "Bad request" @@ -151,7 +149,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit "return failed for invalid file" in { when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId)) .thenReturn(Future.failed(ValidationError(List("invalid some field").mkString(",")))) - Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~> + Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~> configurationController.route(accessToken) ~> check { status shouldBe StatusCodes.UnprocessableEntity entityAs[String] shouldBe "invalid some field" diff --git a/controllers/src/test/scala/cromwell/pipeline/controller/ProjectControllerTest.scala b/controllers/src/test/scala/cromwell/pipeline/controller/ProjectControllerTest.scala index 6cfba2258..ae07d6ab7 100644 --- a/controllers/src/test/scala/cromwell/pipeline/controller/ProjectControllerTest.scala +++ b/controllers/src/test/scala/cromwell/pipeline/controller/ProjectControllerTest.scala @@ -60,7 +60,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo when(projectService.getUserProjectById(dummyProject.projectId, accessToken.userId)) .thenReturn(Future.successful(dummyProject)) - Get(s"/projects/${dummyProject.projectId.value}") ~> projectController.route(accessToken) ~> check { + Get(s"/projects/${dummyProject.projectId}") ~> projectController.route(accessToken) ~> check { status shouldBe StatusCodes.OK responseAs[Project] shouldEqual dummyProject } @@ -72,7 +72,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo when(projectService.getUserProjectById(dummyProject.projectId, accessToken.userId)) .thenReturn(Future.failed(error)) - Get(s"/projects/${dummyProject.projectId.value}") ~> projectController.route(accessToken) ~> check { + Get(s"/projects/${dummyProject.projectId}") ~> projectController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } @@ -131,7 +131,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo projectService.deactivateProjectById(dummyProject.projectId, accessToken.userId) ).thenReturn(Future.successful(deactivatedProject)) - Delete(s"/projects/${dummyProject.projectId.value}") ~> projectController.route(accessToken) ~> check { + Delete(s"/projects/${dummyProject.projectId}") ~> projectController.route(accessToken) ~> check { responseAs[Project] shouldBe deactivatedProject } } @@ -142,7 +142,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo when(projectService.deactivateProjectById(projectId, strangerAccessToken.userId)) .thenReturn(Future.failed(InternalError())) - Delete(s"/projects/${projectId.value}") ~> projectController.route(strangerAccessToken) ~> check { + Delete(s"/projects/${projectId}") ~> projectController.route(strangerAccessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } @@ -155,7 +155,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo when(projectService.updateProjectName(dummyProject.projectId, request, accessToken.userId)) .thenReturn(Future.successful(dummyProject.projectId)) - Put(s"/projects/${dummyProject.projectId.value}", request) ~> projectController.route(accessToken) ~> check { + Put(s"/projects/${dummyProject.projectId}", request) ~> projectController.route(accessToken) ~> check { status shouldBe StatusCodes.OK } } @@ -166,7 +166,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo when(projectService.updateProjectName(dummyProject.projectId, request, strangerAccessToken.userId)) .thenReturn(Future.failed(InternalError())) - Put(s"/projects/${dummyProject.projectId.value}", request) ~> projectController.route(strangerAccessToken) ~> check { + Put(s"/projects/${dummyProject.projectId}", request) ~> projectController.route(strangerAccessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } diff --git a/controllers/src/test/scala/cromwell/pipeline/controller/ProjectFileControllerTest.scala b/controllers/src/test/scala/cromwell/pipeline/controller/ProjectFileControllerTest.scala index 3fc79f2f7..9ede01df1 100644 --- a/controllers/src/test/scala/cromwell/pipeline/controller/ProjectFileControllerTest.scala +++ b/controllers/src/test/scala/cromwell/pipeline/controller/ProjectFileControllerTest.scala @@ -108,7 +108,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate accessToken.userId ) ).thenReturn(Future.successful(Right(()))) - Post(s"/projects/${projectId.value}/files", request) ~> projectFileController.route(accessToken) ~> check { + Post(s"/projects/$projectId/files", request) ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.OK } } @@ -123,7 +123,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate accessToken.userId ) ).thenReturn(Future.successful(Right(()))) - Post(s"/projects/${projectId.value}/files", requestWithoutVersion) ~> projectFileController.route( + Post(s"/projects/$projectId/files", requestWithoutVersion) ~> projectFileController.route( accessToken ) ~> check { status shouldBe StatusCodes.OK @@ -141,7 +141,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate accessToken.userId ) ).thenReturn(Future.successful(Right(()))) - Post(s"/projects/${projectId.value}/files", request) ~> projectFileController.route(accessToken) ~> check { + Post(s"/projects/$projectId/files", request) ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.Created } } @@ -156,7 +156,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate accessToken.userId ) ).thenReturn(Future.successful(Left(VersioningException.HttpException("Bad request")))) - Post(s"/projects/${projectId.value}/files", request) ~> projectFileController.route(accessToken) ~> check { + Post(s"/projects/$projectId/files", request) ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.UnprocessableEntity entityAs[String] shouldBe "File have not uploaded due to Bad request" } @@ -167,7 +167,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate "delete file with status code OK" in { when(projectFileService.deleteFile(dummyProject.projectId, path, versionOption, accessToken.userId)) .thenReturn(Future.successful(Right(()))) - Delete(s"/projects/${projectId.value}/files/$pathEncoded?version=$versionString") ~> + Delete(s"/projects/$projectId/files/$pathEncoded?version=$versionString") ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.OK } @@ -182,7 +182,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate ) ) - Delete(s"/projects/${dummyProject.projectId.value}/files/$pathEncoded?version=$versionString") ~> + Delete(s"/projects/${dummyProject.projectId}/files/$pathEncoded?version=$versionString") ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.BadRequest entityAs[String] shouldBe exceptionMsg @@ -194,7 +194,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate "return files with status code OK" in { when(projectFileService.getFiles(projectId, versionOption, accessToken.userId)) .thenReturn(Future.successful(List(projectFile))) - Get(s"/projects/${projectId.value}/files?version=$versionString") ~> + Get(s"/projects/$projectId/files?version=$versionString") ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.OK entityAs[List[ProjectFile]] shouldBe List(projectFile) @@ -204,7 +204,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate "return files with status code OK without version" in { when(projectFileService.getFiles(projectId, None, accessToken.userId)) .thenReturn(Future.successful(List(projectFile))) - Get(s"/projects/${projectId.value}/files") ~> + Get(s"/projects/$projectId/files") ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.OK entityAs[List[ProjectFile]] shouldBe List(projectFile) @@ -216,7 +216,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate when(projectFileService.getFiles(projectId, None, accessToken.userId)) .thenReturn(Future.failed(versioningException)) - Get(s"/projects/${projectId.value}/files") ~> + Get(s"/projects/$projectId/files") ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.NotFound } @@ -227,7 +227,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate "return file with status code OK" in { when(projectFileService.getFile(projectId, path, versionOption, accessToken.userId)) .thenReturn(Future.successful(projectFile)) - Get(s"/projects/${projectId.value}/files/$pathEncoded?version=$versionString") ~> + Get(s"/projects/$projectId/files/$pathEncoded?version=$versionString") ~> projectFileController.route(accessToken) ~> check { status shouldBe StatusCodes.OK entityAs[ProjectFile] shouldBe projectFile @@ -237,7 +237,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate "return file with status code OK without version" in { when(projectFileService.getFile(projectId, path, None, accessToken.userId)) .thenReturn(Future.successful(projectFile)) - Get(s"/projects/${projectId.value}/files/$pathEncoded") ~> projectFileController.route( + Get(s"/projects/$projectId/files/$pathEncoded") ~> projectFileController.route( accessToken ) ~> check { status shouldBe StatusCodes.OK @@ -250,7 +250,7 @@ class ProjectFileControllerTest extends AsyncWordSpec with Matchers with Scalate when(projectFileService.getFile(projectId, path, versionOption, accessToken.userId)) .thenReturn(Future.failed(versioningException)) - Get(s"/projects/${projectId.value}/files/$pathEncoded?version=$versionString") ~> projectFileController.route( + Get(s"/projects/$projectId/files/$pathEncoded?version=$versionString") ~> projectFileController.route( accessToken ) ~> check { status shouldBe StatusCodes.NotFound diff --git a/controllers/src/test/scala/cromwell/pipeline/controller/RunControllerTest.scala b/controllers/src/test/scala/cromwell/pipeline/controller/RunControllerTest.scala index 3a3a37163..ee5793e3d 100644 --- a/controllers/src/test/scala/cromwell/pipeline/controller/RunControllerTest.scala +++ b/controllers/src/test/scala/cromwell/pipeline/controller/RunControllerTest.scala @@ -40,7 +40,7 @@ class RunControllerTest when(runService.getRunByIdAndUser(runId, projectId, accessToken.userId)) .thenReturn(Future.successful(runRespOption)) - Get(s"/projects/${projectId.value}/runs/$runId") ~> runController.route(accessToken) ~> check { + Get(s"/projects/$projectId/runs/$runId") ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.OK responseAs[Option[Run]] shouldEqual runRespOption } @@ -53,7 +53,7 @@ class RunControllerTest when(runService.getRunByIdAndUser(runId, projectId, accessToken.userId)) .thenReturn(Future.failed(new RuntimeException("something went wrong"))) - Get(s"/projects/${projectId.value}/runs/$runId") ~> runController.route(accessToken) ~> check { + Get(s"/projects/$projectId/runs/$runId") ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } @@ -62,7 +62,7 @@ class RunControllerTest val projectId = TestRunUtils.getDummyProjectId val invalidRunId = "123" - Get(s"/projects/${projectId.value}/runs/$invalidRunId") ~> Route.seal(runController.route(accessToken)) ~> check { + Get(s"/projects/$projectId/runs/$invalidRunId") ~> Route.seal(runController.route(accessToken)) ~> check { status shouldBe StatusCodes.NotFound } } @@ -78,7 +78,7 @@ class RunControllerTest when(runService.getRunsByProject(projectId, accessToken.userId)).thenReturn(Future.successful(runRespSeq)) - Get(s"/projects/${projectId.value}/runs") ~> runController.route(accessToken) ~> check { + Get(s"/projects/$projectId/runs") ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.OK responseAs[Seq[Run]] shouldEqual runRespSeq } @@ -90,7 +90,7 @@ class RunControllerTest when(runService.getRunsByProject(projectId, accessToken.userId)) .thenReturn(Future.failed(new RuntimeException("something went wrong"))) - Get(s"/projects/${projectId.value}/runs") ~> runController.route(accessToken) ~> check { + Get(s"/projects/$projectId/runs") ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } @@ -104,7 +104,7 @@ class RunControllerTest when(runService.deleteRunById(runId, projectId, accessToken.userId)).thenReturn(Future.successful(1)) - Delete(s"/projects/${projectId.value}/runs/$runId") ~> runController.route(accessToken) ~> check { + Delete(s"/projects/$projectId/runs/$runId") ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.OK } } @@ -114,7 +114,7 @@ class RunControllerTest when(runService.deleteRunById(runId, projectId, accessToken.userId)) .thenReturn(Future.failed(new RuntimeException("something went wrong"))) - Delete(s"/projects/${projectId.value}/runs/$runId") ~> runController.route(accessToken) ~> check { + Delete(s"/projects/$projectId/runs/$runId") ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } @@ -124,7 +124,7 @@ class RunControllerTest when(runService.deleteRunById(runId, projectId, accessToken.userId)) .thenReturn(Future.failed(new RuntimeException("Something wrong."))) - Delete(s"/projects/${projectId.value}/runs/$runId") ~> runController.route(accessToken) ~> check { + Delete(s"/projects/$projectId/runs/$runId") ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } @@ -144,7 +144,7 @@ class RunControllerTest ) when(runService.updateRun(runId, request, projectId, accessToken.userId)).thenReturn(Future.successful(1)) - Put(s"/projects/${projectId.value}/runs/$runId", request) ~> runController.route(accessToken) ~> check { + Put(s"/projects/$projectId/runs/$runId", request) ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.NoContent } } @@ -162,7 +162,7 @@ class RunControllerTest ) when(runService.updateRun(runId, request, projectId, accessToken.userId)).thenReturn(Future.successful(1)) - Put(s"/projects/${projectId.value}/runs/$runId", request) ~> runController.route(accessToken) ~> check { + Put(s"/projects/$projectId/runs/$runId", request) ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.NoContent } } @@ -182,7 +182,7 @@ class RunControllerTest when(runService.updateRun(runId, request, projectId, accessToken.userId)) .thenReturn(Future.failed(new RuntimeException("something went wrong"))) - Put(s"/projects/${projectId.value}/runs/$runId", request) ~> runController.route(accessToken) ~> check { + Put(s"/projects/$projectId/runs/$runId", request) ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } @@ -200,7 +200,7 @@ class RunControllerTest ) when(runService.addRun(request, projectId, accessToken.userId)).thenReturn(Future.successful(runId)) - Post(s"/projects/${projectId.value}/runs", request) ~> runController.route(accessToken) ~> check { + Post(s"/projects/$projectId/runs", request) ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.OK responseAs[RunId] shouldEqual runId } @@ -216,7 +216,7 @@ class RunControllerTest when(runService.addRun(request, projectId, accessToken.userId)) .thenReturn(Future.failed(new RuntimeException("something went wrong"))) - Post(s"/projects/${projectId.value}/runs", request) ~> runController.route(accessToken) ~> check { + Post(s"/projects/$projectId/runs", request) ~> runController.route(accessToken) ~> check { status shouldBe StatusCodes.InternalServerError } } diff --git a/docker-compose.yml b/docker-compose.yml index bc5566356..8678acdfb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -55,7 +55,7 @@ services: restart: always environment: GITLAB_OMNIBUS_CONFIG: | -# gitlab_rails['initial_root_password'] = 'initial_root_password' + # gitlab_rails['initial_root_password'] = 'initial_root_password' external_url 'http://localhost:9080' nginx['listen_port'] = 9080 # make nginx to listen on the same port as confgured in external_url # Add any other gitlab.rb configuration here, each on its own line diff --git a/model/src/main/scala/cromwell/pipeline/model/validator/Wrapped.scala b/model/src/main/scala/cromwell/pipeline/model/validator/Wrapped.scala index 05492f58a..71e195020 100644 --- a/model/src/main/scala/cromwell/pipeline/model/validator/Wrapped.scala +++ b/model/src/main/scala/cromwell/pipeline/model/validator/Wrapped.scala @@ -20,6 +20,7 @@ trait Wrapped[T] extends Any { override def hashCode: Int = this.getClass.hashCode + unwrap.hashCode() override def toString: String = unwrap.toString } + object Wrapped { trait Companion { type Type diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/Name.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/Name.scala index 4db9d56b0..cc4472b5f 100644 --- a/model/src/main/scala/cromwell/pipeline/model/wrapper/Name.scala +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/Name.scala @@ -2,8 +2,6 @@ package cromwell.pipeline.model.wrapper import cats.data.{ NonEmptyChain, Validated } import cromwell.pipeline.model.validator.Wrapped -import play.api.libs.json.Format -import cats.implicits.catsStdShowForString final class Name private (override val unwrap: String) extends AnyVal with Wrapped[String] @@ -11,7 +9,6 @@ object Name extends Wrapped.Companion { type Type = String type Wrapper = Name type Error = String - implicit lazy val nameFormat: Format[Name] = wrapperFormat override protected def create(value: String): Name = new Name(value) override protected def validate(value: String): ValidationResult[String] = Validated.cond( diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/Password.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/Password.scala index 1b8686da5..cb15805a4 100644 --- a/model/src/main/scala/cromwell/pipeline/model/wrapper/Password.scala +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/Password.scala @@ -2,8 +2,6 @@ package cromwell.pipeline.model.wrapper import cats.data.{ NonEmptyChain, Validated } import cromwell.pipeline.model.validator.Wrapped -import play.api.libs.json.Format -import cats.implicits.catsStdShowForString import slick.lifted.MappedTo final class Password private (override val unwrap: String) extends AnyVal with Wrapped[String] with MappedTo[String] { @@ -14,7 +12,6 @@ object Password extends Wrapped.Companion { type Type = String type Wrapper = Password type Error = String - implicit lazy val passwordFormat: Format[Password] = wrapperFormat override protected def create(value: String): Password = new Password(value) override protected def validate(value: String): ValidationResult[String] = Validated.cond( value.matches("(?=^.{10,}$)(?=.*\\d)((?=.*\\W+)|(?=.*[_]))(?![.\\n])(?=.*[A-Z])(?=.*[a-z]).*$"), diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectConfigurationId.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectConfigurationId.scala new file mode 100644 index 000000000..920b0acc5 --- /dev/null +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectConfigurationId.scala @@ -0,0 +1,30 @@ +package cromwell.pipeline.model.wrapper + +import cats.data.{ NonEmptyChain, Validated } +import cromwell.pipeline.model.validator.Wrapped +import slick.lifted.MappedTo + +import java.util.UUID + +final class ProjectConfigurationId private (override val unwrap: String) + extends AnyVal + with Wrapped[String] + with MappedTo[String] { + override def value: String = unwrap +} + +object ProjectConfigurationId extends Wrapped.Companion { + type Type = String + type Wrapper = ProjectConfigurationId + type Error = String + + val pattern: String = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" + + override protected def create(value: String): ProjectConfigurationId = new ProjectConfigurationId(value) + + override protected def validate(value: String): ValidationResult[String] = Validated.cond( + value.matches(pattern), + value, + NonEmptyChain.one("Invalid ProjectConfigurationId") + ) +} diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectId.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectId.scala new file mode 100644 index 000000000..20f70edbc --- /dev/null +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectId.scala @@ -0,0 +1,29 @@ +package cromwell.pipeline.model.wrapper + +import cats.data.{ NonEmptyChain, Validated } +import cromwell.pipeline.model.validator.Wrapped +import slick.lifted.MappedTo + +import java.util.UUID.randomUUID + +final class ProjectId private (override val unwrap: String) extends AnyVal with Wrapped[String] with MappedTo[String] { + override def value: String = unwrap +} + +object ProjectId extends Wrapped.Companion { + type Type = String + type Wrapper = ProjectId + type Error = String + + val pattern: String = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" + + override protected def create(value: String): ProjectId = new ProjectId(value) + + override protected def validate(value: String): ValidationResult[String] = Validated.cond( + value.matches(pattern), + value, + NonEmptyChain.one("Invalid ProjectId") + ) + + def random: ProjectId = new ProjectId(randomUUID().toString) +} diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectSearchFilterId.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectSearchFilterId.scala index 24d6cea6f..a6fd3d0db 100644 --- a/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectSearchFilterId.scala +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/ProjectSearchFilterId.scala @@ -2,7 +2,6 @@ package cromwell.pipeline.model.wrapper import cats.data.{ NonEmptyChain, Validated } import cromwell.pipeline.model.validator.Wrapped -import play.api.libs.json.Format final class ProjectSearchFilterId private (override val unwrap: String) extends AnyVal with Wrapped[String] @@ -11,7 +10,6 @@ object ProjectSearchFilterId extends Wrapped.Companion { type Wrapper = ProjectSearchFilterId type Error = String val pattern: String = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" - implicit lazy val projectSearchIdFormat: Format[ProjectSearchFilterId] = wrapperFormat override protected def create(value: String): ProjectSearchFilterId = new ProjectSearchFilterId(value) override protected def validate(value: String): ValidationResult[String] = Validated.cond( value.matches(pattern), diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/RepositoryId.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/RepositoryId.scala new file mode 100644 index 000000000..93d11802f --- /dev/null +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/RepositoryId.scala @@ -0,0 +1,22 @@ +package cromwell.pipeline.model.wrapper + +import cats.data.{ NonEmptyChain, Validated } +import cromwell.pipeline.model.validator.Wrapped +import slick.lifted.MappedTo + +final case class RepositoryId(override val unwrap: Int) extends AnyVal with MappedTo[Int] with Wrapped[Int] { + override def value: Int = unwrap +} + +object RepositoryId extends Wrapped.Companion { + type Type = Int + type Wrapper = RepositoryId + type Error = String + + override protected def create(value: Int): RepositoryId = new RepositoryId(value) + override protected def validate(value: Int): ValidationResult[Int] = Validated.cond( + value >= 0, + value, + NonEmptyChain.one("Value should be not negative integer") + ) +} diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/RunId.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/RunId.scala index bc94096eb..2392390be 100644 --- a/model/src/main/scala/cromwell/pipeline/model/wrapper/RunId.scala +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/RunId.scala @@ -1,9 +1,7 @@ package cromwell.pipeline.model.wrapper import cats.data.{ NonEmptyChain, Validated } -import cats.implicits.catsStdShowForString import cromwell.pipeline.model.validator.Wrapped -import play.api.libs.json.Format final class RunId private (override val unwrap: String) extends AnyVal with Wrapped[String] @@ -12,7 +10,6 @@ object RunId extends Wrapped.Companion { type Wrapper = RunId type Error = String val pattern: String = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" - implicit lazy val runIdFormat: Format[RunId] = wrapperFormat override protected def create(value: String): RunId = new RunId(value) override protected def validate(value: String): ValidationResult[String] = Validated.cond( value.matches(pattern), diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/UserEmail.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/UserEmail.scala index 570948343..c9cfe7f83 100644 --- a/model/src/main/scala/cromwell/pipeline/model/wrapper/UserEmail.scala +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/UserEmail.scala @@ -2,8 +2,6 @@ package cromwell.pipeline.model.wrapper import cats.data.{ NonEmptyChain, Validated } import cromwell.pipeline.model.validator.Wrapped -import play.api.libs.json.Format -import cats.implicits.catsStdShowForString final class UserEmail private (override val unwrap: String) extends AnyVal with Wrapped[String] @@ -11,7 +9,6 @@ object UserEmail extends Wrapped.Companion { type Type = String type Wrapper = UserEmail type Error = String - implicit lazy val userEmailFormat: Format[UserEmail] = wrapperFormat override protected def create(value: String): UserEmail = new UserEmail(value) override protected def validate(value: String): ValidationResult[String] = Validated.cond( value.matches( diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/UserId.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/UserId.scala index 9c9f2dd5c..76f66e24b 100644 --- a/model/src/main/scala/cromwell/pipeline/model/wrapper/UserId.scala +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/UserId.scala @@ -2,8 +2,6 @@ package cromwell.pipeline.model.wrapper import cats.data.{ NonEmptyChain, Validated } import cromwell.pipeline.model.validator.Wrapped -import play.api.libs.json.Format -import cats.implicits.catsStdShowForString final class UserId private (override val unwrap: String) extends AnyVal with Wrapped[String] @@ -12,7 +10,6 @@ object UserId extends Wrapped.Companion { type Wrapper = UserId type Error = String val pattern: String = "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$" - implicit lazy val userIdFormat: Format[UserId] = wrapperFormat override protected def create(value: String): UserId = new UserId(value) override protected def validate(value: String): ValidationResult[String] = Validated.cond( value.matches(pattern), diff --git a/model/src/main/scala/cromwell/pipeline/model/wrapper/VersionValue.scala b/model/src/main/scala/cromwell/pipeline/model/wrapper/VersionValue.scala index 7e710a94c..8533e9e5d 100644 --- a/model/src/main/scala/cromwell/pipeline/model/wrapper/VersionValue.scala +++ b/model/src/main/scala/cromwell/pipeline/model/wrapper/VersionValue.scala @@ -1,9 +1,7 @@ package cromwell.pipeline.model.wrapper import cats.data.{ NonEmptyChain, Validated } -import cats.implicits.catsStdShowForString import cromwell.pipeline.model.validator.Wrapped -import play.api.libs.json.Format final class VersionValue private (override val unwrap: Int) extends AnyVal with Wrapped[Int] @@ -12,7 +10,6 @@ object VersionValue extends Wrapped.Companion { type Wrapper = VersionValue type Error = String val pattern = "^[0-9]+$" - implicit val versionNumberFormat: Format[VersionValue] = wrapperFormat def increment(value: VersionValue): VersionValue = create(value.unwrap + 1) def resetValue: VersionValue = create(0) def fromString(value: String): ValidationResult[Wrapper] = diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/DatastorageModule.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/DatastorageModule.scala index 3be12a3e0..25ea4800e 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/DatastorageModule.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/DatastorageModule.scala @@ -44,6 +44,12 @@ trait Profile { implicit def uuidIso: Isomorphism[UserId, String] = iso[UserId, String](_.unwrap, UserId(_, Enable.Unsafe)) implicit def runidIso: Isomorphism[RunId, String] = iso[RunId, String](_.unwrap, RunId(_, Enable.Unsafe)) + implicit def projectidIso: Isomorphism[ProjectId, String] = + iso[ProjectId, String](_.unwrap, ProjectId(_, Enable.Unsafe)) + implicit def projectConfigurationIdIso: Isomorphism[ProjectConfigurationId, String] = + iso[ProjectConfigurationId, String](_.unwrap, ProjectConfigurationId(_, Enable.Unsafe)) + implicit def repositoryId: Isomorphism[RepositoryId, Int] = + iso[RepositoryId, Int](_.unwrap, RepositoryId(_, Enable.Unsafe)) implicit def filteridIso: Isomorphism[ProjectSearchFilterId, String] = iso[ProjectSearchFilterId, String](_.unwrap, ProjectSearchFilterId(_, Enable.Unsafe)) implicit def searchQueryIso: Isomorphism[ProjectSearchQuery, JsValue] = diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/ProjectEntry.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/ProjectEntry.scala index b35872bda..c0bc77903 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/ProjectEntry.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/ProjectEntry.scala @@ -2,8 +2,7 @@ package cromwell.pipeline.datastorage.dao.entry import cromwell.pipeline.datastorage.Profile import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId -import slick.lifted.MappedToBase.mappedToIsomorphism +import cromwell.pipeline.model.wrapper.{ ProjectId, RepositoryId, UserId } import slick.lifted.{ ForeignKeyQuery, ProvenShape } trait ProjectEntry { this: Profile with UserEntry with MyPostgresProfile with AliasesSupport => diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/RunEntry.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/RunEntry.scala index d6f16ce45..dd4c172de 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/RunEntry.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/entry/RunEntry.scala @@ -4,7 +4,7 @@ import java.time.Instant import cromwell.pipeline.datastorage.Profile import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.{ RunId, UserId } +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId, UserId } import slick.lifted.{ ForeignKeyQuery, ProvenShape } trait RunEntry { this: Profile with UserEntry with ProjectEntry with MyPostgresProfile with AliasesSupport => diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepository.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepository.scala index 189c1d607..ff6bbda51 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepository.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepository.scala @@ -2,7 +2,8 @@ package cromwell.pipeline.datastorage.dao.repository import cromwell.pipeline.datastorage.dao.mongo.DocumentCodecInstances.projectConfigurationDocumentCodec import cromwell.pipeline.datastorage.dao.mongo.DocumentRepository -import cromwell.pipeline.datastorage.dto.{ ProjectConfiguration, ProjectConfigurationId, ProjectId } +import cromwell.pipeline.datastorage.dto.ProjectConfiguration +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId } import scala.concurrent.{ ExecutionContext, Future } diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectRepository.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectRepository.scala index 094d8c77e..c0d72537a 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectRepository.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/ProjectRepository.scala @@ -2,8 +2,8 @@ package cromwell.pipeline.datastorage.dao.repository import cromwell.pipeline.database.PipelineDatabaseEngine import cromwell.pipeline.datastorage.dao.entry.ProjectEntry -import cromwell.pipeline.datastorage.dto.{ Project, ProjectId } -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.datastorage.dto.Project +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } import scala.concurrent.Future diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/RunRepository.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/RunRepository.scala index d018d979c..88d8511fd 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/RunRepository.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dao/repository/RunRepository.scala @@ -2,8 +2,8 @@ package cromwell.pipeline.datastorage.dao.repository import cromwell.pipeline.database.PipelineDatabaseEngine import cromwell.pipeline.datastorage.dao.entry.RunEntry -import cromwell.pipeline.datastorage.dto.{ ProjectId, Run } -import cromwell.pipeline.model.wrapper.{ RunId, UserId } +import cromwell.pipeline.datastorage.dto.Run +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId, UserId } import scala.concurrent.Future diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/CromwellInput.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/CromwellInput.scala index 33ec2a684..581f38beb 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/CromwellInput.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/CromwellInput.scala @@ -1,6 +1,6 @@ package cromwell.pipeline.datastorage.dto -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } final case class CromwellInput( projectId: ProjectId, diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Project.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Project.scala index 72838169a..e376194cb 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Project.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Project.scala @@ -2,12 +2,12 @@ package cromwell.pipeline.datastorage.dto import cats.data.Validated import cats.implicits._ -import cromwell.pipeline.model.wrapper.{ UserId, VersionValue } +import cromwell.pipeline.model.wrapper.{ ProjectId, RepositoryId, UserId, VersionValue } import play.api.libs.functional.syntax._ import play.api.libs.json.JsonNaming.SnakeCase import play.api.libs.json._ + import java.nio.file.{ Path, Paths } -import slick.lifted.MappedTo // scalastyle:off number.of.types final case class Project( projectId: ProjectId, @@ -18,6 +18,7 @@ final case class Project( version: PipelineVersion, visibility: Visibility = Private ) + object Project { implicit lazy val projectFormat: OFormat[Project] = Json.format[Project] } @@ -41,25 +42,12 @@ final case class LocalProject( ) } -final case class PostProject(name: String) +final case class PostProject(name: ProjectId) object PostProject { implicit lazy val postProject: OFormat[PostProject] = Json.format[PostProject] } -final case class ProjectId(value: String) extends MappedTo[String] - -object ProjectId { - implicit lazy val projectIdFormat: Format[ProjectId] = implicitly[Format[String]].inmap(ProjectId.apply, _.value) -} - -final case class RepositoryId(value: Int) extends MappedTo[Int] - -object RepositoryId { - implicit lazy val repositoryIdFormat: Format[RepositoryId] = - implicitly[Format[Int]].inmap(RepositoryId.apply, _.value) -} - final case class ProjectAdditionRequest(name: String) object ProjectAdditionRequest { diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectConfiguration.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectConfiguration.scala index 8a795d06d..77bfff138 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectConfiguration.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectConfiguration.scala @@ -1,13 +1,12 @@ package cromwell.pipeline.datastorage.dto import cats.data.Validated -import cromwell.pipeline.model.wrapper.VersionValue +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId, VersionValue } import ProjectFile.pathFormat import play.api.libs.functional.syntax.toInvariantFunctorOps import play.api.libs.json.{ Format, Json, OFormat } import java.nio.file.Path -import java.util.UUID case class WdlParams(path: Path, inputs: List[FileParameter]) @@ -54,14 +53,6 @@ object ProjectConfigurationVersion { implicitly[Format[String]].inmap(ProjectConfigurationVersion.apply, _.name) } -final case class ProjectConfigurationId(value: String) - -object ProjectConfigurationId { - def randomId: ProjectConfigurationId = ProjectConfigurationId(UUID.randomUUID().toString) - implicit lazy val configurationIdFormat: Format[ProjectConfigurationId] = - implicitly[Format[String]].inmap(ProjectConfigurationId.apply, _.value) -} - final case class ProjectConfigurationAdditionRequest( id: ProjectConfigurationId, active: Boolean, diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectResponse.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectResponse.scala index d8420e2ec..70711bc38 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectResponse.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/ProjectResponse.scala @@ -1,5 +1,6 @@ package cromwell.pipeline.datastorage.dto +import cromwell.pipeline.model.wrapper.ProjectId import play.api.libs.json.{ Json, OFormat } final case class ProjectResponse(projectId: ProjectId, name: String, active: Boolean) diff --git a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Run.scala b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Run.scala index 6452225e4..8ed28798d 100644 --- a/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Run.scala +++ b/repositories/src/main/scala/cromwell/pipeline/datastorage/dto/Run.scala @@ -1,6 +1,6 @@ package cromwell.pipeline.datastorage.dto -import cromwell.pipeline.model.wrapper.{ RunId, UserId } +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId, UserId } import play.api.libs.functional.syntax._ import play.api.libs.json._ diff --git a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepositoryTest.scala b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepositoryTest.scala index f387fdff5..e7f1a58dc 100644 --- a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepositoryTest.scala +++ b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/ProjectConfigurationRepositoryTest.scala @@ -1,11 +1,11 @@ package cromwell.pipeline.datastorage.dao.repository import java.nio.file.Paths - import cromwell.pipeline.datastorage.dao.mongo.DocumentCodecInstances.projectConfigurationDocumentCodec import cromwell.pipeline.datastorage.dao.mongo.DocumentRepository import cromwell.pipeline.datastorage.dao.utils.TestProjectUtils import cromwell.pipeline.datastorage.dto._ +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId } import org.mockito.Mockito.when import org.scalatest.{ AsyncWordSpec, Matchers } import org.scalatestplus.mockito.MockitoSugar diff --git a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectConfigurationRepositoryTestImpl.scala b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectConfigurationRepositoryTestImpl.scala index 4da4bd128..c36d6f22e 100644 --- a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectConfigurationRepositoryTestImpl.scala +++ b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectConfigurationRepositoryTestImpl.scala @@ -1,7 +1,8 @@ package cromwell.pipeline.datastorage.dao.repository.impls import cromwell.pipeline.datastorage.dao.repository.ProjectConfigurationRepository -import cromwell.pipeline.datastorage.dto.{ ProjectConfiguration, ProjectConfigurationId, ProjectId } +import cromwell.pipeline.datastorage.dto.ProjectConfiguration +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId } import scala.collection.mutable import scala.concurrent.Future diff --git a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectRepositoryTestImpl.scala b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectRepositoryTestImpl.scala index c21dffd46..265dd0d07 100644 --- a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectRepositoryTestImpl.scala +++ b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/ProjectRepositoryTestImpl.scala @@ -1,8 +1,8 @@ package cromwell.pipeline.datastorage.dao.repository.impls import cromwell.pipeline.datastorage.dao.repository.ProjectRepository -import cromwell.pipeline.datastorage.dto.{ Project, ProjectId } -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.datastorage.dto.Project +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } import scala.collection.mutable import scala.concurrent.Future diff --git a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/RunRepositoryTestImpl.scala b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/RunRepositoryTestImpl.scala index ecc73a539..b5f03bcfb 100644 --- a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/RunRepositoryTestImpl.scala +++ b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/repository/impls/RunRepositoryTestImpl.scala @@ -1,8 +1,8 @@ package cromwell.pipeline.datastorage.dao.repository.impls import cromwell.pipeline.datastorage.dao.repository.RunRepository -import cromwell.pipeline.datastorage.dto.{ ProjectId, Run } -import cromwell.pipeline.model.wrapper.{ RunId, UserId } +import cromwell.pipeline.datastorage.dto.Run +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId, UserId } import scala.collection.mutable import scala.concurrent.Future diff --git a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/GeneratorUtils.scala b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/GeneratorUtils.scala index 9b6fd8e4d..b14187017 100644 --- a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/GeneratorUtils.scala +++ b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/GeneratorUtils.scala @@ -20,10 +20,10 @@ object GeneratorUtils { private def listOfN[T](gen: Gen[T], maxLength: Int = defaultListMaxLength): Gen[List[T]] = Gen.chooseNum(0, maxLength).flatMap(length => Gen.listOfN(length, gen)) - private lazy val projectIdGen: Gen[ProjectId] = Gen.uuid.map(id => ProjectId(id.toString)) + private lazy val projectIdGen: Gen[ProjectId] = Gen.uuid.map(id => ProjectId(id.toString, Enable.Unsafe)) private lazy val projectConfigurationIdGen: Gen[ProjectConfigurationId] = - Gen.uuid.map(id => ProjectConfigurationId(id.toString)) + Gen.uuid.map(id => ProjectConfigurationId(id.toString, Enable.Unsafe)) private lazy val emailGen: Gen[UserEmail] = for { name <- stringGen() diff --git a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestProjectUtils.scala b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestProjectUtils.scala index b713d19e6..202eda464 100644 --- a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestProjectUtils.scala +++ b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestProjectUtils.scala @@ -1,7 +1,8 @@ package cromwell.pipeline.datastorage.dao.utils import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.validator.Enable +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId, RepositoryId, UserId } import java.nio.file.Paths import java.util.UUID @@ -12,8 +13,8 @@ object TestProjectUtils { private val defaultRange: Int = 100 private def randomInt(range: Int = defaultRange): Int = Random.nextInt(range) private def randomUuidStr: String = UUID.randomUUID().toString - def getDummyProjectId: ProjectId = ProjectId(randomUuidStr) - def getDummyRepositoryId: RepositoryId = RepositoryId(randomInt()) + def getDummyProjectId: ProjectId = ProjectId(randomUuidStr, Enable.Unsafe) + def getDummyRepositoryId: RepositoryId = RepositoryId(randomInt(), Enable.Unsafe) def getDummyProject( projectId: ProjectId = getDummyProjectId, ownerId: UserId = TestUserUtils.getDummyUserId, diff --git a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestRunUtils.scala b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestRunUtils.scala index d8130e5f2..52d079a1d 100644 --- a/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestRunUtils.scala +++ b/repositories/src/test/scala/cromwell/pipeline/datastorage/dao/utils/TestRunUtils.scala @@ -2,14 +2,13 @@ package cromwell.pipeline.datastorage.dao.utils import java.time.Instant import java.util.UUID - -import cromwell.pipeline.datastorage.dto.{ Created, ProjectId, Run, Status } -import cromwell.pipeline.model.wrapper.{ RunId, UserId } +import cromwell.pipeline.datastorage.dto.{ Created, Run, Status } +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId, UserId } object TestRunUtils { private def randomUuidStr: String = UUID.randomUUID().toString - def getDummyProjectId: ProjectId = ProjectId(randomUuidStr) + def getDummyProjectId: ProjectId = ProjectId.random def getDummyRunId: RunId = RunId.random def getDummyTimeStart: Instant = Instant.now() def getDummyTimeEnd(isEmpty: Boolean): Option[Instant] = diff --git a/services/src/main/scala/cromwell/pipeline/service/AggregationService.scala b/services/src/main/scala/cromwell/pipeline/service/AggregationService.scala index 110e9d100..5bdedce96 100644 --- a/services/src/main/scala/cromwell/pipeline/service/AggregationService.scala +++ b/services/src/main/scala/cromwell/pipeline/service/AggregationService.scala @@ -3,7 +3,8 @@ package cromwell.pipeline.service import cats.data.EitherT import cats.implicits._ import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } + import scala.concurrent.{ ExecutionContext, Future } trait AggregationService { diff --git a/services/src/main/scala/cromwell/pipeline/service/GitLabProjectVersioning.scala b/services/src/main/scala/cromwell/pipeline/service/GitLabProjectVersioning.scala index 03978deaa..82db295ee 100644 --- a/services/src/main/scala/cromwell/pipeline/service/GitLabProjectVersioning.scala +++ b/services/src/main/scala/cromwell/pipeline/service/GitLabProjectVersioning.scala @@ -4,6 +4,7 @@ import cats.data.EitherT import cats.implicits.toTraverseOps import cromwell.pipeline.datastorage.dto.File.{ DeleteFileRequest, UpdateFileRequest } import cromwell.pipeline.datastorage.dto._ +import cromwell.pipeline.model.wrapper.RepositoryId import cromwell.pipeline.service.VersioningException._ import cromwell.pipeline.utils.HttpStatusCodes.{ Accepted, NoContent, OK } import cromwell.pipeline.utils.{ GitLabConfig, URLEncoderUtils } @@ -19,7 +20,7 @@ class GitLabProjectVersioning(httpClient: HttpClient, config: GitLabConfig)(impl Future.failed(RepositoryException("Could not create a repository for deleted project.")) } else { val createRepoUrl: String = s"${config.url}projects" - val postProject = PostProject(name = localProject.projectId.value) + val postProject = PostProject(name = localProject.projectId) httpClient .post[GitLabRepositoryResponse, PostProject](url = createRepoUrl, headers = config.token, payload = postProject) .map { @@ -42,7 +43,7 @@ class GitLabProjectVersioning(httpClient: HttpClient, config: GitLabConfig)(impl ): AsyncResult[PipelineVersion] = { val path = URLEncoderUtils.encode(projectFile.path.toString) val repositoryId: RepositoryId = project.repositoryId - val fileUrl = s"${config.url}projects/${repositoryId.value}/repository/files/$path" + val fileUrl = s"${config.url}projects/${repositoryId}/repository/files/$path" getUpdatedProjectVersion(project, version).flatMap { case l @ Left(_) => Future.successful(l) @@ -171,7 +172,7 @@ class GitLabProjectVersioning(httpClient: HttpClient, config: GitLabConfig)(impl createTag(repositoryId, version).map(_.map(_ => version)) private def createTag(repositoryId: RepositoryId, version: PipelineVersion): AsyncResult[SuccessResponseMessage] = { - val tagUrl = s"${config.url}projects/${repositoryId.value}/repository/tags" + val tagUrl = s"${config.url}projects/${repositoryId}/repository/tags" httpClient .post[SuccessResponseMessage, EmptyPayload]( tagUrl, @@ -193,7 +194,7 @@ class GitLabProjectVersioning(httpClient: HttpClient, config: GitLabConfig)(impl case None => Map() } val filesTreeUrl: String = - s"${config.url}projects/${project.repositoryId.value}/repository/tree" + s"${config.url}projects/${project.repositoryId}/repository/tree" httpClient .get[List[FileTree]](url = filesTreeUrl, params = versionId, headers = config.token) diff --git a/services/src/main/scala/cromwell/pipeline/service/ProjectConfigurationService.scala b/services/src/main/scala/cromwell/pipeline/service/ProjectConfigurationService.scala index 9e1717177..88dd94c3e 100644 --- a/services/src/main/scala/cromwell/pipeline/service/ProjectConfigurationService.scala +++ b/services/src/main/scala/cromwell/pipeline/service/ProjectConfigurationService.scala @@ -2,7 +2,7 @@ package cromwell.pipeline.service import cromwell.pipeline.datastorage.dao.repository.ProjectConfigurationRepository import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId, UserId } import cromwell.pipeline.service.ProjectConfigurationService.Exceptions.{ AccessDenied, InternalError, @@ -143,7 +143,7 @@ object ProjectConfigurationService { Future.failed(InternalError(s"Failed to $action due to unexpected internal error")) private def notFoundProjectError(projectId: ProjectId) = - Future.failed(NotFound(s"There is no configuration with project_id: ${projectId.value}")) + Future.failed(NotFound(s"There is no configuration with project_id: $projectId")) private def serviceErrorMapper(exc: ProjectServiceException): Future[Nothing] = exc match { diff --git a/services/src/main/scala/cromwell/pipeline/service/ProjectFileService.scala b/services/src/main/scala/cromwell/pipeline/service/ProjectFileService.scala index 348ce26e3..6f2be8ff2 100644 --- a/services/src/main/scala/cromwell/pipeline/service/ProjectFileService.scala +++ b/services/src/main/scala/cromwell/pipeline/service/ProjectFileService.scala @@ -1,7 +1,7 @@ package cromwell.pipeline.service import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } import cromwell.pipeline.womtool.WomToolAPI import java.nio.file.Path diff --git a/services/src/main/scala/cromwell/pipeline/service/ProjectService.scala b/services/src/main/scala/cromwell/pipeline/service/ProjectService.scala index 7bf5bb9e2..bba0d9b74 100644 --- a/services/src/main/scala/cromwell/pipeline/service/ProjectService.scala +++ b/services/src/main/scala/cromwell/pipeline/service/ProjectService.scala @@ -2,11 +2,10 @@ package cromwell.pipeline.service import cromwell.pipeline.datastorage.dao.repository.ProjectRepository import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } import cromwell.pipeline.service.ProjectService.Exceptions._ import cromwell.pipeline.service.exceptions.ServiceException -import java.util.UUID import scala.concurrent.{ ExecutionContext, Future } trait ProjectService { @@ -74,7 +73,7 @@ object ProjectService { def addProject(request: ProjectAdditionRequest, userId: UserId): Future[Project] = { val localProject = LocalProject( - projectId = ProjectId(UUID.randomUUID().toString), + projectId = ProjectId.random, ownerId = userId, name = request.name, active = true diff --git a/services/src/main/scala/cromwell/pipeline/service/RunService.scala b/services/src/main/scala/cromwell/pipeline/service/RunService.scala index a4399ee81..68d2454b6 100644 --- a/services/src/main/scala/cromwell/pipeline/service/RunService.scala +++ b/services/src/main/scala/cromwell/pipeline/service/RunService.scala @@ -2,7 +2,7 @@ package cromwell.pipeline.service import cromwell.pipeline.datastorage.dao.repository.RunRepository import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.{ RunId, UserId } +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId, UserId } import cromwell.pipeline.service.ProjectService.Exceptions.ProjectServiceException import cromwell.pipeline.service.RunService.Exceptions._ import cromwell.pipeline.service.exceptions.ServiceException diff --git a/services/src/test/scala/cromwell/pipeline/service/AggregationServiceTest.scala b/services/src/test/scala/cromwell/pipeline/service/AggregationServiceTest.scala index 307af6929..45b453299 100644 --- a/services/src/test/scala/cromwell/pipeline/service/AggregationServiceTest.scala +++ b/services/src/test/scala/cromwell/pipeline/service/AggregationServiceTest.scala @@ -2,6 +2,7 @@ package cromwell.pipeline.service import cromwell.pipeline.datastorage.dao.utils.{ TestProjectUtils, TestRunUtils, TestUserUtils } import cromwell.pipeline.datastorage.dto._ +import cromwell.pipeline.model.wrapper.ProjectConfigurationId import cromwell.pipeline.service.ProjectService.Exceptions.NotFound import cromwell.pipeline.service.impls.{ ProjectConfigurationServiceTestImpl, @@ -75,12 +76,12 @@ class AggregationServiceTest extends AsyncWordSpec with Matchers { "should return exception if configuration not found" taggedAs Service in { val emptyProjectConfigurationService = ProjectConfigurationServiceTestImpl.withException( - NotFound(s"Configurations for projectId ${projectId.value} not found") + NotFound(s"Configurations for projectId $projectId not found") ) val aggregatorService = createAggregationService(projectConfigurationService = emptyProjectConfigurationService) aggregatorService.aggregate(run).failed.map { - _ should have.message(s"Configurations for projectId ${projectId.value} not found") + _ should have.message(s"Configurations for projectId $projectId not found") } } diff --git a/services/src/test/scala/cromwell/pipeline/service/GitLabProjectVersioningTest.scala b/services/src/test/scala/cromwell/pipeline/service/GitLabProjectVersioningTest.scala index fba36be3b..0654f9960 100644 --- a/services/src/test/scala/cromwell/pipeline/service/GitLabProjectVersioningTest.scala +++ b/services/src/test/scala/cromwell/pipeline/service/GitLabProjectVersioningTest.scala @@ -41,7 +41,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki def configureGetVersions( versions: List[GitLabVersion], - tagUrl: String = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId.value}/repository/tags" + tagUrl: String = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId}/repository/tags" ): Unit = when { mockHttpClient.get[List[GitLabVersion]]( @@ -72,7 +72,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki def configureCreateTag( version: PipelineVersion, response: SuccessResponseMessage, - tagUrl: String = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId.value}/repository/tags" + tagUrl: String = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId}/repository/tags" ): Unit = when { mockHttpClient.post[SuccessResponseMessage, EmptyPayload]( @@ -88,7 +88,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki "deleteFile" should { val path = URLEncoderUtils.encode(existFile.path.toString) - val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId.value}/repository/files/$path" + val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId}/repository/files/$path" val gitlabVersion = TestProjectUtils.getDummyGitLabVersion(dummyPipelineVersion) val payload = DeleteFileRequest( s"Deleting file ${existFile.path} from repository: ${projectWithRepo.name}", @@ -196,14 +196,14 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki "updateFile" should { val successCreateMessage = "File was created" - val tagUrl = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId.value}/repository/tags" + val tagUrl = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId}/repository/tags" val gitlabVersion = TestProjectUtils.getDummyGitLabVersion(dummyPipelineVersion) val gitlabVersionHigher = TestProjectUtils.getDummyGitLabVersion(dummyPipelineVersionHigher) "succeed when file is new" taggedAs Service in { val payload = UpdateFileRequest(newFile.content, dummyPipelineVersionHigher.name, gitLabConfig.defaultBranch) val path = URLEncoderUtils.encode(newFile.path.toString) - val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId.value}/repository/files/$path" + val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId}/repository/files/$path" val putResponse = Response[UpdateFileResponse]( @@ -232,7 +232,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki "succeed when file already exists" taggedAs Service in { val payload = UpdateFileRequest(existFile.content, dummyPipelineVersionHigher.name, gitLabConfig.defaultBranch) val path = URLEncoderUtils.encode(existFile.path.toString) - val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId.value}/repository/files/$path" + val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId}/repository/files/$path" val putResponse = Response[UpdateFileResponse]( StatusCodes.OK.intValue, @@ -253,7 +253,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki val updatedVersion = dummyPipelineVersion.increaseRevision val payload = UpdateFileRequest(existFile.content, updatedVersion.name, gitLabConfig.defaultBranch) val path = URLEncoderUtils.encode(existFile.path.toString) - val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId.value}/repository/files/$path" + val url = s"${gitLabConfig.url}projects/${projectWithRepo.repositoryId}/repository/files/$path" val putResponse = Response[UpdateFileResponse]( StatusCodes.OK.intValue, @@ -304,7 +304,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki val encodedPathStr = URLEncoderUtils.encode(path.toString) when { mockHttpClient.get[GitLabFileContent]( - s"${gitLabConfig.url}projects/${activeProject.repositoryId.value}/repository/files/$encodedPathStr", + s"${gitLabConfig.url}projects/${activeProject.repositoryId}/repository/files/$encodedPathStr", Map("ref" -> dummyPipelineVersion.name), gitLabConfig.token ) @@ -328,7 +328,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki val encodedPathStr = URLEncoderUtils.encode(path.toString) when { mockHttpClient.get[GitLabFileContent]( - s"${gitLabConfig.url}projects/${activeProject.repositoryId.value}/repository/files/$encodedPathStr", + s"${gitLabConfig.url}projects/${activeProject.repositoryId}/repository/files/$encodedPathStr", Map("ref" -> dummyPipelineVersion.name), gitLabConfig.token ) @@ -356,7 +356,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki case None => Map() } mockHttpClient.get[List[FileTree]]( - url = exact(s"${gitLabConfig.url}projects/${project.repositoryId.value}/repository/tree"), + url = exact(s"${gitLabConfig.url}projects/${project.repositoryId}/repository/tree"), params = exact(versionId), headers = exact(gitLabConfig.token) )(ec = any[ExecutionContext], f = any[Reads[List[FileTree]]]) @@ -368,14 +368,14 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki version: Option[PipelineVersion] ): Future[Response[GitLabFileContent]] = mockHttpClient.get[GitLabFileContent]( - exact(s"${gitLabConfig.url}projects/${project.repositoryId.value}/repository/files/$filePath"), + exact(s"${gitLabConfig.url}projects/${project.repositoryId}/repository/files/$filePath"), exact(Map("ref" -> version.map(_.name).getOrElse(project.version.name))), exact(gitLabConfig.token) )(ec = any[ExecutionContext], f = any[Reads[GitLabFileContent]]) def getGitLabProjectVersions(project: Project): Future[Response[List[GitLabVersion]]] = mockHttpClient.get[List[GitLabVersion]]( - exact(s"${gitLabConfig.url}projects/${project.repositoryId.value}/repository/tags"), + exact(s"${gitLabConfig.url}projects/${project.repositoryId}/repository/tags"), any[Map[String, String]], exact(gitLabConfig.token) )(ec = any[ExecutionContext], f = any[Reads[List[GitLabVersion]]]) @@ -428,7 +428,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki } when { mockHttpClient.get[GitLabFileContent]( - s"${gitLabConfig.url}projects/${activeProject.repositoryId.value}/repository/files/$encodedPathStr", + s"${gitLabConfig.url}projects/${activeProject.repositoryId}/repository/files/$encodedPathStr", Map("ref" -> dummyPipelineVersion.name), gitLabConfig.token ) @@ -447,7 +447,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki "getProjectVersions" should { def getProjectVersions(project: Project): Future[Response[Seq[GitLabVersion]]] = mockHttpClient.get[Seq[GitLabVersion]]( - url = exact(gitLabConfig.url + "projects/" + project.repositoryId.value + "/repository/tags"), + url = exact(gitLabConfig.url + "projects/" + project.repositoryId + "/repository/tags"), headers = any[Map[String, String]], params = any[Map[String, String]] )(any[ExecutionContext], any[Reads[Seq[GitLabVersion]]]) @@ -493,7 +493,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki def getFileVersions(project: Project): Future[Response[Seq[GLFileCommitInfo]]] = mockHttpClient.get[Seq[GLFileCommitInfo]]( - url = exact(s"${gitLabConfig.url}projects/${project.repositoryId.value}/repository/commits"), + url = exact(s"${gitLabConfig.url}projects/${project.repositoryId}/repository/commits"), params = exact(Map("path" -> urlEncoder)), headers = exact(gitLabConfig.token) )(ec = any[ExecutionContext], f = any[Reads[Seq[GLFileCommitInfo]]]) @@ -539,7 +539,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki def getFileCommits(project: Project): Future[Response[List[GLFileCommitInfo]]] = mockHttpClient.get[List[GLFileCommitInfo]]( - url = exact(s"${gitLabConfig.url}projects/${project.repositoryId.value}/repository/commits"), + url = exact(s"${gitLabConfig.url}projects/${project.repositoryId}/repository/commits"), params = exact(Map("path" -> urlEncoder)), headers = exact(gitLabConfig.token) )(ec = any[ExecutionContext], f = any[Reads[List[GLFileCommitInfo]]]) @@ -631,7 +631,7 @@ class GitLabProjectVersioningTest extends AsyncWordSpec with Matchers with Mocki lazy val inactiveProject: Project = activeProject.copy(active = false) lazy val projectWithRepo: Project = activeLocalProject.toProject(gitLabRepositoryResponse.id, defaultVersion) - lazy val postProject: PostProject = PostProject(name = activeProject.projectId.value) + lazy val postProject: PostProject = PostProject(name = activeProject.projectId) lazy val dummyPipelineVersion: PipelineVersion = TestProjectUtils.getDummyPipeLineVersion() lazy val dummyPipelineVersionHigher: PipelineVersion = dummyPipelineVersion.increaseMinor diff --git a/services/src/test/scala/cromwell/pipeline/service/ProjectConfigurationServiceTest.scala b/services/src/test/scala/cromwell/pipeline/service/ProjectConfigurationServiceTest.scala index b11d417b6..e86464cd2 100644 --- a/services/src/test/scala/cromwell/pipeline/service/ProjectConfigurationServiceTest.scala +++ b/services/src/test/scala/cromwell/pipeline/service/ProjectConfigurationServiceTest.scala @@ -4,7 +4,7 @@ import cromwell.pipeline.datastorage.dao.repository.ProjectConfigurationReposito import cromwell.pipeline.datastorage.dao.repository.impls.ProjectConfigurationRepositoryTestImpl import cromwell.pipeline.datastorage.dao.utils.{ TestProjectUtils, TestUserUtils } import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId, UserId } import cromwell.pipeline.service.ProjectConfigurationService.Exceptions._ import cromwell.pipeline.service.impls.{ ProjectServiceTestImpl, ProjectVersioningTestImpl, WomToolTestImpl } import cromwell.pipeline.womtool.WomToolAPI diff --git a/services/src/test/scala/cromwell/pipeline/service/ProjectSearchEngineTest.scala b/services/src/test/scala/cromwell/pipeline/service/ProjectSearchEngineTest.scala index 3638c4902..6feedbc54 100644 --- a/services/src/test/scala/cromwell/pipeline/service/ProjectSearchEngineTest.scala +++ b/services/src/test/scala/cromwell/pipeline/service/ProjectSearchEngineTest.scala @@ -2,7 +2,7 @@ package cromwell.pipeline.service import cromwell.pipeline.datastorage.dao.utils.TestProjectUtils import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId, UserId } import cromwell.pipeline.service.ProjectSearchEngine.Exceptions.InternalError import cromwell.pipeline.service.impls.{ ProjectConfigurationServiceTestImpl, diff --git a/services/src/test/scala/cromwell/pipeline/service/ProjectServiceTest.scala b/services/src/test/scala/cromwell/pipeline/service/ProjectServiceTest.scala index 77f9143e7..2e36a0126 100644 --- a/services/src/test/scala/cromwell/pipeline/service/ProjectServiceTest.scala +++ b/services/src/test/scala/cromwell/pipeline/service/ProjectServiceTest.scala @@ -3,6 +3,7 @@ package cromwell.pipeline.service import cromwell.pipeline.datastorage.dao.repository.impls.ProjectRepositoryTestImpl import cromwell.pipeline.datastorage.dao.utils.TestProjectUtils import cromwell.pipeline.datastorage.dto._ +import cromwell.pipeline.model.wrapper.ProjectId import cromwell.pipeline.service.ProjectService.Exceptions.{ AccessDenied, InternalError, NotFound } import cromwell.pipeline.service.impls.ProjectVersioningTestImpl import org.scalatest.{ AsyncWordSpec, Matchers } @@ -106,7 +107,7 @@ class ProjectServiceTest extends AsyncWordSpec with Matchers with MockitoSugar { } "return none if project not found" taggedAs Service in { - val projectId = ProjectId("projectId") + val projectId = ProjectId.random projectService.getUserProjectById(projectId, userId).failed.map { _ shouldBe NotFound() } } diff --git a/services/src/test/scala/cromwell/pipeline/service/impls/ProjectConfigurationServiceTestImpl.scala b/services/src/test/scala/cromwell/pipeline/service/impls/ProjectConfigurationServiceTestImpl.scala index 880d7aebf..f29bc1ed4 100644 --- a/services/src/test/scala/cromwell/pipeline/service/impls/ProjectConfigurationServiceTestImpl.scala +++ b/services/src/test/scala/cromwell/pipeline/service/impls/ProjectConfigurationServiceTestImpl.scala @@ -1,7 +1,7 @@ package cromwell.pipeline.service.impls import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId, UserId } import cromwell.pipeline.service.ProjectConfigurationService import java.nio.file.Path diff --git a/services/src/test/scala/cromwell/pipeline/service/impls/ProjectFileServiceTestImpl.scala b/services/src/test/scala/cromwell/pipeline/service/impls/ProjectFileServiceTestImpl.scala index 8436e8ae5..f87bdcfd4 100644 --- a/services/src/test/scala/cromwell/pipeline/service/impls/ProjectFileServiceTestImpl.scala +++ b/services/src/test/scala/cromwell/pipeline/service/impls/ProjectFileServiceTestImpl.scala @@ -1,7 +1,7 @@ package cromwell.pipeline.service.impls import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } import cromwell.pipeline.service.{ ProjectFileService, VersioningException } import java.nio.file.Path diff --git a/services/src/test/scala/cromwell/pipeline/service/impls/ProjectServiceTestImpl.scala b/services/src/test/scala/cromwell/pipeline/service/impls/ProjectServiceTestImpl.scala index eeb27db5f..c92ed5328 100644 --- a/services/src/test/scala/cromwell/pipeline/service/impls/ProjectServiceTestImpl.scala +++ b/services/src/test/scala/cromwell/pipeline/service/impls/ProjectServiceTestImpl.scala @@ -2,7 +2,7 @@ package cromwell.pipeline.service.impls import cromwell.pipeline.datastorage.dao.utils.TestProjectUtils import cromwell.pipeline.datastorage.dto._ -import cromwell.pipeline.model.wrapper.UserId +import cromwell.pipeline.model.wrapper.{ ProjectId, UserId } import cromwell.pipeline.service.ProjectService import scala.concurrent.Future diff --git a/services/src/test/scala/cromwell/pipeline/service/impls/RunServiceTestImpl.scala b/services/src/test/scala/cromwell/pipeline/service/impls/RunServiceTestImpl.scala index f53281355..c1985ad67 100644 --- a/services/src/test/scala/cromwell/pipeline/service/impls/RunServiceTestImpl.scala +++ b/services/src/test/scala/cromwell/pipeline/service/impls/RunServiceTestImpl.scala @@ -1,7 +1,7 @@ package cromwell.pipeline.service.impls -import cromwell.pipeline.datastorage.dto.{ ProjectId, Run, RunCreateRequest, RunUpdateRequest } -import cromwell.pipeline.model.wrapper.{ RunId, UserId } +import cromwell.pipeline.datastorage.dto.{ Run, RunCreateRequest, RunUpdateRequest } +import cromwell.pipeline.model.wrapper.{ ProjectId, RunId, UserId } import cromwell.pipeline.service.RunService import scala.concurrent.Future