Skip to content

Commit

Permalink
Final Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioann Kurchin committed Feb 21, 2022
1 parent ea04c1c commit 60f393f
Show file tree
Hide file tree
Showing 24 changed files with 72 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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
Expand Down Expand Up @@ -62,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) ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand Down Expand Up @@ -99,10 +100,14 @@ class ProjectFileController(wdlService: ProjectFileService)(

val route: AccessTokenContent => Route = implicit accessToken =>
validateFile ~
pathPrefix("projects" / ProjectId / "files") { projectId =>
getFile(projectId) ~
getFiles(projectId) ~
uploadFile(projectId) ~
deleteFile(projectId)
pathPrefix("projects") {
path(ProjectIdPM / "files") { projectId =>
{
getFile(projectId) ~
getFiles(projectId) ~
uploadFile(projectId) ~
deleteFile(projectId)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -46,12 +47,16 @@ class RunController(runService: RunService) {

val route: AccessTokenContent => Route = implicit accessToken =>
handleExceptions(runServiceExceptionHandler) {
pathPrefix("projects" / ProjectId / "runs") { projectId =>
getRun(projectId) ~
getRunsByProject(projectId) ~
deleteRun(projectId) ~
updateRun(projectId) ~
addRun(projectId)
pathPrefix("projects") {
path(ProjectIdPM / "runs") { projectId =>
{
getRun(projectId) ~
getRunsByProject(projectId) ~
deleteRun(projectId) ~
updateRun(projectId) ~
addRun(projectId)
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ 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.wrapper.{ ProjectId, RunId }

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

Expand All @@ -17,7 +17,10 @@ object FromStringUnmarshallers {
}
implicit val stringToProjectId: Unmarshaller[String, ProjectId] = Unmarshaller.strict[String, ProjectId] {
projectId =>
ProjectId(projectId)
ProjectId.from(projectId) match {
case Validated.Valid(content) => content
case Validated.Invalid(errors) => throw new RuntimeException(errors.head)
}
}
implicit val stringToPath: Unmarshaller[String, Path] = Unmarshaller.strict[String, Path] { path =>
Paths.get(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ 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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ 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}/configurations", configurationAdditionRequest) ~> configurationController.route(
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
accessToken
) ~> check {
status shouldBe StatusCodes.NoContent
Expand All @@ -57,7 +57,7 @@ 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}/configurations", configurationAdditionRequest) ~> configurationController.route(
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
accessToken
) ~> check {
status shouldBe StatusCodes.InternalServerError
Expand All @@ -68,7 +68,7 @@ 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}/configurations", configurationAdditionRequest) ~> configurationController.route(
Put(s"/projects/$projectId/configurations", configurationAdditionRequest) ~> configurationController.route(
accessToken
) ~> check {
status shouldBe StatusCodes.NotFound
Expand All @@ -80,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}/configurations") ~> configurationController.route(accessToken) ~> check {
Get(s"/projects/$projectId/configurations") ~> configurationController.route(accessToken) ~> check {
status shouldBe StatusCodes.OK
entityAs[ProjectConfiguration] shouldBe configuration
}
Expand All @@ -89,7 +89,7 @@ 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 {
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}"
}
Expand All @@ -101,15 +101,15 @@ 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
}
}

"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"
}
Expand All @@ -118,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
}
}
Expand All @@ -129,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
Expand All @@ -139,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"
Expand All @@ -149,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package cromwell.pipeline.datastorage.dao.entry
import cromwell.pipeline.datastorage.Profile
import cromwell.pipeline.datastorage.dto._
import cromwell.pipeline.model.wrapper.{ ProjectId, RepositoryId, UserId }
import slick.lifted.MappedToBase.mappedToIsomorphism
import slick.lifted.{ ForeignKeyQuery, ProvenShape }

trait ProjectEntry { this: Profile with UserEntry with MyPostgresProfile with AliasesSupport =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ 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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cromwell.pipeline.datastorage.dto

import cats.data.Validated
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 }

Expand Down Expand Up @@ -52,7 +53,6 @@ object ProjectConfigurationVersion {
implicitly[Format[String]].inmap(ProjectConfigurationVersion.apply, _.name)
}


final case class ProjectConfigurationAdditionRequest(
id: ProjectConfigurationId,
active: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cromwell.pipeline.datastorage.dao.utils

import cromwell.pipeline.datastorage.dto._
import cromwell.pipeline.model.validator.Enable
import cromwell.pipeline.model.wrapper.{ ProjectConfigurationId, ProjectId, RepositoryId, UserId }

import java.nio.file.Paths
Expand All @@ -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.random
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,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.unwrap)
val postProject = PostProject(name = localProject.projectId)
httpClient
.post[GitLabRepositoryResponse, PostProject](url = createRepoUrl, headers = config.token, payload = postProject)
.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 {
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 60f393f

Please sign in to comment.