Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
voropaevp committed Nov 15, 2022
1 parent 16811ce commit edbc33c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,44 +80,46 @@ private[registries] object Utils {
try {
val d = new File(getClass.getResource(path).getPath)
val schemaFileRegex: Regex = (".*/schemas/?" + // path to file
"([a-zA-Z0-9-_.]+)/" + // Vendor
"([a-zA-Z0-9-_]+)/" + // Name
"([a-zA-Z0-9-_]+)/" + // Format
"([1-9][0-9]*)-(\\d+)-(\\d+)$").r // MODEL, REVISION and ADDITION
"([a-zA-Z0-9-_.]+)/" + // Vendor
"([a-zA-Z0-9-_]+)/" + // Name
"([a-zA-Z0-9-_]+)/" + // Format
"([1-9][0-9]*)-(\\d+)-(\\d+)$").r // MODEL, REVISION and ADDITION

def getFolderContent(d: File ): List[String] = {
def getFolderContent(d: File): List[String] = {
d.listFiles
.filter(_.isFile)
.toList
.filter(_.getName.startsWith(s"${modelMatch.toString}-"))
.map(_.getAbsolutePath)
}

val content = if (d.exists & d.isDirectory)
val content =
if (d.exists & d.isDirectory)
getFolderContent(d)
else
List.empty[String]

content
.traverse{
case schemaFileRegex(vendor, name, format, model, revision, addition) if model == modelMatch.toString =>
SchemaKey(
vendor = vendor,
name = name,
format = format,
version = SchemaVer
.Full(model = model.toInt, revision = revision.toInt, addition = addition.toInt)
).asRight
case f => RegistryError.RepoFailure(s"Corrupted schema file name at $f").asLeft
}
.map(_.sortBy(_.version))
.flatMap(s =>
if (s.isEmpty)

content
.traverse {
case schemaFileRegex(vendor, name, format, model, revision, addition)
if model == modelMatch.toString =>
SchemaKey(
vendor = vendor,
name = name,
format = format,
version = SchemaVer
.Full(model = model.toInt, revision = revision.toInt, addition = addition.toInt)
).asRight
case f => RegistryError.RepoFailure(s"Corrupted schema file name at $f").asLeft
}
.map(_.sortBy(_.version))
.flatMap(s =>
if (s.isEmpty)
RegistryError.NotFound.asLeft
else
s.asRight
)
.map(SchemaList.apply)
)
.map(SchemaList.apply)
} catch {
case NonFatal(e) =>
repoFailure(e).asLeft
Expand Down Expand Up @@ -207,5 +209,7 @@ private[registries] object Utils {
RegistryError.RepoFailure(failure.show)

private[resolver] def repoFailure(failure: Throwable): RegistryError =
RegistryError.RepoFailure(if (failure.getMessage != null) failure.getMessage else "Unhandled error")
RegistryError.RepoFailure(
if (failure.getMessage != null) failure.getMessage else "Unhandled error"
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,34 @@ class EmbeddedSpec extends Specification with CatsEffect {
}

def e6 = {
val schemaList = SchemaList(List(
SchemaKey("com.snowplowanalytics.iglu-test", "test-embedded-list", "jsonschema", SchemaVer.Full(1, 0, 0)),
SchemaKey("com.snowplowanalytics.iglu-test", "test-embedded-list", "jsonschema", SchemaVer.Full(1, 0, 1)),
SchemaKey("com.snowplowanalytics.iglu-test", "test-embedded-list", "jsonschema", SchemaVer.Full(1, 2, 0)),
SchemaKey("com.snowplowanalytics.iglu-test", "test-embedded-list", "jsonschema", SchemaVer.Full(1, 2, 11)),
))
val schemaList = SchemaList(
List(
SchemaKey(
"com.snowplowanalytics.iglu-test",
"test-embedded-list",
"jsonschema",
SchemaVer.Full(1, 0, 0)
),
SchemaKey(
"com.snowplowanalytics.iglu-test",
"test-embedded-list",
"jsonschema",
SchemaVer.Full(1, 0, 1)
),
SchemaKey(
"com.snowplowanalytics.iglu-test",
"test-embedded-list",
"jsonschema",
SchemaVer.Full(1, 2, 0)
),
SchemaKey(
"com.snowplowanalytics.iglu-test",
"test-embedded-list",
"jsonschema",
SchemaVer.Full(1, 2, 11)
)
)
)
SpecHelpers.EmbeddedTest
.list[IO]("com.snowplowanalytics.iglu-test", "test-embedded-list", 1)
.map(result => result must beRight(schemaList))
Expand Down

0 comments on commit edbc33c

Please sign in to comment.