Skip to content

Commit

Permalink
Temp commit for review and help
Browse files Browse the repository at this point in the history
  • Loading branch information
Ioann Kurchin committed Mar 4, 2022
1 parent c706125 commit 0646ebf
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 33 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 => ProjectIdPM }
import cromwell.pipeline.controller.utils.PathMatchers.{ Path, wrapperToPM }
import cromwell.pipeline.datastorage.dto._
import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent
import cromwell.pipeline.model.wrapper.ProjectId
Expand Down Expand Up @@ -60,9 +60,9 @@ class ProjectConfigurationController(projectConfigurationService: ProjectConfigu
}
}

val route: AccessTokenContent => Route = implicit accessToken =>
val route: AccessTokenContent => Route = implicit accessToken =>
handleExceptions(projectConfigurationServiceExceptionHandler) {
pathPrefix("projects" / ProjectIdPM / "configurations") { projectId =>
pathPrefix("projects" / wrapperToPM[ProjectId] / "configurations") { projectId =>
buildConfiguration(projectId) ~
addConfiguration(projectId) ~
getConfiguration(projectId) ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import akka.http.scaladsl.model.{ StatusCode, StatusCodes }
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.{ ExceptionHandler, Route }
import cromwell.pipeline.controller.ProjectController.projectServiceExceptionHandler
import cromwell.pipeline.controller.utils.PathMatchers.ProjectId
import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent
import cromwell.pipeline.datastorage.dto.{ ProjectAdditionRequest, ProjectUpdateNameRequest }
import cromwell.pipeline.service.ProjectService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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 => ProjectIdPM }
import cromwell.pipeline.controller.utils.PathMatchers.{ Path, wrapperToPM}
import cromwell.pipeline.datastorage.dto._
import cromwell.pipeline.datastorage.dto.auth.AccessTokenContent
import cromwell.pipeline.model.wrapper.ProjectId
Expand Down Expand Up @@ -100,7 +100,7 @@ class ProjectFileController(wdlService: ProjectFileService)(

val route: AccessTokenContent => Route = implicit accessToken =>
validateFile ~
pathPrefix("projects" / ProjectIdPM / "files") { projectId =>
pathPrefix("projects" / wrapperToPM[ProjectId] / "files") { projectId =>
getFile(projectId) ~
getFiles(projectId) ~
uploadFile(projectId) ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cromwell.pipeline.controller.utils

import akka.http.scaladsl.server.PathMatcher1
import akka.http.scaladsl.server.PathMatchers.Segment
import cromwell.pipeline.model.wrapper
import cromwell.pipeline.model.validator.Wrapped

import java.nio.file.{ Path, Paths }
import scala.language.implicitConversions

object PathMatchers {
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] =
Segment.flatMap(wrapper.ProjectSearchFilterId.from(_).toOption)

implicit def wrapperToPM[T <: Wrapped[String]](implicit value: Wrapped.Companion[String]): PathMatcher1[T] =
Segment.flatMap(value.from(_).toOption)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ trait Wrapped[T] extends Any {
}

object Wrapped {
trait Companion {
type Type
trait Companion[Type] {
type Error
type Wrapper <: Wrapped[Type]
type ValidationResult[A] = Validated[NonEmptyChain[Error], A]
implicit val selfRef: this.type = this
implicit def wrappedOrdering(implicit ord: Ordering[Type]): Ordering[Wrapper] = Ordering.by(_.unwrap)
implicit def wrapperFormat(implicit show: Show[Error], format: Format[Type]): Format[Wrapper] =
new Format[Wrapper] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import cromwell.pipeline.model.validator.Wrapped

final class Name private (override val unwrap: String) extends AnyVal with Wrapped[String]

object Name extends Wrapped.Companion {
type Type = String
object Name extends Wrapped.Companion[String] {
type Wrapper = Name
type Error = String
override protected def create(value: String): Name = new Name(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ final class Password private (override val unwrap: String) extends AnyVal with W
override def value: String = unwrap
}

object Password extends Wrapped.Companion {
type Type = String
object Password extends Wrapped.Companion[String] {
type Wrapper = Password
type Error = String
override protected def create(value: String): Password = new Password(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ final class ProjectConfigurationId private (override val unwrap: String)
override def value: String = unwrap
}

object ProjectConfigurationId extends Wrapped.Companion {
type Type = String
object ProjectConfigurationId extends Wrapped.Companion[String] {
type Wrapper = ProjectConfigurationId
type Error = String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ final class ProjectId private (override val unwrap: String) extends AnyVal with
override def value: String = unwrap
}

object ProjectId extends Wrapped.Companion {
type Type = String
object ProjectId extends Wrapped.Companion[String] {
type Wrapper = ProjectId
type Error = String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import cromwell.pipeline.model.validator.Wrapped

final class ProjectSearchFilterId private (override val unwrap: String) extends AnyVal with Wrapped[String]

object ProjectSearchFilterId extends Wrapped.Companion {
type Type = String
object ProjectSearchFilterId extends Wrapped.Companion[String] {
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}$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ final case class RepositoryId(override val unwrap: Int) extends AnyVal with Mapp
override def value: Int = unwrap
}

object RepositoryId extends Wrapped.Companion {
type Type = Int
object RepositoryId extends Wrapped.Companion[Int] {
type Wrapper = RepositoryId
type Error = String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import cromwell.pipeline.model.validator.Wrapped

final class RunId private (override val unwrap: String) extends AnyVal with Wrapped[String]

object RunId extends Wrapped.Companion {
type Type = String
object RunId extends Wrapped.Companion[String] {
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}$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import cromwell.pipeline.model.validator.Wrapped

final class UserEmail private (override val unwrap: String) extends AnyVal with Wrapped[String]

object UserEmail extends Wrapped.Companion {
type Type = String
object UserEmail extends Wrapped.Companion[String] {
type Wrapper = UserEmail
type Error = String
override protected def create(value: String): UserEmail = new UserEmail(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import cromwell.pipeline.model.validator.Wrapped

final class UserId private (override val unwrap: String) extends AnyVal with Wrapped[String]

object UserId extends Wrapped.Companion {
type Type = String
object UserId extends Wrapped.Companion[String] {
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}$"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import cromwell.pipeline.model.validator.Wrapped

final class VersionValue private (override val unwrap: Int) extends AnyVal with Wrapped[Int]

object VersionValue extends Wrapped.Companion {
type Type = Int
object VersionValue extends Wrapped.Companion[Int] {
type Wrapper = VersionValue
type Error = String
val pattern = "^[0-9]+$"
Expand Down

0 comments on commit 0646ebf

Please sign in to comment.