Skip to content

Commit c706125

Browse files
author
Ioann Kurchin
committed
refactor: Wrapped id cc into Wrapper with companion objects
1 parent ac85bbc commit c706125

File tree

54 files changed

+249
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+249
-185
lines changed

controllers/src/main/scala/cromwell/pipeline/controller/ProjectConfigurationController.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import akka.http.scaladsl.server.{ ExceptionHandler, Route }
66
import cromwell.pipeline.controller.ProjectConfigurationController._
77
import cromwell.pipeline.controller.utils.FromStringUnmarshallers._
88
import cromwell.pipeline.controller.utils.FromUnitMarshaller._
9-
import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId }
9+
import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId => ProjectIdPM }
1010
import cromwell.pipeline.datastorage.dto._
1111
import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent
12+
import cromwell.pipeline.model.wrapper.ProjectId
1213
import cromwell.pipeline.service.ProjectConfigurationService
1314
import cromwell.pipeline.service.ProjectConfigurationService.Exceptions._
1415
import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport._
@@ -61,7 +62,7 @@ class ProjectConfigurationController(projectConfigurationService: ProjectConfigu
6162

6263
val route: AccessTokenContent => Route = implicit accessToken =>
6364
handleExceptions(projectConfigurationServiceExceptionHandler) {
64-
pathPrefix("projects" / ProjectId / "configurations") { projectId =>
65+
pathPrefix("projects" / ProjectIdPM / "configurations") { projectId =>
6566
buildConfiguration(projectId) ~
6667
addConfiguration(projectId) ~
6768
getConfiguration(projectId) ~

controllers/src/main/scala/cromwell/pipeline/controller/ProjectFileController.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import akka.http.scaladsl.server.Route
66
import akka.stream.Materializer
77
import cromwell.pipeline.controller.utils.FieldUnmarshallers._
88
import cromwell.pipeline.controller.utils.FromStringUnmarshallers._
9-
import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId }
9+
import cromwell.pipeline.controller.utils.PathMatchers.{ Path, ProjectId => ProjectIdPM }
1010
import cromwell.pipeline.datastorage.dto._
1111
import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent
12+
import cromwell.pipeline.model.wrapper.ProjectId
1213
import cromwell.pipeline.service.ProjectFileService
1314
import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport._
1415

@@ -99,7 +100,7 @@ class ProjectFileController(wdlService: ProjectFileService)(
99100

100101
val route: AccessTokenContent => Route = implicit accessToken =>
101102
validateFile ~
102-
pathPrefix("projects" / ProjectId / "files") { projectId =>
103+
pathPrefix("projects" / ProjectIdPM / "files") { projectId =>
103104
getFile(projectId) ~
104105
getFiles(projectId) ~
105106
uploadFile(projectId) ~

controllers/src/main/scala/cromwell/pipeline/controller/RunController.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import akka.http.scaladsl.model.{ StatusCode, StatusCodes }
44
import akka.http.scaladsl.server.Directives.{ entity, _ }
55
import akka.http.scaladsl.server.{ ExceptionHandler, Route }
66
import cromwell.pipeline.controller.RunController.runServiceExceptionHandler
7-
import cromwell.pipeline.controller.utils.PathMatchers.{ ProjectId, RunId }
7+
import cromwell.pipeline.controller.utils.PathMatchers.{ RunId, ProjectId => ProjectIdPM }
88
import cromwell.pipeline.datastorage.dto._
99
import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent
10+
import cromwell.pipeline.model.wrapper.ProjectId
1011
import cromwell.pipeline.service.RunService
1112
import cromwell.pipeline.service.RunService.Exceptions.RunServiceException
1213
import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport._
@@ -46,7 +47,7 @@ class RunController(runService: RunService) {
4647

4748
val route: AccessTokenContent => Route = implicit accessToken =>
4849
handleExceptions(runServiceExceptionHandler) {
49-
pathPrefix("projects" / ProjectId / "runs") { projectId =>
50+
pathPrefix("projects" / ProjectIdPM / "runs") { projectId =>
5051
getRun(projectId) ~
5152
getRunsByProject(projectId) ~
5253
deleteRun(projectId) ~

controllers/src/main/scala/cromwell/pipeline/controller/utils/FromStringUnmarshallers.scala

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package cromwell.pipeline.controller.utils
22

33
import akka.http.scaladsl.unmarshalling.Unmarshaller
44
import cats.data.Validated
5-
import cromwell.pipeline.datastorage.dto.{ PipelineVersion, ProjectId }
6-
import cromwell.pipeline.model.wrapper.RunId
5+
import cromwell.pipeline.datastorage.dto.PipelineVersion
6+
import cromwell.pipeline.model.validator.Enable
7+
import cromwell.pipeline.model.wrapper.{ ProjectId, RunId }
78

89
import java.nio.file.{ Path, Paths }
910

@@ -17,7 +18,7 @@ object FromStringUnmarshallers {
1718
}
1819
implicit val stringToProjectId: Unmarshaller[String, ProjectId] = Unmarshaller.strict[String, ProjectId] {
1920
projectId =>
20-
ProjectId(projectId)
21+
ProjectId(projectId, Enable.Unsafe)
2122
}
2223
implicit val stringToPath: Unmarshaller[String, Path] = Unmarshaller.strict[String, Path] { path =>
2324
Paths.get(path)

controllers/src/main/scala/cromwell/pipeline/controller/utils/PathMatchers.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package cromwell.pipeline.controller.utils
22

33
import akka.http.scaladsl.server.PathMatcher1
44
import akka.http.scaladsl.server.PathMatchers.Segment
5-
import cromwell.pipeline.datastorage.dto
65
import cromwell.pipeline.model.wrapper
7-
86
import java.nio.file.{ Path, Paths }
97

108
object PathMatchers {
11-
val ProjectId: PathMatcher1[dto.ProjectId] = Segment.map(dto.ProjectId(_))
9+
val ProjectId: PathMatcher1[wrapper.ProjectId] = Segment.flatMap(wrapper.ProjectId.from(_).toOption)
1210
val Path: PathMatcher1[Path] = Segment.map(Paths.get(_))
1311
val RunId: PathMatcher1[wrapper.RunId] = Segment.flatMap(wrapper.RunId.from(_).toOption)
1412
val ProjectSearchFilterId: PathMatcher1[wrapper.ProjectSearchFilterId] =

controllers/src/test/scala/cromwell/pipeline/controller/ProjectConfigurationControllerTest.scala

+23-23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest
55
import cromwell.pipeline.datastorage.dao.utils.{ TestProjectUtils, TestUserUtils }
66
import cromwell.pipeline.datastorage.dto._
77
import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent
8+
import cromwell.pipeline.model.validator.Enable
9+
import cromwell.pipeline.model.wrapper.ProjectConfigurationId
810
import cromwell.pipeline.service.ProjectConfigurationService.Exceptions.{ InternalError, NotFound, ValidationError }
911
import cromwell.pipeline.service.{ ProjectConfigurationService, VersioningException }
1012
import cromwell.pipeline.utils.URLEncoderUtils
@@ -14,6 +16,7 @@ import org.scalatest.{ AsyncWordSpec, Matchers }
1416
import org.scalatestplus.mockito.MockitoSugar
1517

1618
import java.nio.file.Paths
19+
import java.util.UUID
1720
import scala.concurrent.Future
1821

1922
class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers with ScalatestRouteTest with MockitoSugar {
@@ -24,7 +27,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
2427
val accessToken = AccessTokenContent(TestUserUtils.getDummyUserId)
2528
val projectId = TestProjectUtils.getDummyProjectId
2629
val configuration = ProjectConfiguration(
27-
ProjectConfigurationId.randomId,
30+
ProjectConfigurationId(UUID.randomUUID().toString, Enable.Unsafe),
2831
projectId,
2932
active = true,
3033
WdlParams(Paths.get("/home/file"), List(FileParameter("nodeName", StringTyped(Some("hello"))))),
@@ -46,21 +49,19 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
4649

4750
"return success for update configuration" in {
4851
when(configurationService.addConfiguration(configuration, accessToken.userId)).thenReturn(Future.unit)
49-
Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController
50-
.route(
51-
accessToken
52-
) ~> check {
52+
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
53+
accessToken
54+
) ~> check {
5355
status shouldBe StatusCodes.NoContent
5456
}
5557
}
5658

5759
"return InternalServerError when failure update configuration" in {
5860
val error = InternalError("Something went wrong")
5961
when(configurationService.addConfiguration(configuration, accessToken.userId)).thenReturn(Future.failed(error))
60-
Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController
61-
.route(
62-
accessToken
63-
) ~> check {
62+
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
63+
accessToken
64+
) ~> check {
6465
status shouldBe StatusCodes.InternalServerError
6566
entityAs[String] shouldBe "Something went wrong"
6667
}
@@ -69,10 +70,9 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
6970
"return NotFound when failure find project to update configuration" in {
7071
when(configurationService.addConfiguration(configuration, accessToken.userId))
7172
.thenReturn(Future.failed(NotFound()))
72-
Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController
73-
.route(
74-
accessToken
75-
) ~> check {
73+
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
74+
accessToken
75+
) ~> check {
7676
status shouldBe StatusCodes.NotFound
7777
}
7878
}
@@ -82,18 +82,18 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
8282
"return configuration by existing project id" in {
8383
when(configurationService.getLastByProjectId(projectId, accessToken.userId))
8484
.thenReturn(Future.successful(configuration))
85-
Get(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
85+
Get(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
8686
status shouldBe StatusCodes.OK
8787
entityAs[ProjectConfiguration] shouldBe configuration
8888
}
8989
}
9090

9191
"return Configuration not found message" in {
9292
when(configurationService.getLastByProjectId(projectId, accessToken.userId))
93-
.thenReturn(Future.failed(NotFound(s"There is no configuration with project_id: ${projectId.value}")))
94-
Get(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
93+
.thenReturn(Future.failed(NotFound(s"There is no configuration with project_id: $projectId")))
94+
Get(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
9595
status shouldBe StatusCodes.NotFound
96-
entityAs[String] shouldBe s"There is no configuration with project_id: ${projectId.value}"
96+
entityAs[String] shouldBe s"There is no configuration with project_id: $projectId"
9797
}
9898
}
9999
}
@@ -103,15 +103,15 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
103103

104104
"return success for deactivate configuration" in {
105105
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId)).thenReturn(Future.unit)
106-
Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
106+
Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
107107
status shouldBe StatusCodes.NoContent
108108
}
109109
}
110110

111111
"return InternalServerError when failure deactivate configuration" in {
112112
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId))
113113
.thenReturn(Future.failed(error))
114-
Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
114+
Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
115115
status shouldBe StatusCodes.InternalServerError
116116
entityAs[String] shouldBe "Something went wrong"
117117
}
@@ -120,7 +120,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
120120
"return NotFound when failure find project to deactivate configuration" in {
121121
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId))
122122
.thenReturn(Future.failed(NotFound()))
123-
Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
123+
Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
124124
status shouldBe StatusCodes.NotFound
125125
}
126126
}
@@ -131,7 +131,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
131131
"return configuration for file" in {
132132
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
133133
.thenReturn(Future.successful(configuration))
134-
Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~>
134+
Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~>
135135
configurationController.route(accessToken) ~> check {
136136
status shouldBe StatusCodes.OK
137137
entityAs[ProjectConfiguration] shouldBe configuration
@@ -141,7 +141,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
141141
"return failed for Bad request" in {
142142
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
143143
.thenReturn(Future.failed(VersioningException.HttpException("Bad request")))
144-
Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~>
144+
Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~>
145145
configurationController.route(accessToken) ~> check {
146146
status shouldBe StatusCodes.InternalServerError
147147
entityAs[String] shouldBe "Bad request"
@@ -151,7 +151,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
151151
"return failed for invalid file" in {
152152
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
153153
.thenReturn(Future.failed(ValidationError(List("invalid some field").mkString(","))))
154-
Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~>
154+
Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~>
155155
configurationController.route(accessToken) ~> check {
156156
status shouldBe StatusCodes.UnprocessableEntity
157157
entityAs[String] shouldBe "invalid some field"

controllers/src/test/scala/cromwell/pipeline/controller/ProjectControllerTest.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo
6060
when(projectService.getUserProjectById(dummyProject.projectId, accessToken.userId))
6161
.thenReturn(Future.successful(dummyProject))
6262

63-
Get(s"/projects/${dummyProject.projectId.value}") ~> projectController.route(accessToken) ~> check {
63+
Get(s"/projects/${dummyProject.projectId}") ~> projectController.route(accessToken) ~> check {
6464
status shouldBe StatusCodes.OK
6565
responseAs[Project] shouldEqual dummyProject
6666
}
@@ -72,7 +72,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo
7272
when(projectService.getUserProjectById(dummyProject.projectId, accessToken.userId))
7373
.thenReturn(Future.failed(error))
7474

75-
Get(s"/projects/${dummyProject.projectId.value}") ~> projectController.route(accessToken) ~> check {
75+
Get(s"/projects/${dummyProject.projectId}") ~> projectController.route(accessToken) ~> check {
7676
status shouldBe StatusCodes.InternalServerError
7777
}
7878
}
@@ -131,7 +131,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo
131131
projectService.deactivateProjectById(dummyProject.projectId, accessToken.userId)
132132
).thenReturn(Future.successful(deactivatedProject))
133133

134-
Delete(s"/projects/${dummyProject.projectId.value}") ~> projectController.route(accessToken) ~> check {
134+
Delete(s"/projects/${dummyProject.projectId}") ~> projectController.route(accessToken) ~> check {
135135
responseAs[Project] shouldBe deactivatedProject
136136
}
137137
}
@@ -142,7 +142,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo
142142
when(projectService.deactivateProjectById(projectId, strangerAccessToken.userId))
143143
.thenReturn(Future.failed(InternalError()))
144144

145-
Delete(s"/projects/${projectId.value}") ~> projectController.route(strangerAccessToken) ~> check {
145+
Delete(s"/projects/${projectId}") ~> projectController.route(strangerAccessToken) ~> check {
146146
status shouldBe StatusCodes.InternalServerError
147147
}
148148
}
@@ -155,7 +155,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo
155155
when(projectService.updateProjectName(dummyProject.projectId, request, accessToken.userId))
156156
.thenReturn(Future.successful(dummyProject.projectId))
157157

158-
Put(s"/projects/${dummyProject.projectId.value}", request) ~> projectController.route(accessToken) ~> check {
158+
Put(s"/projects/${dummyProject.projectId}", request) ~> projectController.route(accessToken) ~> check {
159159
status shouldBe StatusCodes.OK
160160
}
161161
}
@@ -166,7 +166,7 @@ class ProjectControllerTest extends AsyncWordSpec with Matchers with ScalatestRo
166166
when(projectService.updateProjectName(dummyProject.projectId, request, strangerAccessToken.userId))
167167
.thenReturn(Future.failed(InternalError()))
168168

169-
Put(s"/projects/${dummyProject.projectId.value}", request) ~> projectController.route(strangerAccessToken) ~> check {
169+
Put(s"/projects/${dummyProject.projectId}", request) ~> projectController.route(strangerAccessToken) ~> check {
170170
status shouldBe StatusCodes.InternalServerError
171171
}
172172
}

0 commit comments

Comments
 (0)