Skip to content

Commit 2f628d2

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

File tree

54 files changed

+234
-180
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

+234
-180
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

+20-22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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.wrapper.ProjectConfigurationId
89
import cromwell.pipeline.service.ProjectConfigurationService.Exceptions.{ InternalError, NotFound, ValidationError }
910
import cromwell.pipeline.service.{ ProjectConfigurationService, VersioningException }
1011
import cromwell.pipeline.utils.URLEncoderUtils
@@ -46,21 +47,19 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
4647

4748
"return success for update configuration" in {
4849
when(configurationService.addConfiguration(configuration, accessToken.userId)).thenReturn(Future.unit)
49-
Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController
50-
.route(
51-
accessToken
52-
) ~> check {
50+
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
51+
accessToken
52+
) ~> check {
5353
status shouldBe StatusCodes.NoContent
5454
}
5555
}
5656

5757
"return InternalServerError when failure update configuration" in {
5858
val error = InternalError("Something went wrong")
5959
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 {
60+
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
61+
accessToken
62+
) ~> check {
6463
status shouldBe StatusCodes.InternalServerError
6564
entityAs[String] shouldBe "Something went wrong"
6665
}
@@ -69,10 +68,9 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
6968
"return NotFound when failure find project to update configuration" in {
7069
when(configurationService.addConfiguration(configuration, accessToken.userId))
7170
.thenReturn(Future.failed(NotFound()))
72-
Put(s"/projects/${projectId.value}/configurations", configurationAdditionRequest) ~> configurationController
73-
.route(
74-
accessToken
75-
) ~> check {
71+
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
72+
accessToken
73+
) ~> check {
7674
status shouldBe StatusCodes.NotFound
7775
}
7876
}
@@ -82,18 +80,18 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
8280
"return configuration by existing project id" in {
8381
when(configurationService.getLastByProjectId(projectId, accessToken.userId))
8482
.thenReturn(Future.successful(configuration))
85-
Get(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
83+
Get(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
8684
status shouldBe StatusCodes.OK
8785
entityAs[ProjectConfiguration] shouldBe configuration
8886
}
8987
}
9088

9189
"return Configuration not found message" in {
9290
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 {
91+
.thenReturn(Future.failed(NotFound(s"There is no configuration with project_id: $projectId")))
92+
Get(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
9593
status shouldBe StatusCodes.NotFound
96-
entityAs[String] shouldBe s"There is no configuration with project_id: ${projectId.value}"
94+
entityAs[String] shouldBe s"There is no configuration with project_id: $projectId"
9795
}
9896
}
9997
}
@@ -103,15 +101,15 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
103101

104102
"return success for deactivate configuration" in {
105103
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId)).thenReturn(Future.unit)
106-
Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
104+
Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
107105
status shouldBe StatusCodes.NoContent
108106
}
109107
}
110108

111109
"return InternalServerError when failure deactivate configuration" in {
112110
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId))
113111
.thenReturn(Future.failed(error))
114-
Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
112+
Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
115113
status shouldBe StatusCodes.InternalServerError
116114
entityAs[String] shouldBe "Something went wrong"
117115
}
@@ -120,7 +118,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
120118
"return NotFound when failure find project to deactivate configuration" in {
121119
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId))
122120
.thenReturn(Future.failed(NotFound()))
123-
Delete(s"/projects/${projectId.value}/configurations") ~> configurationController.route(accessToken) ~> check {
121+
Delete(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
124122
status shouldBe StatusCodes.NotFound
125123
}
126124
}
@@ -131,7 +129,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
131129
"return configuration for file" in {
132130
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
133131
.thenReturn(Future.successful(configuration))
134-
Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~>
132+
Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~>
135133
configurationController.route(accessToken) ~> check {
136134
status shouldBe StatusCodes.OK
137135
entityAs[ProjectConfiguration] shouldBe configuration
@@ -141,7 +139,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
141139
"return failed for Bad request" in {
142140
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
143141
.thenReturn(Future.failed(VersioningException.HttpException("Bad request")))
144-
Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~>
142+
Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~>
145143
configurationController.route(accessToken) ~> check {
146144
status shouldBe StatusCodes.InternalServerError
147145
entityAs[String] shouldBe "Bad request"
@@ -151,7 +149,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
151149
"return failed for invalid file" in {
152150
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
153151
.thenReturn(Future.failed(ValidationError(List("invalid some field").mkString(","))))
154-
Get(s"/projects/${projectId.value}/configurations/files/$pathString?version=$versionString") ~>
152+
Get(s"/projects/$projectId/configurations/files/$pathString?version=$versionString") ~>
155153
configurationController.route(accessToken) ~> check {
156154
status shouldBe StatusCodes.UnprocessableEntity
157155
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)