Skip to content

Commit

Permalink
refactor: remove dsp-shared project (DEV-2045) (#2619)
Browse files Browse the repository at this point in the history
  • Loading branch information
mpro7 committed Apr 25, 2023
1 parent 461b0b6 commit 772e77c
Show file tree
Hide file tree
Showing 34 changed files with 93 additions and 125 deletions.
14 changes: 1 addition & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ lazy val root: Project = Project(id = "root", file("."))
.aggregate(
webapi,
sipi,
shared,
schemaCore
)
.enablePlugins(GitVersioning, GitBranchPrompt)
Expand Down Expand Up @@ -262,7 +261,7 @@ lazy val webapi: Project = Project(id = "webapi", base = file("webapi"))
),
buildInfoPackage := "org.knora.webapi.http.version"
)
.dependsOn(shared, schemaCore)
.dependsOn(schemaCore)

//////////////////////////////////////
// DSP's new codebase
Expand All @@ -277,14 +276,3 @@ lazy val schemaCore = project
libraryDependencies ++= Dependencies.schemaCoreLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)
.dependsOn(shared)

// shared project
lazy val shared = project
.in(file("dsp-shared"))
.settings(
scalacOptions ++= customScalacOptions,
name := "shared",
libraryDependencies ++= Dependencies.sharedLibraryDependencies,
testFrameworks := Seq(new TestFramework("zio.test.sbt.ZTestFramework"))
)

This file was deleted.

19 changes: 0 additions & 19 deletions dsp-shared/src/main/resources/application.conf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dsp.schema.domain
package dsp.valueobjects

import zio.prelude.Validation

Expand All @@ -7,14 +7,9 @@ import java.time.Instant
import dsp.errors.ValidationException
import dsp.valueobjects.LangString
import dsp.valueobjects.Schema
import org.knora.webapi.messages.SmartIri

/**
* SmartIri placeholder value object.
* WARNING: don't use this in production code. First find a solution how we deal with SmartIri in the new codebase.
*
* // TODO: this is only a placeholder for SmartIri - eventually we need a proper solution for IRI value objects.
*/
case class SmartIri(value: String)
// below file was moved from dsp-shared, for more info refer to issue DEV-745 and BL

/**
* Command/Value object representing a command to create a property on a schema/ontology.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import java.time.Instant
import dsp.constants.SalsahGui
import dsp.errors.BadRequestException
import dsp.errors.ValidationException
import dsp.schema.domain.CreatePropertyCommand
import dsp.schema.domain.{SmartIri => SmartIriV3}
import dsp.valueobjects.CreatePropertyCommand
import dsp.valueobjects.Iri._
import dsp.valueobjects.LangString
import dsp.valueobjects.Schema._
Expand Down Expand Up @@ -510,39 +509,40 @@ final case class OntologiesRouteV2()(
.validate(validatedGuiAttributes, validatedGuiElement)
.flatMap(values => GuiObject.make(values._1, values._2))

ontologyIri =
Validation.succeed(SmartIriV3(inputOntology.ontologyMetadata.ontologyIri.toString))
ontologyIri <- IriConverter.asSmartIri(inputOntology.ontologyMetadata.ontologyIri.toString)
lastModificationDate = Validation.succeed(propertyUpdateInfo.lastModificationDate)
propertyIri = Validation.succeed(SmartIriV3(propertyInfoContent.propertyIri.toString))
propertyIri <- IriConverter.asSmartIri(propertyInfoContent.propertyIri.toString)
subClassConstraintSmartIri <-
RouteUtilZ.toSmartIri(OntologyConstants.KnoraBase.SubjectClassConstraint, "Should not happen")
subjectType = propertyInfoContent.predicates.get(subClassConstraintSmartIri) match {
case None => Validation.succeed(None)
case Some(value) =>
value.objects.head match {
case objectType: SmartIriLiteralV2 =>
Validation.succeed(
Some(SmartIriV3(objectType.value.toOntologySchema(InternalSchema).toString))
)
case other =>
Validation.fail(ValidationException(s"Unexpected subject type for $other"))
}
}
subjectType <-
propertyInfoContent.predicates.get(subClassConstraintSmartIri) match {
case None => ZIO.succeed(None)
case Some(value) =>
value.objects.head match {
case objectType: SmartIriLiteralV2 =>
IriConverter
.asSmartIri(
objectType.value.toOntologySchema(InternalSchema).toString
)
.map(Some(_))
case other =>
ZIO.fail(ValidationException(s"Unexpected subject type for $other"))
}
}
objectTypeSmartIri <- RouteUtilZ
.toSmartIri(OntologyConstants.KnoraApiV2Complex.ObjectType, "Should not happen")
objectType = propertyInfoContent.predicates.get(objectTypeSmartIri) match {
case None =>
Validation.fail(ValidationException(s"Object type cannot be empty."))
case Some(value) =>
value.objects.head match {
case objectType: SmartIriLiteralV2 =>
Validation.succeed(
SmartIriV3(objectType.value.toOntologySchema(InternalSchema).toString)
)
case other =>
Validation.fail(ValidationException(s"Unexpected object type for $other"))
}
}
objectType <-
propertyInfoContent.predicates.get(objectTypeSmartIri) match {
case None =>
ZIO.fail(ValidationException(s"Object type cannot be empty."))
case Some(value) =>
value.objects.head match {
case objectType: SmartIriLiteralV2 =>
IriConverter.asSmartIri(objectType.value.toOntologySchema(InternalSchema).toString)
case other =>
ZIO.fail(ValidationException(s"Unexpected object type for $other"))
}
}
labelSmartIri <- RouteUtilZ.toSmartIri(OntologyConstants.Rdfs.Label, "Should not happen")
label = propertyInfoContent.predicates.get(labelSmartIri) match {
case None => Validation.fail(ValidationException("Label missing"))
Expand All @@ -567,25 +567,24 @@ final case class OntologiesRouteV2()(
}
}
superProperties =
propertyInfoContent.subPropertyOf.toList.map(smartIri => SmartIriV3(smartIri.toString)) match {
propertyInfoContent.subPropertyOf.toList match {
case Nil => Validation.fail(ValidationException("SuperProperties cannot be empty."))
case superProps => Validation.succeed(superProps)
}

_ <-
Validation
.validate(
ontologyIri,
lastModificationDate,
propertyIri,
subjectType,
objectType,
label,
comment,
superProperties,
guiObject
)
.flatMap(v => CreatePropertyCommand.make(v._1, v._2, v._3, v._4, v._5, v._6, v._7, v._8, v._9))
.flatMap(v =>
CreatePropertyCommand
.make(ontologyIri, v._1, propertyIri, subjectType, objectType, v._2, v._3, v._4, v._5)
)
.toZIO
} yield requestMessage

Expand Down
54 changes: 54 additions & 0 deletions webapi/src/test/scala/dsp/valueobjects/SchemaCommandsSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dsp.valueobjects

import zio.test.Assertion._
import zio.test._

import java.time.Instant
import scala.collection.immutable.List

import dsp.constants.SalsahGui
import dsp.valueobjects.LangString
import dsp.valueobjects.LanguageCode
import dsp.valueobjects.Schema
import org.knora.webapi.messages.StringFormatter
import org.knora.webapi.slice.resourceinfo.domain.IriConverter

/**
* This spec is used to test [[dsp.valueobjects.CreatePropertyCommand]].
*/
object SchemaCommandsSpec extends ZIOSpecDefault {

def spec = (createPropertyCommandTest).provide(IriConverter.layer, StringFormatter.test)

private val createPropertyCommandTest = suite("CreatePropertyCommand")(
test("create a createPropertyCommand") {
val lastModificationDate = Instant.now()
val subjectType = None
(for {
ontologyIri <- IriConverter.asSmartIri("http://www.knora.org/ontology/0001/anything")
propertyIri <- IriConverter.asSmartIri("http://www.knora.org/ontology/0001/anything#someProperty")
objectType <- IriConverter.asSmartIri("http://www.knora.org/ontology/0001/anything#SomeClass")
superProperties <-
IriConverter.asSmartIri("http://www.knora.org/ontology/0001/anything#someSuperCoolProperty").map(List(_))
label <- LangString.make(LanguageCode.en, "some label").toZIO
commentLangString <- LangString.make(LanguageCode.en, "some comment").toZIO
comment = Some(commentLangString)
guiAttribute <- Schema.GuiAttribute.make("hlist=<http://rdfh.ch/lists/082F/PbRLUy66TsK10qNP1mBwzA>").toZIO
guiElement <- Schema.GuiElement.make(SalsahGui.List).toZIO
guiObject <- Schema.GuiObject.make(Set(guiAttribute), Some(guiElement)).toZIO
command =
CreatePropertyCommand.make(
ontologyIri = ontologyIri,
lastModificationDate = lastModificationDate,
propertyIri = propertyIri,
subjectType = subjectType,
objectType = objectType,
label = label,
comment = comment,
superProperties = superProperties,
guiObject = guiObject
)
} yield assert(command.toEither)(isRight))
}
)
}

0 comments on commit 772e77c

Please sign in to comment.