Skip to content

Commit

Permalink
Merge branch 'main' into update/all
Browse files Browse the repository at this point in the history
  • Loading branch information
mpro7 authored Nov 7, 2023
2 parents d49264f + dbda1cc commit 84c829f
Show file tree
Hide file tree
Showing 22 changed files with 126 additions and 178 deletions.
12 changes: 6 additions & 6 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Issue Number: DEV-

### PR Type

- [ ] build/chore: maintenance tasks (no production code change)
- [ ] docs: documentation changes (no production code change)
- [ ] feat: represents new features
- [ ] fix: represents bug fixes
- [ ] perf: performance improvements
- [ ] refactor: represents production code refactoring
- [ ] feat: represents a new feature
- [ ] docs: documentation changes (no production code change)
- [ ] chore: maintenance tasks (no production code change)
- [ ] test: all about tests: adding, refactoring tests (no production code change)
- [ ] other... Please describe:
- [ ] test: adding or refactoring tests (no production code change)

### Basic Requirements for bug fixes and features
### Basic requirements for bug fixes and features

- [ ] Tests for the changes have been added
- [ ] Docs have been added / updated
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-pr-title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
steps:
- uses: deepakputhraya/action-pr-title@master
with:
regex: '^(feat|fix|build|chore|test|refactor|docs)(\(.+\))?!?: [A-Z].+$'
regex: '^(build|chore|docs|feat|fix|perf|refactor|test)(\(.+\))?!?: [A-Z].+$'
max_length: 140
9 changes: 5 additions & 4 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ jobs:
package-name: dsp-api
pull-request-title-pattern: "chore${scope}: Release${component} ${version}"
changelog-types: '[
{"type": "feat", "section": "Enhancements", "hidden": false },
{"type": "fix", "section": "Bug Fixes", "hidden": false },
{"type": "build", "section": "Maintenance", "hidden": false },
{"type": "chore", "section": "Maintenance", "hidden": false },
{"type": "test", "section": "Maintenance", "hidden": false },
{"type": "docs", "section": "Documentation", "hidden": false },
{"type": "feat", "section": "Enhancements", "hidden": false },
{"type": "fix", "section": "Bug Fixes", "hidden": false },
{"type": "perf", "section": "Enhancements", "hidden": false },
{"type": "refactor", "section": "Maintenance", "hidden": false },
{"type": "docs", "section": "Documentation", "hidden": false }
{"type": "test", "section": "Maintenance", "hidden": false }
]'
5 changes: 3 additions & 2 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ updates.ignore = [
#
# Default: []
pullRequests.grouping = [
{ name = "patches", "title" = "chore: Patch updates", "filter" = [{"version" = "patch"}] },
{ name = "minor_major", "title" = "chore: Minor/major updates", "filter" = [{"version" = "minor"}, {"version" = "major"}] },
{ name = "patch", "title" = "chore: Patch dependency updates", "filter" = [{"version" = "patch"}] },
{ name = "minor", "title" = "chore: Minor dependency updates", "filter" = [{"version" = "minor"}] },
{ name = "major", "title" = "chore: Major dependency updates", "filter" = [{"version" = "major"}] },
{ name = "all", "title" = "chore: Dependency updates", "filter" = [{"group" = "*"}] }
]

Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.7.14"
version = "3.7.15"
runner.dialect = scala213
maxColumn = 120
align.preset = most
Expand Down
12 changes: 6 additions & 6 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ object Dependencies {

val fusekiImage =
"daschswiss/apache-jena-fuseki:2.1.2" // should be the same version as in docker-compose.yml, also make sure to use the same version when deploying it (i.e. version in ops-deploy)!
val sipiImage = "daschswiss/sipi:3.8.2" // base image the knora-sipi image is created from
val sipiImage = "daschswiss/sipi:3.8.3" // base image the knora-sipi image is created from

val ScalaVersion = "2.13.11"
val ScalaVersion = "2.13.12"

val PekkoActorVersion = "1.0.1"
val PekkoHttpVersion = "1.0.0"
Expand All @@ -24,7 +24,7 @@ object Dependencies {
val ZioConfigVersion = "3.0.7"
val ZioLoggingVersion = "2.1.14"
val ZioNioVersion = "2.0.2"
val ZioMetricsConnectorsVersion = "2.2.0"
val ZioMetricsConnectorsVersion = "2.2.1"
val ZioPreludeVersion = "1.0.0-RC21"
val ZioSchemaVersion = "0.2.0"
val ZioVersion = "2.0.18"
Expand Down Expand Up @@ -70,8 +70,8 @@ object Dependencies {

// Metrics
val aspectjweaver = "org.aspectj" % "aspectjweaver" % "1.9.20.1"
val kamonCore = "io.kamon" %% "kamon-core" % "2.6.4" // Scala 3 compatible
val kamonScalaFuture = "io.kamon" %% "kamon-scala-future" % "2.6.4" // Scala 3 incompatible
val kamonCore = "io.kamon" %% "kamon-core" % "2.6.5" // Scala 3 compatible
val kamonScalaFuture = "io.kamon" %% "kamon-scala-future" % "2.6.5" // Scala 3 incompatible

// input validation
val commonsValidator =
Expand All @@ -81,7 +81,7 @@ object Dependencies {
val jwtSprayJson = "com.github.jwt-scala" %% "jwt-spray-json" % "9.0.2"
// jwtSprayJson -> 9.0.2 is the latest version that's compatible with spray-json; if it wasn't for spray, this would be Scala 3 compatible
val springSecurityCore =
"org.springframework.security" % "spring-security-core" % "6.1.4" exclude ("commons-logging", "commons-logging") exclude ("org.springframework", "spring-aop")
"org.springframework.security" % "spring-security-core" % "6.1.5" exclude ("commons-logging", "commons-logging") exclude ("org.springframework", "spring-aop")
val bouncyCastle = "org.bouncycastle" % "bcprov-jdk15to18" % "1.76"

// caching
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.6
sbt.version=1.9.7
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ resolvers ++= Seq(

addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.16")
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.1.2")
addSbtPlugin("com.typesafe.play" % "sbt-twirl" % "1.6.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.3")
addSbtPlugin("com.typesafe.play" % "sbt-twirl" % "1.6.2")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.4")
addSbtPlugin("com.github.sbt" % "sbt-javaagent" % "0.1.7")
// also update the scalac-scoverage-runtime version in build.sbt
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
Expand Down
32 changes: 13 additions & 19 deletions webapi/src/main/scala/dsp/valueobjects/Project.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import zio.prelude.Validation
import scala.util.matching.Regex

import dsp.errors.ValidationException
import dsp.valueobjects.Iri

object Project {
// A regex sub-pattern for project IDs, which must consist of 4 hexadecimal digits.
Expand All @@ -28,17 +27,6 @@ object Project {
*/
private val shortnameRegex: Regex = "^[a-zA-Z][a-zA-Z0-9_-]{2,19}$".r

/**
* Check that the string represents a valid project shortname.
*
* @param shortname string to be checked.
* @return the same string.
*/
private def validateAndEscapeProjectShortname(shortname: String): Option[String] =
shortnameRegex
.findFirstIn(shortname)
.flatMap(Iri.toSparqlEncodedString)

object ErrorMessages {
val ShortcodeMissing = "Shortcode cannot be empty."
val ShortcodeInvalid = (v: String) => s"Invalid project shortcode: $v"
Expand All @@ -64,8 +52,7 @@ object Project {
implicit val encoder: JsonEncoder[Shortcode] =
JsonEncoder[String].contramap((shortcode: Shortcode) => shortcode.value)

def unsafeFrom(str: String) = make(str)
.getOrElse(throw new IllegalArgumentException(ErrorMessages.ShortcodeInvalid(str)))
def unsafeFrom(str: String): Shortcode = make(str).fold(e => throw e.head, identity)

def make(value: String): Validation[ValidationException, Shortcode] =
if (value.isEmpty) Validation.fail(ValidationException(ErrorMessages.ShortcodeMissing))
Expand All @@ -87,19 +74,26 @@ object Project {
implicit val encoder: JsonEncoder[Shortname] =
JsonEncoder[String].contramap((shortname: Shortname) => shortname.value)

def unsafeFrom(str: String): Shortname = make(str).fold(e => throw e.head, identity)

def make(value: String): Validation[ValidationException, Shortname] =
if (value.isEmpty) Validation.fail(ValidationException(ErrorMessages.ShortnameMissing))
else
Validation
.fromOption(validateAndEscapeProjectShortname(value))
.fromOption(validateAndEscape(value))
.mapError(_ => ValidationException(ErrorMessages.ShortnameInvalid(value)))
.map(new Shortname(_) {})

def make(value: Option[String]): Validation[ValidationException, Option[Shortname]] =
value match {
case Some(v) => self.make(v).map(Some(_))
case None => Validation.succeed(None)
private def validateAndEscape(shortname: String): Option[String] = {
val defaultSharedOntologiesProject = "DefaultSharedOntologiesProject"
if (shortname == defaultSharedOntologiesProject) {
Some(defaultSharedOntologiesProject)

Check warning on line 90 in webapi/src/main/scala/dsp/valueobjects/Project.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/dsp/valueobjects/Project.scala#L90

Added line #L90 was not covered by tests
} else {
shortnameRegex
.findFirstIn(shortname)
.flatMap(Iri.toSparqlEncodedString)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ package org.knora.webapi.slice.admin.domain.model
import zio.NonEmptyChunk

import dsp.valueobjects.Project.Shortcode
import dsp.valueobjects.Project.Shortname
import dsp.valueobjects.V2.StringLiteralV2
import org.knora.webapi.slice.resourceinfo.domain.InternalIri

case class KnoraProject(
id: InternalIri,
shortname: String,
shortname: Shortname,
shortcode: Shortcode,
longname: Option[String],
description: NonEmptyChunk[StringLiteralV2],
keywords: List[String],
logo: Option[String],
status: Boolean,
selfjoin: Boolean
selfjoin: Boolean,
ontologies: List[InternalIri]
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ import zio.Task
import dsp.valueobjects.Project.Shortcode
import dsp.valueobjects.RestrictedViewSize
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectIdentifierADM.ShortcodeIdentifier
import org.knora.webapi.slice.admin.domain.model.KnoraProject
import org.knora.webapi.slice.common.repo.service.Repository
import org.knora.webapi.slice.resourceinfo.domain.InternalIri

trait KnoraProjectRepo extends Repository[KnoraProject, InternalIri] {
def findById(id: ProjectIdentifierADM): Task[Option[KnoraProject]]
def findByShortcode(shortcode: Shortcode): Task[Option[KnoraProject]] = findById(ShortcodeIdentifier(shortcode))
def findOntologies(project: KnoraProject): Task[List[InternalIri]]
def findByShortcode(code: Shortcode): Task[Option[KnoraProject]] =
findById(ProjectIdentifierADM.ShortcodeIdentifier(code))
def setProjectRestrictedViewSize(project: KnoraProject, size: RestrictedViewSize): Task[Unit]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.knora.webapi.slice.admin.domain.service
import zio._

import dsp.valueobjects.Project.Shortcode
import dsp.valueobjects.Project.Shortname
import dsp.valueobjects.RestrictedViewSize
import org.knora.webapi.messages.OntologyConstants
import org.knora.webapi.messages.admin.responder.projectsmessages.ProjectADM
Expand Down Expand Up @@ -38,10 +39,9 @@ object ProjectADMService {
* @return the [[InternalIri]] of the project's data named graph.
*/
def projectDataNamedGraphV2(project: ProjectADM): InternalIri = {
val shortcode = Shortcode
.make(project.shortcode)
.getOrElse(throw new IllegalArgumentException(s"Invalid project shortcode: ${project.shortcode}"))
projectDataNamedGraphV2(shortcode, project.shortname)
val shortcode = Shortcode.unsafeFrom(project.shortcode)
val shortname = Shortname.unsafeFrom(project.shortname)
projectDataNamedGraphV2(shortcode, shortname)
}

/**
Expand All @@ -53,8 +53,8 @@ object ProjectADMService {
def projectDataNamedGraphV2(project: KnoraProject): InternalIri =
projectDataNamedGraphV2(project.shortcode, project.shortname)

private def projectDataNamedGraphV2(shortcode: Shortcode, projectShortname: String) =
InternalIri(s"${OntologyConstants.NamedGraphs.DataNamedGraphStart}/${shortcode.value}/$projectShortname")
private def projectDataNamedGraphV2(shortcode: Shortcode, shortname: Shortname) =
InternalIri(s"${OntologyConstants.NamedGraphs.DataNamedGraphStart}/${shortcode.value}/${shortname.value}")
}

final case class ProjectADMServiceLive(
Expand All @@ -67,33 +67,33 @@ final case class ProjectADMServiceLive(
projectRepo.findById(projectId).flatMap(ZIO.foreach(_)(toProjectADM))

private def toProjectADM(knoraProject: KnoraProject): Task[ProjectADM] =
for {
ontologyIris <- projectRepo.findOntologies(knoraProject)
} yield ProjectADM(
id = knoraProject.id.value,
shortname = knoraProject.shortname,
shortcode = knoraProject.shortcode.value,
longname = knoraProject.longname,
description = knoraProject.description,
keywords = knoraProject.keywords,
logo = knoraProject.logo,
status = knoraProject.status,
selfjoin = knoraProject.selfjoin,
ontologies = ontologyIris.map(_.value)
).unescape
ZIO.attempt(
ProjectADM(
id = knoraProject.id.value,
shortname = knoraProject.shortname.value,
shortcode = knoraProject.shortcode.value,
longname = knoraProject.longname,
description = knoraProject.description,
keywords = knoraProject.keywords,
logo = knoraProject.logo,
status = knoraProject.status,
selfjoin = knoraProject.selfjoin,
ontologies = knoraProject.ontologies.map(_.value)
).unescape

Check warning on line 82 in webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala#L70-L82

Added lines #L70 - L82 were not covered by tests
)

private def toKnoraProject(project: ProjectADM): KnoraProject =
KnoraProject(
id = InternalIri.apply(project.id),
shortname = project.shortname,
shortcode =
Shortcode.make(project.shortcode).getOrElse(throw new IllegalArgumentException("Should not happened.")),
shortname = Shortname.unsafeFrom(project.shortname),
shortcode = Shortcode.unsafeFrom(project.shortcode),

Check warning on line 89 in webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala#L88-L89

Added lines #L88 - L89 were not covered by tests
longname = project.longname,
description = NonEmptyChunk.fromIterable(project.description.head, project.description.tail),
keywords = project.keywords.toList,
logo = project.logo,
status = project.status,
selfjoin = project.selfjoin
selfjoin = project.selfjoin,
ontologies = project.ontologies.map(InternalIri.apply).toList

Check warning on line 96 in webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectADMService.scala#L95-L96

Added lines #L95 - L96 were not covered by tests
)

override def findAllProjectsKeywords: Task[ProjectsKeywordsGetResponseADM] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,13 @@ final case class ProjectExportServiceLive(

override def exportProjectTriples(project: KnoraProject): Task[Path] =
Files
.createTempDirectory(Some(project.shortname), fileAttributes = Nil)
.createTempDirectory(Some(project.shortname.value), fileAttributes = Nil)

Check warning on line 134 in webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala#L134

Added line #L134 was not covered by tests
.map(trigExportFilePath(project, _))
.flatMap(exportProjectTriples(project, _))

override def exportProjectTriples(project: KnoraProject, targetFile: Path): Task[Path] = ZIO.scoped {
for {
tempDir <- Files.createTempDirectoryScoped(Some(project.shortname), fileAttributes = Nil)
tempDir <- Files.createTempDirectoryScoped(Some(project.shortname.value), fileAttributes = Nil)

Check warning on line 140 in webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala

View check run for this annotation

Codecov / codecov/patch

webapi/src/main/scala/org/knora/webapi/slice/admin/domain/service/ProjectExportService.scala#L140

Added line #L140 was not covered by tests
ontologyAndData <- downloadOntologyAndData(project, tempDir)
adminData <- downloadProjectAdminData(project, tempDir)
permissionData <- downloadPermissionData(project, tempDir)
Expand Down
Loading

0 comments on commit 84c829f

Please sign in to comment.